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 3118-3120
subtest 'is_anonymous' => sub {
Link Here
|
3118 |
$schema->storage->txn_rollback; |
3118 |
$schema->storage->txn_rollback; |
3119 |
|
3119 |
|
3120 |
}; |
3120 |
}; |
3121 |
- |
3121 |
|
|
|
3122 |
subtest 'has_2fa_enabled() tests' => sub { |
3123 |
plan tests => 3; |
3124 |
|
3125 |
$schema->storage->txn_begin; |
3126 |
|
3127 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
3128 |
|
3129 |
# Test patron without 2FA |
3130 |
is( $patron->has_2fa_enabled, 0, 'has_2fa_enabled returns 0 when no secret is set' ); |
3131 |
|
3132 |
# Test patron with empty secret |
3133 |
$patron->secret('')->store; |
3134 |
is( $patron->has_2fa_enabled, 0, 'has_2fa_enabled returns 0 when secret is empty string' ); |
3135 |
|
3136 |
# Test patron with 2FA enabled |
3137 |
$patron->secret('some_secret_value')->store; |
3138 |
is( $patron->has_2fa_enabled, 1, 'has_2fa_enabled returns 1 when secret is set' ); |
3139 |
|
3140 |
$schema->storage->txn_rollback; |
3141 |
}; |
3142 |
|
3143 |
subtest 'reset_2fa() tests' => sub { |
3144 |
plan tests => 6; |
3145 |
|
3146 |
$schema->storage->txn_begin; |
3147 |
|
3148 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
3149 |
|
3150 |
# Set up patron with 2FA enabled |
3151 |
$patron->set( |
3152 |
{ |
3153 |
secret => 'test_secret_123', |
3154 |
auth_method => 'two-factor', |
3155 |
} |
3156 |
)->store; |
3157 |
|
3158 |
# Verify 2FA is enabled |
3159 |
is( $patron->has_2fa_enabled, 1, '2FA is enabled before reset' ); |
3160 |
is( $patron->auth_method, 'two-factor', 'auth_method is two-factor before reset' ); |
3161 |
|
3162 |
# Test reset_2fa method |
3163 |
my $result = $patron->reset_2fa; |
3164 |
|
3165 |
# Verify method returns patron object for chaining |
3166 |
isa_ok( $result, 'Koha::Patron', 'reset_2fa returns Koha::Patron object' ); |
3167 |
is( $result->borrowernumber, $patron->borrowernumber, 'returned object is the same patron' ); |
3168 |
|
3169 |
# Verify 2FA has been reset |
3170 |
$patron->discard_changes; |
3171 |
is( $patron->has_2fa_enabled, 0, '2FA is disabled after reset' ); |
3172 |
is( $patron->auth_method, 'password', 'auth_method is password after reset' ); |
3173 |
|
3174 |
$schema->storage->txn_rollback; |
3175 |
}; |