3 # This Koha test module is a stub!
4 # Add more tests here!!!
10 use List::MoreUtils qw/all any none/;
11 use Test::More tests => 11;
14 use Koha::AuthUtils qw/hash_password/;
20 my $dbh = C4::Context->dbh;
23 $dbh->{AutoCommit} = 0;
24 $dbh->{RaiseError} = 1;
27 # get_template_and_user tests
29 { # Tests for the language URL parameter
32 my ($query,$authnotrequired,$flagsrequired,$type) = @_;
34 my $userid = 'cobain';
36 # we don't need to bother about permissions for this test
38 superlibrarian => 1, acquisition => 0,
39 borrow => 0, borrowers => 0,
40 catalogue => 1, circulate => 0,
41 coursereserves => 0, editauthorities => 0,
42 editcatalogue => 0, management => 0,
43 parameters => 0, permissions => 0,
44 plugins => 0, reports => 0,
45 reserveforothers => 0, serials => 0,
46 staffaccess => 0, tools => 0,
50 my $session_cookie = $query->cookie(
56 return ( $userid, $session_cookie, $sessionID, $flags );
59 # Mock checkauth, build the scenario
60 my $auth = new Test::MockModule( 'C4::Auth' );
61 $auth->mock( 'checkauth', \&MockedCheckauth );
63 # Make sure 'EnableOpacSearchHistory' is set
64 C4::Context->set_preference('EnableOpacSearchHistory',1);
65 # Enable es-ES for the OPAC and staff interfaces
66 C4::Context->set_preference('opaclanguages','en,es-ES');
67 C4::Context->set_preference('language','en,es-ES');
69 # we need a session cookie
70 $ENV{"SERVER_PORT"} = 80;
71 $ENV{"HTTP_COOKIE"} = 'CGISESSID=nirvana';
74 $query->param('language','es-ES');
76 my ( $template, $loggedinuser, $cookies ) = get_template_and_user(
78 template_name => "about.tt",
82 flagsrequired => { catalogue => 1 },
87 ok ( ( all { ref($_) eq 'CGI::Cookie' } @$cookies ),
88 'BZ9735: the cookies array is flat' );
90 # new query, with non-existent language (we only have en and es-ES)
91 $query->param('language','tomas');
93 ( $template, $loggedinuser, $cookies ) = get_template_and_user(
95 template_name => "about.tt",
99 flagsrequired => { catalogue => 1 },
104 ok( ( none { $_->name eq 'KohaOpacLanguage' and $_->value eq 'tomas' } @$cookies ),
105 'BZ9735: invalid language, it is not set');
107 ok( ( any { $_->name eq 'KohaOpacLanguage' and $_->value eq 'en' } @$cookies ),
108 'BZ9735: invalid language, then default to en');
110 for my $template_name (
112 ../../../../../../../../../../../../../../../etc/passwd
113 test/../../../../../../../../../../../../../../etc/passwd
118 ( $template, $loggedinuser, $cookies ) = get_template_and_user(
120 template_name => $template_name,
123 authnotrequired => 1,
124 flagsrequired => { catalogue => 1 },
128 like ( $@, qr(^bad template path), 'The file $template_name should not be accessible' );
132 # Check that there is always an OPACBaseURL set.
133 my $input = CGI->new();
134 my ( $template1, $borrowernumber, $cookie );
135 ( $template1, $borrowernumber, $cookie ) = get_template_and_user(
137 template_name => "opac-detail.tt",
140 authnotrequired => 1,
144 ok( ( any { 'OPACBaseURL' eq $_ } keys %{$template1->{VARS}} ),
145 'OPACBaseURL is in OPAC template' );
148 ( $template2, $borrowernumber, $cookie ) = get_template_and_user(
150 template_name => "catalogue/detail.tt",
153 authnotrequired => 1,
157 ok( ( any { 'OPACBaseURL' eq $_ } keys %{$template2->{VARS}} ),
158 'OPACBaseURL is in Staff template' );
160 my $hash1 = hash_password('password');
161 my $hash2 = hash_password('password');
163 ok(C4::Auth::checkpw_hash('password', $hash1), 'password validates with first hash');
164 ok(C4::Auth::checkpw_hash('password', $hash2), 'password validates with second hash');