3 # tests for Koha::Token
5 # Copyright 2016 Rijksmuseum
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 3 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 use Test
::More tests
=> 6;
26 my $tokenizer = Koha
::Token
->new;
27 is
( length( $tokenizer->generate ), 1, "Generate without parameters" );
28 my $token = $tokenizer->generate({ length => 20 });
29 is
( length($token), 20, "Token $token has 20 chars" );
31 my $id = $tokenizer->generate({ length => 8 });
32 my $secr = $tokenizer->generate({ length => 32 });
33 my $csrftoken = $tokenizer->generate_csrf({ id
=> $id, secret
=> $secr });
34 isnt
( length($csrftoken), 0, "Token $csrftoken should not be empty" );
36 is
( $tokenizer->check, undef, "Check without any parameters" );
37 my $result = $tokenizer->check_csrf({
38 id
=> $id, secret
=> $secr, token
=> $csrftoken,
40 is
( $result, 1, "CSRF token verified" );
42 $result = $tokenizer->check({
43 type
=> 'CSRF', id
=> $id, secret
=> $secr, token
=> $token,
45 isnt
( $result, 1, "This token is no CSRF token" );