Lines 1-7
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
use Test::More tests => 2; |
4 |
use Test::More tests => 3; |
5 |
use Test::Exception; |
5 |
use Test::Exception; |
6 |
use Test::MockModule; |
6 |
use Test::MockModule; |
7 |
|
7 |
|
Lines 89-91
subtest 'qr_code' => sub {
Link Here
|
89 |
|
89 |
|
90 |
$schema->storage->txn_rollback; |
90 |
$schema->storage->txn_rollback; |
91 |
}; |
91 |
}; |
92 |
- |
92 |
|
|
|
93 |
subtest 'verify' => sub { |
94 |
plan tests => 4; |
95 |
|
96 |
$schema->storage->txn_begin; |
97 |
|
98 |
t::lib::Mocks::mock_preference( 'TwoFactorAuthentication', 'enabled' ); |
99 |
t::lib::Mocks::mock_config( 'encryption_key', 'bad_example' ); |
100 |
t::lib::Mocks::mock_config( 'mfa_range', undef ); |
101 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
102 |
$patron->encode_secret('6557s35ui2gyhkmuuvei6rpk44'); # this is base32 btw |
103 |
$patron->auth_method('two-factor'); |
104 |
$patron->store; |
105 |
|
106 |
my $auth = Koha::Auth::TwoFactorAuth->new( { patron => $patron } ); |
107 |
my $code = 394342; |
108 |
my $timestamp = 1694137671; |
109 |
my $verified; |
110 |
$verified = $auth->verify( $code, undef, undef, $timestamp, undef ); |
111 |
is( $verified, 1, "code valid within 1 minute" ); |
112 |
|
113 |
$verified = $auth->verify( $code, undef, undef, ( $timestamp + 60 ), undef ); |
114 |
is( $verified, 0, "code invalid within 2 minutes" ); |
115 |
|
116 |
t::lib::Mocks::mock_config( 'mfa_range', 10 ); |
117 |
$verified = $auth->verify( $code, undef, undef, ( $timestamp + 300 ), undef ); |
118 |
is( $verified, 1, "code valid within 5 minutes" ); |
119 |
|
120 |
$verified = $auth->verify( $code, undef, undef, ( $timestamp + 330 ), undef ); |
121 |
is( $verified, 0, "code valid within 5.5 minutes" ); |
122 |
|
123 |
$schema->storage->txn_rollback; |
124 |
}; |