Lines 1344-1350
subtest 'StaffLoginBranchBasedOnIP' => sub {
Link Here
|
1344 |
|
1344 |
|
1345 |
subtest 'AutoLocation' => sub { |
1345 |
subtest 'AutoLocation' => sub { |
1346 |
|
1346 |
|
1347 |
plan tests => 7; |
1347 |
plan tests => 9; |
1348 |
|
1348 |
|
1349 |
$schema->storage->txn_begin; |
1349 |
$schema->storage->txn_begin; |
1350 |
|
1350 |
|
Lines 1366-1372
subtest 'AutoLocation' => sub {
Link Here
|
1366 |
|
1366 |
|
1367 |
$ENV{REMOTE_ADDR} = '127.0.0.1'; |
1367 |
$ENV{REMOTE_ADDR} = '127.0.0.1'; |
1368 |
my ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1368 |
my ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1369 |
is( $userid, $patron->userid ); |
1369 |
is( $userid, $patron->userid, "Standard login without AutoLocation" ); |
1370 |
|
1370 |
|
1371 |
my $template; |
1371 |
my $template; |
1372 |
t::lib::Mocks::mock_preference( 'AutoLocation', 1 ); |
1372 |
t::lib::Mocks::mock_preference( 'AutoLocation', 1 ); |
Lines 1375-1400
subtest 'AutoLocation' => sub {
Link Here
|
1375 |
$patron->library->branchip('')->store; # There is none, allow access from anywhere |
1375 |
$patron->library->branchip('')->store; # There is none, allow access from anywhere |
1376 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1376 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1377 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1377 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1378 |
is( $userid, $patron->userid ); |
1378 |
is( $userid, $patron->userid, "Login is successful when patron's branch does not have an IP" ); |
1379 |
is( $template, undef ); |
1379 |
is( $template, undef, "Template is undef as none passed and not sent to error page" ); |
1380 |
|
1380 |
|
1381 |
$patron->library->branchip('1.2.3.4')->store; |
1381 |
$patron->library->branchip('1.2.3.4')->store; |
1382 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1382 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1383 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } ); |
1383 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } ); |
1384 |
is( $template->{VARS}->{wrongip}, 1 ); |
1384 |
is( |
|
|
1385 |
$template->{VARS}->{wrongip}, 1, |
1386 |
"Login denied when no branch specified and IP does not match patron's branch IP" |
1387 |
); |
1385 |
|
1388 |
|
1386 |
$patron->library->branchip('127.0.0.1')->store; |
1389 |
$patron->library->branchip('127.0.0.1')->store; |
1387 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1390 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1388 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1391 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1389 |
is( $userid, $patron->userid ); |
1392 |
is( $userid, $patron->userid, "Login is successful when patron IP and branch IP match" ); |
1390 |
is( $template, undef ); |
1393 |
is( $template, undef, "Template is undef as none passed and not sent to error page" ); |
1391 |
|
1394 |
|
1392 |
my $other_library = $builder->build_object( { class => 'Koha::Libraries', value => { branchip => '127.0.0.1' } } ); |
1395 |
my $other_library = $builder->build_object( { class => 'Koha::Libraries', value => { branchip => '127.0.0.1' } } ); |
1393 |
$patron->library->branchip('127.0.0.1')->store; |
1396 |
$patron->library->branchip('127.0.0.1')->store; |
1394 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1397 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1395 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1398 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1396 |
my $session = C4::Auth::get_session($sessionID); |
1399 |
my $session = C4::Auth::get_session($sessionID); |
1397 |
is( $session->param('branch'), $patron->branchcode ); |
1400 |
is( |
|
|
1401 |
$session->param('branch'), $patron->branchcode, |
1402 |
"If no branch specified, and IP matches patron branch, login is successful at patron branch even if another branch IP matches" |
1403 |
); |
1404 |
|
1405 |
$cgi->param( 'branch', $other_library->branchcode ); |
1406 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1407 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } ); |
1408 |
$session = C4::Auth::get_session($sessionID); |
1409 |
is( |
1410 |
$session->param('branch'), $other_library->branchcode, |
1411 |
"AutoLocation allows specifying a branch as long as the IP matches" |
1412 |
); |
1413 |
|
1414 |
$other_library->branchip('129.0.0.1')->store; |
1415 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1416 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } ); |
1417 |
is( $template->{VARS}->{wrongip}, 1, "Login denied when branch specified and IP does not match branch IP" ); |
1398 |
|
1418 |
|
1399 |
$schema->storage->txn_rollback; |
1419 |
$schema->storage->txn_rollback; |
1400 |
|
1420 |
|
1401 |
- |
|
|