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 |
{ |
1345 |
{ |
1346 |
class => 'Koha::Libraries', |
1346 |
class => 'Koha::Libraries', |
Lines 1357-1369
subtest 'StaffLoginBranchBasedOnIP' => sub {
Link Here
|
1357 |
|
1357 |
|
1358 |
}; |
1358 |
}; |
1359 |
|
1359 |
|
1360 |
subtest 'AutoLocation' => sub { |
1360 |
subtest 'StaffLoginRestrictBranchByIP' => sub { |
1361 |
|
1361 |
|
1362 |
plan tests => 12; |
1362 |
plan tests => 12; |
1363 |
|
1363 |
|
1364 |
$schema->storage->txn_begin; |
1364 |
$schema->storage->txn_begin; |
1365 |
|
1365 |
|
1366 |
t::lib::Mocks::mock_preference( 'AutoLocation', 0 ); |
1366 |
t::lib::Mocks::mock_preference( 'StaffLoginRestrictBranchByIP', 0 ); |
1367 |
|
1367 |
|
1368 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 1 } } ); |
1368 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 1 } } ); |
1369 |
my $password = 'password'; |
1369 |
my $password = 'password'; |
Lines 1381-1392
subtest 'AutoLocation' => sub {
Link Here
|
1381 |
|
1381 |
|
1382 |
$ENV{REMOTE_ADDR} = '127.0.0.1'; |
1382 |
$ENV{REMOTE_ADDR} = '127.0.0.1'; |
1383 |
my ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1383 |
my ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1384 |
is( $userid, $patron->userid, "Standard login without AutoLocation" ); |
1384 |
is( $userid, $patron->userid, "Standard login without StaffLoginRestrictBranchByIP" ); |
1385 |
|
1385 |
|
1386 |
my $template; |
1386 |
my $template; |
1387 |
t::lib::Mocks::mock_preference( 'AutoLocation', 1 ); |
1387 |
t::lib::Mocks::mock_preference( 'StaffLoginRestrictBranchByIP', 1 ); |
1388 |
|
1388 |
|
1389 |
# AutoLocation: "Require staff to log in from a computer in the IP address range specified by their library (if any)" |
1389 |
# StaffLoginRestrictBranchByIP: "Require staff to log in from a computer in the IP address range specified by their library (if any)" |
1390 |
$patron->library->branchip('')->store; # There is none, allow access from anywhere |
1390 |
$patron->library->branchip('')->store; # There is none, allow access from anywhere |
1391 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1391 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1392 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1392 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
Lines 1423-1429
subtest 'AutoLocation' => sub {
Link Here
|
1423 |
$session = C4::Auth::get_session($sessionID); |
1423 |
$session = C4::Auth::get_session($sessionID); |
1424 |
is( |
1424 |
is( |
1425 |
$session->param('branch'), $other_library->branchcode, |
1425 |
$session->param('branch'), $other_library->branchcode, |
1426 |
"AutoLocation allows specifying a branch as long as the IP matches" |
1426 |
"StaffLoginRestrictBranchByIP allows specifying a branch as long as the IP matches" |
1427 |
); |
1427 |
); |
1428 |
|
1428 |
|
1429 |
$other_library->branchip('129.0.0.1')->store; |
1429 |
$other_library->branchip('129.0.0.1')->store; |
1430 |
- |
|
|