Lines 1355-1393
subtest 'password expiration tests' => sub {
Link Here
|
1355 |
plan tests => 5; |
1355 |
plan tests => 5; |
1356 |
|
1356 |
|
1357 |
$schema->storage->txn_begin; |
1357 |
$schema->storage->txn_begin; |
1358 |
my $date = dt_from_string(); |
1358 |
my $date = dt_from_string(); |
1359 |
my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { |
1359 |
my $category = $builder->build_object( |
1360 |
password_expiry_days => 10, |
1360 |
{ |
1361 |
require_strong_password => 0, |
1361 |
class => 'Koha::Patron::Categories', |
1362 |
force_password_reset_when_set_by_staff => 0, |
1362 |
value => { |
|
|
1363 |
password_expiry_days => 10, |
1364 |
require_strong_password => 0, |
1365 |
force_password_reset_when_set_by_staff => 0, |
1366 |
} |
1363 |
} |
1367 |
} |
1364 |
}); |
1368 |
); |
1365 |
my $patron = $builder->build_object({ class=> 'Koha::Patrons', value => { |
1369 |
my $patron = $builder->build_object( |
1366 |
categorycode => $category->categorycode, |
1370 |
{ |
1367 |
password => 'hats' |
1371 |
class => 'Koha::Patrons', |
|
|
1372 |
value => { |
1373 |
categorycode => $category->categorycode, |
1374 |
password => 'hats' |
1375 |
} |
1368 |
} |
1376 |
} |
1369 |
}); |
1377 |
); |
1370 |
|
1378 |
|
1371 |
$patron->delete()->store()->discard_changes(); # Make sure we are storing a 'new' patron |
1379 |
$patron->delete()->store()->discard_changes(); # Make sure we are storing a 'new' patron |
1372 |
|
1380 |
|
1373 |
is( $patron->password_expiration_date(), $date->add( days => 10 )->ymd() , "Password expiration date set correctly on patron creation"); |
1381 |
is( |
|
|
1382 |
$patron->password_expiration_date(), $date->add( days => 10 )->ymd(), |
1383 |
"Password expiration date set correctly on patron creation" |
1384 |
); |
1374 |
|
1385 |
|
1375 |
$patron = $builder->build_object({ class => 'Koha::Patrons', value => { |
1386 |
$patron = $builder->build_object( |
1376 |
categorycode => $category->categorycode, |
1387 |
{ |
1377 |
password => undef |
1388 |
class => 'Koha::Patrons', |
|
|
1389 |
value => { |
1390 |
categorycode => $category->categorycode, |
1391 |
password => undef |
1392 |
} |
1378 |
} |
1393 |
} |
1379 |
}); |
1394 |
); |
1380 |
$patron->delete()->store()->discard_changes(); |
1395 |
$patron->delete()->store()->discard_changes(); |
1381 |
|
1396 |
|
1382 |
is( $patron->password_expiration_date(), undef, "Password expiration date is not set if patron does not have a password"); |
1397 |
is( |
|
|
1398 |
$patron->password_expiration_date(), undef, |
1399 |
"Password expiration date is not set if patron does not have a password" |
1400 |
); |
1383 |
|
1401 |
|
1384 |
$category->password_expiry_days(undef)->store(); |
1402 |
$category->password_expiry_days(undef)->store(); |
1385 |
$patron = $builder->build_object({ class => 'Koha::Patrons', value => { |
1403 |
$patron = |
1386 |
categorycode => $category->categorycode |
1404 |
$builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $category->categorycode } } ); |
1387 |
} |
|
|
1388 |
}); |
1389 |
$patron->delete()->store()->discard_changes(); |
1405 |
$patron->delete()->store()->discard_changes(); |
1390 |
is( $patron->password_expiration_date(), undef, "Password expiration date is not set if category does not have expiry days set"); |
1406 |
is( |
|
|
1407 |
$patron->password_expiration_date(), undef, |
1408 |
"Password expiration date is not set if category does not have expiry days set" |
1409 |
); |
1391 |
|
1410 |
|
1392 |
$schema->storage->txn_rollback; |
1411 |
$schema->storage->txn_rollback; |
1393 |
|
1412 |
|
Lines 1397-1414
subtest 'password expiration tests' => sub {
Link Here
|
1397 |
|
1416 |
|
1398 |
$schema->storage->txn_begin; |
1417 |
$schema->storage->txn_begin; |
1399 |
my $date = dt_from_string(); |
1418 |
my $date = dt_from_string(); |
1400 |
$patron = $builder->build_object({ class => 'Koha::Patrons', value => { |
1419 |
$patron = |
1401 |
password_expiration_date => undef |
1420 |
$builder->build_object( { class => 'Koha::Patrons', value => { password_expiration_date => undef } } ); |
1402 |
} |
1421 |
is( $patron->password_expired, 0, "Patron with no password expiration date, password not expired" ); |
1403 |
}); |
1422 |
$patron->password_expiration_date($date)->store; |
1404 |
is( $patron->password_expired, 0, "Patron with no password expiration date, password not expired"); |
|
|
1405 |
$patron->password_expiration_date( $date )->store; |
1406 |
$patron->discard_changes(); |
1423 |
$patron->discard_changes(); |
1407 |
is( $patron->password_expired, 1, "Patron with password expiration date of today, password expired"); |
1424 |
is( $patron->password_expired, 1, "Patron with password expiration date of today, password expired" ); |
1408 |
$date->subtract( days => 1 ); |
1425 |
$date->subtract( days => 1 ); |
1409 |
$patron->password_expiration_date( $date )->store; |
1426 |
$patron->password_expiration_date($date)->store; |
1410 |
$patron->discard_changes(); |
1427 |
$patron->discard_changes(); |
1411 |
is( $patron->password_expired, 1, "Patron with password expiration date in past, password expired"); |
1428 |
is( $patron->password_expired, 1, "Patron with password expiration date in past, password expired" ); |
1412 |
|
1429 |
|
1413 |
$schema->storage->txn_rollback; |
1430 |
$schema->storage->txn_rollback; |
1414 |
}; |
1431 |
}; |
Lines 1420-1445
subtest 'password expiration tests' => sub {
Link Here
|
1420 |
$schema->storage->txn_begin; |
1437 |
$schema->storage->txn_begin; |
1421 |
|
1438 |
|
1422 |
my $date = dt_from_string(); |
1439 |
my $date = dt_from_string(); |
1423 |
my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { |
1440 |
my $category = |
1424 |
password_expiry_days => 10 |
1441 |
$builder->build_object( { class => 'Koha::Patron::Categories', value => { password_expiry_days => 10 } } ); |
1425 |
} |
1442 |
my $patron = $builder->build_object( |
1426 |
}); |
1443 |
{ |
1427 |
my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { |
1444 |
class => 'Koha::Patrons', |
1428 |
categorycode => $category->categorycode, |
1445 |
value => { |
1429 |
password_expiration_date => $date->subtract( days => 1 ) |
1446 |
categorycode => $category->categorycode, |
|
|
1447 |
password_expiration_date => $date->subtract( days => 1 ) |
1448 |
} |
1430 |
} |
1449 |
} |
1431 |
}); |
1450 |
); |
1432 |
is( $patron->password_expired, 1, "Patron password is expired"); |
1451 |
is( $patron->password_expired, 1, "Patron password is expired" ); |
1433 |
|
1452 |
|
1434 |
$date = dt_from_string(); |
1453 |
$date = dt_from_string(); |
1435 |
$patron->set_password({ password => "kitten", skip_validation => 1 })->discard_changes(); |
1454 |
$patron->set_password( { password => "kitten", skip_validation => 1 } )->discard_changes(); |
1436 |
is( $patron->password_expired, 0, "Patron password no longer expired when new password set"); |
1455 |
is( $patron->password_expired, 0, "Patron password no longer expired when new password set" ); |
1437 |
is( $patron->password_expiration_date(), $date->add( days => 10 )->ymd(), "Password expiration date set correctly on patron creation"); |
1456 |
is( |
1438 |
|
1457 |
$patron->password_expiration_date(), $date->add( days => 10 )->ymd(), |
|
|
1458 |
"Password expiration date set correctly on patron creation" |
1459 |
); |
1439 |
|
1460 |
|
1440 |
$category->password_expiry_days( undef )->store(); |
1461 |
$category->password_expiry_days(undef)->store(); |
1441 |
$patron->set_password({ password => "puppies", skip_validation => 1 })->discard_changes(); |
1462 |
$patron->set_password( { password => "puppies", skip_validation => 1 } )->discard_changes(); |
1442 |
is( $patron->password_expiration_date(), undef, "Password expiration date is unset if category does not have expiry days"); |
1463 |
is( |
|
|
1464 |
$patron->password_expiration_date(), undef, |
1465 |
"Password expiration date is unset if category does not have expiry days" |
1466 |
); |
1443 |
|
1467 |
|
1444 |
$schema->storage->txn_rollback; |
1468 |
$schema->storage->txn_rollback; |
1445 |
}; |
1469 |
}; |
Lines 1451-1483
subtest 'force_password_reset_when_set_by_staff tests' => sub {
Link Here
|
1451 |
|
1475 |
|
1452 |
$schema->storage->txn_begin; |
1476 |
$schema->storage->txn_begin; |
1453 |
|
1477 |
|
1454 |
my $category = $builder->build_object({ |
1478 |
my $category = $builder->build_object( |
1455 |
class => 'Koha::Patron::Categories', |
1479 |
{ |
1456 |
value => { |
1480 |
class => 'Koha::Patron::Categories', |
1457 |
force_password_reset_when_set_by_staff => 1, |
1481 |
value => { |
1458 |
require_strong_password => 0, |
1482 |
force_password_reset_when_set_by_staff => 1, |
|
|
1483 |
require_strong_password => 0, |
1484 |
} |
1459 |
} |
1485 |
} |
1460 |
}); |
1486 |
); |
1461 |
|
1487 |
|
1462 |
my $patron = $builder->build_object({ |
1488 |
my $patron = $builder->build_object( |
1463 |
class => 'Koha::Patrons', |
1489 |
{ |
1464 |
value => { |
1490 |
class => 'Koha::Patrons', |
1465 |
categorycode => $category->categorycode, |
1491 |
value => { |
1466 |
password => 'hats' |
1492 |
categorycode => $category->categorycode, |
|
|
1493 |
password => 'hats' |
1494 |
} |
1467 |
} |
1495 |
} |
1468 |
}); |
1496 |
); |
1469 |
|
1497 |
|
1470 |
$patron->delete()->store()->discard_changes(); |
1498 |
$patron->delete()->store()->discard_changes(); |
1471 |
is($patron->password_expired, 1, "Patron forced into changing password, password expired."); |
1499 |
is( $patron->password_expired, 1, "Patron forced into changing password, password expired." ); |
1472 |
|
1500 |
|
1473 |
$patron->category->force_password_reset_when_set_by_staff(0)->store(); |
1501 |
$patron->category->force_password_reset_when_set_by_staff(0)->store(); |
1474 |
$patron->delete()->store()->discard_changes(); |
1502 |
$patron->delete()->store()->discard_changes(); |
1475 |
is($patron->password_expired, 0, "Patron not forced into changing password, password not expired."); |
1503 |
is( $patron->password_expired, 0, "Patron not forced into changing password, password not expired." ); |
1476 |
|
1504 |
|
1477 |
$patron->category->force_password_reset_when_set_by_staff(1)->store(); |
1505 |
$patron->category->force_password_reset_when_set_by_staff(1)->store(); |
1478 |
t::lib::Mocks::mock_preference('PatronSelfRegistrationDefaultCategory', $patron->categorycode); |
1506 |
t::lib::Mocks::mock_preference( 'PatronSelfRegistrationDefaultCategory', $patron->categorycode ); |
1479 |
$patron->delete()->store()->discard_changes(); |
1507 |
$patron->delete()->store()->discard_changes(); |
1480 |
is($patron->password_expired, 0, "Patron forced into changing password but patron is self registered, password not expired."); |
1508 |
is( |
|
|
1509 |
$patron->password_expired, 0, |
1510 |
"Patron forced into changing password but patron is self registered, password not expired." |
1511 |
); |
1481 |
|
1512 |
|
1482 |
$schema->storage->txn_rollback; |
1513 |
$schema->storage->txn_rollback; |
1483 |
}; |
1514 |
}; |