Lines 20-26
Link Here
|
20 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
21 |
|
21 |
|
22 |
use Modern::Perl; |
22 |
use Modern::Perl; |
23 |
use Test::More tests => 6; |
23 |
use Test::More tests => 8; |
|
|
24 |
use Time::HiRes qw|usleep|; |
24 |
use Koha::Token; |
25 |
use Koha::Token; |
25 |
|
26 |
|
26 |
my $tokenizer = Koha::Token->new; |
27 |
my $tokenizer = Koha::Token->new; |
Lines 43-45
$result = $tokenizer->check({
Link Here
|
43 |
type => 'CSRF', id => $id, secret => $secr, token => $token, |
44 |
type => 'CSRF', id => $id, secret => $secr, token => $token, |
44 |
}); |
45 |
}); |
45 |
isnt( $result, 1, "This token is no CSRF token" ); |
46 |
isnt( $result, 1, "This token is no CSRF token" ); |
46 |
- |
47 |
|
|
|
48 |
# Test MaxAge parameter |
49 |
my $age = 1; # 1 second |
50 |
$result = $tokenizer->check_csrf({ |
51 |
id => $id, secret => $secr, token => $csrftoken, MaxAge => $age, |
52 |
}); |
53 |
is( $result, 1, "CSRF token still valid within one second" ); |
54 |
usleep $age * 1000000 * 2; # micro (millionth) seconds + 100% |
55 |
$result = $tokenizer->check_csrf({ |
56 |
id => $id, secret => $secr, token => $csrftoken, MaxAge => $age, |
57 |
}); |
58 |
isnt( $result, 1, "CSRF token expired after one second" ); |