|
Lines 7-13
use CGI qw ( -utf8 );
Link Here
|
| 7 |
use Test::MockObject; |
7 |
use Test::MockObject; |
| 8 |
use Test::MockModule; |
8 |
use Test::MockModule; |
| 9 |
use List::MoreUtils qw/all any none/; |
9 |
use List::MoreUtils qw/all any none/; |
| 10 |
use Test::More tests => 21; |
10 |
use Test::More tests => 22; |
| 11 |
use Test::Warn; |
11 |
use Test::Warn; |
| 12 |
use t::lib::Mocks; |
12 |
use t::lib::Mocks; |
| 13 |
use t::lib::TestBuilder; |
13 |
use t::lib::TestBuilder; |
|
Lines 1292-1297
subtest 'checkpw() return values tests' => sub {
Link Here
|
| 1292 |
}; |
1292 |
}; |
| 1293 |
}; |
1293 |
}; |
| 1294 |
|
1294 |
|
|
|
1295 |
subtest 'StaffLoginBranchBasedOnIP' => sub { |
| 1296 |
|
| 1297 |
plan tests => 5; |
| 1298 |
|
| 1299 |
$schema->storage->txn_begin; |
| 1300 |
|
| 1301 |
t::lib::Mocks::mock_preference( 'AutoLocation', 0 ); |
| 1302 |
t::lib::Mocks::mock_preference( 'StaffLoginBranchBasedOnIP', 0 ); |
| 1303 |
|
| 1304 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 1 } } ); |
| 1305 |
my $branch = $builder->build_object( { class => 'Koha::Libraries', value => { branchip => "127.0.0.1" } } ); |
| 1306 |
my $password = 'password'; |
| 1307 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); |
| 1308 |
$patron->set_password( { password => $password } ); |
| 1309 |
|
| 1310 |
my $cgi_mock = Test::MockModule->new('CGI'); |
| 1311 |
$cgi_mock->mock( 'request_method', sub { return 'POST' } ); |
| 1312 |
my $cgi = CGI->new; |
| 1313 |
my $auth = Test::MockModule->new('C4::Auth'); |
| 1314 |
|
| 1315 |
# Simulating the login form submission |
| 1316 |
$cgi->param( 'login_userid', $patron->userid ); |
| 1317 |
$cgi->param( 'login_password', $password ); |
| 1318 |
|
| 1319 |
$ENV{REMOTE_ADDR} = '127.0.0.1'; |
| 1320 |
my ( $userid, $cookie, $sessionID, $flags ) = |
| 1321 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
| 1322 |
is( $userid, $patron->userid, "User successfully logged in" ); |
| 1323 |
my $session = C4::Auth::get_session($sessionID); |
| 1324 |
is( $session->param('branch'), $patron->branchcode, "Logged in branch is set to the patron's branchcode" ); |
| 1325 |
|
| 1326 |
my $template; |
| 1327 |
t::lib::Mocks::mock_preference( 'StaffLoginBranchBasedOnIP', 1 ); |
| 1328 |
|
| 1329 |
( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
| 1330 |
is( $userid, $patron->userid, "User successfully logged in" ); |
| 1331 |
$session = C4::Auth::get_session($sessionID); |
| 1332 |
is( $session->param('branch'), $branch->branchcode, "Logged in branch is set based on the IP from REMOTE_ADDR " ); |
| 1333 |
|
| 1334 |
# AutoLocation overrides StaffLoginBranchBasedOnIP |
| 1335 |
t::lib::Mocks::mock_preference( 'AutoLocation', 1 ); |
| 1336 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
| 1337 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } ); |
| 1338 |
is( |
| 1339 |
$template->{VARS}->{wrongip}, 1, |
| 1340 |
"AutoLocation prevents StaffLoginBranchBasedOnIP from logging user in to another branch" |
| 1341 |
); |
| 1342 |
|
| 1343 |
}; |
| 1344 |
|
| 1295 |
subtest 'AutoLocation' => sub { |
1345 |
subtest 'AutoLocation' => sub { |
| 1296 |
|
1346 |
|
| 1297 |
plan tests => 7; |
1347 |
plan tests => 7; |
| 1298 |
- |
|
|