|
Lines 1341-1357
subtest 'StaffLoginBranchBasedOnIP' => sub {
Link Here
|
| 1341 |
); |
1341 |
); |
| 1342 |
|
1342 |
|
| 1343 |
t::lib::Mocks::mock_preference( 'AutoLocation', 0 ); |
1343 |
t::lib::Mocks::mock_preference( 'AutoLocation', 0 ); |
| 1344 |
my $other_branch = $builder->build_object( { class => 'Koha::Libraries', value => { branchip => "127.0.0.1" } } ); |
1344 |
my $other_branch = $builder->build_object( |
|
|
1345 |
{ |
| 1346 |
class => 'Koha::Libraries', |
| 1347 |
value => { branchip => "127.0.0.1", branchcode => substr( "z" . $branch->branchcode, 0, 10 ) } |
| 1348 |
} |
| 1349 |
); |
| 1345 |
( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1350 |
( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
| 1346 |
is( $userid, $patron->userid, "User successfully logged in" ); |
1351 |
is( $userid, $patron->userid, "User successfully logged in" ); |
| 1347 |
$session = C4::Auth::get_session($sessionID); |
1352 |
$session = C4::Auth::get_session($sessionID); |
| 1348 |
is( $session->param('branch'), $branch->branchcode, "Logged in branch is set based which branch when two libraries have same IP?" ); |
1353 |
is( |
|
|
1354 |
$session->param('branch'), $branch->branchcode, |
| 1355 |
"Logged in branch is set based which branch when two libraries have same IP?" |
| 1356 |
); |
| 1349 |
|
1357 |
|
| 1350 |
}; |
1358 |
}; |
| 1351 |
|
1359 |
|
| 1352 |
subtest 'AutoLocation' => sub { |
1360 |
subtest 'AutoLocation' => sub { |
| 1353 |
|
1361 |
|
| 1354 |
plan tests => 11; |
1362 |
plan tests => 12; |
| 1355 |
|
1363 |
|
| 1356 |
$schema->storage->txn_begin; |
1364 |
$schema->storage->txn_begin; |
| 1357 |
|
1365 |
|
|
Lines 1428-1446
subtest 'AutoLocation' => sub {
Link Here
|
| 1428 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1436 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
| 1429 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1437 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
| 1430 |
$session = C4::Auth::get_session($sessionID); |
1438 |
$session = C4::Auth::get_session($sessionID); |
| 1431 |
is( $session->param('branch'), $noip_library->branchcode, "When a branch with no IP set is chosen, we respect the choice regardless of current IP" ); |
1439 |
is( |
|
|
1440 |
$session->param('branch'), $noip_library->branchcode, |
| 1441 |
"When a branch with no IP set is chosen, we respect the choice regardless of current IP" |
| 1442 |
); |
| 1432 |
|
1443 |
|
| 1433 |
$ENV{REMOTE_ADDR} = '129.0.0.1'; # Set current IP to match other_branch |
1444 |
$ENV{REMOTE_ADDR} = '129.0.0.1'; # Set current IP to match other_branch |
| 1434 |
$cgi->param( 'branch', undef ); # Do not pass a branch |
1445 |
$cgi->param( 'branch', '' ); # Do not pass a branch |
| 1435 |
$patron->library->branchip('')->store; # Unset user branch IP, to allow IP matching on any branch |
1446 |
$patron->library->branchip('')->store; # Unset user branch IP, to allow IP matching on any branch |
| 1436 |
# Add a second branch with same IP |
1447 |
# Add a second branch with same IP |
| 1437 |
my $another_library = $builder->build_object( { class => 'Koha::Libraries', value => { branchip => '129.0.0.1' } } ); |
1448 |
my $another_library = $builder->build_object( |
|
|
1449 |
{ |
| 1450 |
class => 'Koha::Libraries', |
| 1451 |
value => { branchip => "129.0.0.1", branchcode => substr( "z" . $other_library->branchcode, 0, 10 ) } |
| 1452 |
} |
| 1453 |
); |
| 1438 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1454 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
| 1439 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } ); |
1455 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } ); |
| 1440 |
$session = C4::Auth::get_session($sessionID); |
1456 |
$session = C4::Auth::get_session($sessionID); |
| 1441 |
is( |
1457 |
is( |
| 1442 |
$session->param('branch'), $other_library->branchcode, |
1458 |
$session->param('branch'), $patron->library->branchcode, |
| 1443 |
"Which branch is chosen when home branch has no IP and more than 1 library matches?" |
1459 |
"When user branch has no IP, and no branch chosen, user is logged in to their homebranch" |
|
|
1460 |
); |
| 1461 |
|
| 1462 |
$cgi->param( 'branch', $another_library->branchcode ) |
| 1463 |
; # Choose branch with duplicate IP and alphabetically later branchcode |
| 1464 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
| 1465 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } ); |
| 1466 |
$session = C4::Auth::get_session($sessionID); |
| 1467 |
is( |
| 1468 |
$session->param('branch'), $another_library->branchcode, |
| 1469 |
"When there is an IP conflict, we use the chosen branch if it matches" |
| 1444 |
); |
1470 |
); |
| 1445 |
|
1471 |
|
| 1446 |
$schema->storage->txn_rollback; |
1472 |
$schema->storage->txn_rollback; |
| 1447 |
- |
|
|