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 => 19; |
10 |
use Test::More tests => 20; |
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 1268-1273
subtest 'checkpw() return values tests' => sub {
Link Here
|
1268 |
}; |
1268 |
}; |
1269 |
}; |
1269 |
}; |
1270 |
|
1270 |
|
|
|
1271 |
subtest 'AutoLocation' => sub { |
1272 |
|
1273 |
plan tests => 6; |
1274 |
|
1275 |
$schema->storage->txn_begin; |
1276 |
|
1277 |
t::lib::Mocks::mock_preference( 'AutoLocation', 0 ); |
1278 |
|
1279 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 1 } } ); |
1280 |
my $password = 'password'; |
1281 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); |
1282 |
$patron->set_password( { password => $password } ); |
1283 |
|
1284 |
my $cgi_mock = Test::MockModule->new('CGI'); |
1285 |
$cgi_mock->mock( 'request_method', sub { return 'POST' } ); |
1286 |
my $cgi = CGI->new; |
1287 |
my $auth = Test::MockModule->new('C4::Auth'); |
1288 |
|
1289 |
# Simulating the login form submission |
1290 |
$cgi->param( 'userid', $patron->userid ); |
1291 |
$cgi->param( 'password', $password ); |
1292 |
|
1293 |
$ENV{REMOTE_ADDR} = '127.0.0.1'; |
1294 |
my ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1295 |
is( $userid, $patron->userid ); |
1296 |
|
1297 |
my $template; |
1298 |
t::lib::Mocks::mock_preference( 'AutoLocation', 1 ); |
1299 |
|
1300 |
# AutoLocation: "Require staff to log in from a computer in the IP address range specified by their library (if any)" |
1301 |
$patron->library->branchip('')->store; # There is none, allow access from anywhere |
1302 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1303 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1304 |
is( $userid, $patron->userid ); |
1305 |
is( $template, undef ); |
1306 |
|
1307 |
$patron->library->branchip('1.2.3.4')->store; |
1308 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1309 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } ); |
1310 |
is( $template->{VARS}->{wrongip}, 1 ); |
1311 |
|
1312 |
$patron->library->branchip('127.0.0.1')->store; |
1313 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
1314 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
1315 |
is( $userid, $patron->userid ); |
1316 |
is( $template, undef ); |
1317 |
|
1318 |
$schema->storage->txn_rollback; |
1319 |
|
1320 |
}; |
1321 |
|
1271 |
sub set_weak_password { |
1322 |
sub set_weak_password { |
1272 |
my ($patron) = @_; |
1323 |
my ($patron) = @_; |
1273 |
my $password = 'password'; |
1324 |
my $password = 'password'; |
1274 |
- |
|
|