|
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 1240-1245
subtest 'checkpw() return values tests' => sub {
Link Here
|
| 1240 |
}; |
1240 |
}; |
| 1241 |
}; |
1241 |
}; |
| 1242 |
|
1242 |
|
|
|
1243 |
subtest 'AutoLocation' => sub { |
| 1244 |
|
| 1245 |
plan tests => 6; |
| 1246 |
|
| 1247 |
$schema->storage->txn_begin; |
| 1248 |
|
| 1249 |
t::lib::Mocks::mock_preference( 'AutoLocation', 0 ); |
| 1250 |
|
| 1251 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 1 } } ); |
| 1252 |
my $password = 'password'; |
| 1253 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); |
| 1254 |
$patron->set_password( { password => $password } ); |
| 1255 |
|
| 1256 |
my $cgi_mock = Test::MockModule->new('CGI'); |
| 1257 |
$cgi_mock->mock( 'request_method', sub { return 'POST' } ); |
| 1258 |
my $cgi = CGI->new; |
| 1259 |
my $auth = Test::MockModule->new('C4::Auth'); |
| 1260 |
|
| 1261 |
# Simulating the login form submission |
| 1262 |
$cgi->param( 'userid', $patron->userid ); |
| 1263 |
$cgi->param( 'password', $password ); |
| 1264 |
|
| 1265 |
$ENV{REMOTE_ADDR} = '127.0.0.1'; |
| 1266 |
my ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
| 1267 |
is( $userid, $patron->userid ); |
| 1268 |
|
| 1269 |
my $template; |
| 1270 |
t::lib::Mocks::mock_preference( 'AutoLocation', 1 ); |
| 1271 |
|
| 1272 |
# AutoLocation: "Require staff to log in from a computer in the IP address range specified by their library (if any)" |
| 1273 |
$patron->library->branchip('')->store; # There is none, allow access from anywhere |
| 1274 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
| 1275 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
| 1276 |
is( $userid, $patron->userid ); |
| 1277 |
is( $template, undef ); |
| 1278 |
|
| 1279 |
$patron->library->branchip('1.2.3.4')->store; |
| 1280 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
| 1281 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet', undef, undef, { do_not_print => 1 } ); |
| 1282 |
is( $template->{VARS}->{wrongip}, 1 ); |
| 1283 |
|
| 1284 |
$patron->library->branchip('127.0.0.1')->store; |
| 1285 |
( $userid, $cookie, $sessionID, $flags, $template ) = |
| 1286 |
C4::Auth::checkauth( $cgi, 0, { catalogue => 1 }, 'intranet' ); |
| 1287 |
is( $userid, $patron->userid ); |
| 1288 |
is( $template, undef ); |
| 1289 |
|
| 1290 |
$schema->storage->txn_rollback; |
| 1291 |
|
| 1292 |
}; |
| 1293 |
|
| 1243 |
sub set_weak_password { |
1294 |
sub set_weak_password { |
| 1244 |
my ($patron) = @_; |
1295 |
my ($patron) = @_; |
| 1245 |
my $password = 'password'; |
1296 |
my $password = 'password'; |
| 1246 |
- |
|
|