|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 42; |
22 |
use Test::More tests => 44; |
| 23 |
use Test::NoWarnings; |
23 |
use Test::NoWarnings; |
| 24 |
use Test::Exception; |
24 |
use Test::Exception; |
| 25 |
use Test::Warn; |
25 |
use Test::Warn; |
|
Lines 3309-3311
subtest 'is_anonymous' => sub {
Link Here
|
| 3309 |
$schema->storage->txn_rollback; |
3309 |
$schema->storage->txn_rollback; |
| 3310 |
|
3310 |
|
| 3311 |
}; |
3311 |
}; |
| 3312 |
- |
3312 |
|
|
|
3313 |
subtest 'has_2fa_enabled() tests' => sub { |
| 3314 |
plan tests => 3; |
| 3315 |
|
| 3316 |
$schema->storage->txn_begin; |
| 3317 |
|
| 3318 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 3319 |
|
| 3320 |
# Test patron without 2FA |
| 3321 |
is( $patron->has_2fa_enabled, 0, 'has_2fa_enabled returns 0 when no secret is set' ); |
| 3322 |
|
| 3323 |
# Test patron with empty secret |
| 3324 |
$patron->secret('')->store; |
| 3325 |
is( $patron->has_2fa_enabled, 0, 'has_2fa_enabled returns 0 when secret is empty string' ); |
| 3326 |
|
| 3327 |
# Test patron with 2FA enabled |
| 3328 |
$patron->secret('some_secret_value')->store; |
| 3329 |
is( $patron->has_2fa_enabled, 1, 'has_2fa_enabled returns 1 when secret is set' ); |
| 3330 |
|
| 3331 |
$schema->storage->txn_rollback; |
| 3332 |
}; |
| 3333 |
|
| 3334 |
subtest 'reset_2fa() tests' => sub { |
| 3335 |
plan tests => 6; |
| 3336 |
|
| 3337 |
$schema->storage->txn_begin; |
| 3338 |
|
| 3339 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 3340 |
|
| 3341 |
# Set up patron with 2FA enabled |
| 3342 |
$patron->set( |
| 3343 |
{ |
| 3344 |
secret => 'test_secret_123', |
| 3345 |
auth_method => 'two-factor', |
| 3346 |
} |
| 3347 |
)->store; |
| 3348 |
|
| 3349 |
# Verify 2FA is enabled |
| 3350 |
is( $patron->has_2fa_enabled, 1, '2FA is enabled before reset' ); |
| 3351 |
is( $patron->auth_method, 'two-factor', 'auth_method is two-factor before reset' ); |
| 3352 |
|
| 3353 |
# Test reset_2fa method |
| 3354 |
my $result = $patron->reset_2fa; |
| 3355 |
|
| 3356 |
# Verify method returns patron object for chaining |
| 3357 |
isa_ok( $result, 'Koha::Patron', 'reset_2fa returns Koha::Patron object' ); |
| 3358 |
is( $result->borrowernumber, $patron->borrowernumber, 'returned object is the same patron' ); |
| 3359 |
|
| 3360 |
# Verify 2FA has been reset |
| 3361 |
$patron->discard_changes; |
| 3362 |
is( $patron->has_2fa_enabled, 0, '2FA is disabled after reset' ); |
| 3363 |
is( $patron->auth_method, 'password', 'auth_method is password after reset' ); |
| 3364 |
|
| 3365 |
$schema->storage->txn_rollback; |
| 3366 |
}; |