Lines 1298-1305
subtest 'StaffLoginBranchBasedOnIP' => sub {
Link Here
|
1298 |
|
1298 |
|
1299 |
$schema->storage->txn_begin; |
1299 |
$schema->storage->txn_begin; |
1300 |
|
1300 |
|
1301 |
t::lib::Mocks::mock_preference( 'AutoLocation', 0 ); |
1301 |
t::lib::Mocks::mock_preference( 'StaffLoginRestrictBranchByIP', 0 ); |
1302 |
t::lib::Mocks::mock_preference( 'StaffLoginBranchBasedOnIP', 0 ); |
1302 |
t::lib::Mocks::mock_preference( 'StaffLoginBranchBasedOnIP', 0 ); |
1303 |
|
1303 |
|
1304 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 1 } } ); |
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" } } ); |
1305 |
my $branch = $builder->build_object( { class => 'Koha::Libraries', value => { branchip => "127.0.0.1" } } ); |
Lines 1331-1346
subtest 'StaffLoginBranchBasedOnIP' => sub {
Link Here
|
1331 |
$session = C4::Auth::get_session($sessionID); |
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 " ); |
1332 |
is( $session->param('branch'), $branch->branchcode, "Logged in branch is set based on the IP from REMOTE_ADDR " ); |
1333 |
|
1333 |
|
1334 |
# AutoLocation overrides StaffLoginBranchBasedOnIP |
1334 |
# StaffLoginRestrictBranchByIP overrides StaffLoginBranchBasedOnIP |
1335 |
t::lib::Mocks::mock_preference( 'AutoLocation', 1 ); |
1335 |
t::lib::Mocks::mock_preference( 'StaffLoginRestrictBranchByIP', 1 ); |
1336 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1336 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1337 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } ); |
1337 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } ); |
1338 |
is( |
1338 |
is( |
1339 |
$template->{VARS}->{wrongip}, 1, |
1339 |
$template->{VARS}->{wrongip}, 1, |
1340 |
"AutoLocation prevents StaffLoginBranchBasedOnIP from logging user in to another branch" |
1340 |
"StaffLoginRestrictBranchByIP prevents StaffLoginBranchBasedOnIP from logging user in to another branch" |
1341 |
); |
1341 |
); |
1342 |
|
1342 |
|
1343 |
t::lib::Mocks::mock_preference( 'AutoLocation', 0 ); |
1343 |
t::lib::Mocks::mock_preference( 'StaffLoginRestrictBranchByIP', 0 ); |
1344 |
my $other_branch = $builder->build_object( |
1344 |
my $other_branch = $builder->build_object( |
1345 |
{ class => 'Koha::Libraries', value => { branchip => "127.0.0.1", branchcode => "z" . $branch->branchcode } } ); |
1345 |
{ class => 'Koha::Libraries', value => { branchip => "127.0.0.1", branchcode => "z" . $branch->branchcode } } ); |
1346 |
( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1346 |
( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
Lines 1353-1365
subtest 'StaffLoginBranchBasedOnIP' => sub {
Link Here
|
1353 |
|
1353 |
|
1354 |
}; |
1354 |
}; |
1355 |
|
1355 |
|
1356 |
subtest 'AutoLocation' => sub { |
1356 |
subtest 'StaffLoginRestrictBranchByIP' => sub { |
1357 |
|
1357 |
|
1358 |
plan tests => 10; |
1358 |
plan tests => 10; |
1359 |
|
1359 |
|
1360 |
$schema->storage->txn_begin; |
1360 |
$schema->storage->txn_begin; |
1361 |
|
1361 |
|
1362 |
t::lib::Mocks::mock_preference( 'AutoLocation', 0 ); |
1362 |
t::lib::Mocks::mock_preference( 'StaffLoginRestrictBranchByIP', 0 ); |
1363 |
|
1363 |
|
1364 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 1 } } ); |
1364 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 1 } } ); |
1365 |
my $password = 'password'; |
1365 |
my $password = 'password'; |
Lines 1377-1388
subtest 'AutoLocation' => sub {
Link Here
|
1377 |
|
1377 |
|
1378 |
$ENV{REMOTE_ADDR} = '127.0.0.1'; |
1378 |
$ENV{REMOTE_ADDR} = '127.0.0.1'; |
1379 |
my ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1379 |
my ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1380 |
is( $userid, $patron->userid, "Standard login without AutoLocation" ); |
1380 |
is( $userid, $patron->userid, "Standard login without StaffLoginRestrictBranchByIP" ); |
1381 |
|
1381 |
|
1382 |
my $template; |
1382 |
my $template; |
1383 |
t::lib::Mocks::mock_preference( 'AutoLocation', 1 ); |
1383 |
t::lib::Mocks::mock_preference( 'StaffLoginRestrictBranchByIP', 1 ); |
1384 |
|
1384 |
|
1385 |
# AutoLocation: "Require staff to log in from a computer in the IP address range specified by their library (if any)" |
1385 |
# StaffLoginRestrictBranchByIP: "Require staff to log in from a computer in the IP address range specified by their library (if any)" |
1386 |
$patron->library->branchip('')->store; # There is none, allow access from anywhere |
1386 |
$patron->library->branchip('')->store; # There is none, allow access from anywhere |
1387 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1387 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1388 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1388 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
Lines 1419-1425
subtest 'AutoLocation' => sub {
Link Here
|
1419 |
$session = C4::Auth::get_session($sessionID); |
1419 |
$session = C4::Auth::get_session($sessionID); |
1420 |
is( |
1420 |
is( |
1421 |
$session->param('branch'), $other_library->branchcode, |
1421 |
$session->param('branch'), $other_library->branchcode, |
1422 |
"AutoLocation allows specifying a branch as long as the IP matches" |
1422 |
"StaffLoginRestrictBranchByIP allows specifying a branch as long as the IP matches" |
1423 |
); |
1423 |
); |
1424 |
|
1424 |
|
1425 |
$other_library->branchip('129.0.0.1')->store; |
1425 |
$other_library->branchip('129.0.0.1')->store; |
Lines 1427-1433
subtest 'AutoLocation' => sub {
Link Here
|
1427 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } ); |
1427 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } ); |
1428 |
is( $template->{VARS}->{wrongip}, 1, "Login denied when branch specified and IP does not match branch IP" ); |
1428 |
is( $template->{VARS}->{wrongip}, 1, "Login denied when branch specified and IP does not match branch IP" ); |
1429 |
|
1429 |
|
1430 |
|
|
|
1431 |
$ENV{REMOTE_ADDR} = '129.0.0.1'; # Set current IP to match other_branch |
1430 |
$ENV{REMOTE_ADDR} = '129.0.0.1'; # Set current IP to match other_branch |
1432 |
$cgi->param( 'branch', undef ); # Do not pass a branch |
1431 |
$cgi->param( 'branch', undef ); # Do not pass a branch |
1433 |
$patron->library->branchip('')->store; # Unset user branch IP, to allow IP matching on any branch |
1432 |
$patron->library->branchip('')->store; # Unset user branch IP, to allow IP matching on any branch |
1434 |
- |
|
|