Lines 1-6
Link Here
|
1 |
# This file is part of Koha. |
1 |
# This file is part of Koha. |
2 |
# |
2 |
# |
3 |
# Copyright (C) 2013 Equinox Software, Inc. |
3 |
# Copyright (C) 2013 Equinox Software, Inc. |
|
|
4 |
# Copyright 2017 Koha Development Team |
4 |
# |
5 |
# |
5 |
# Koha is free software; you can redistribute it and/or modify it |
6 |
# Koha is free software; you can redistribute it and/or modify it |
6 |
# under the terms of the GNU General Public License as published by |
7 |
# under the terms of the GNU General Public License as published by |
Lines 16-26
Link Here
|
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
17 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
17 |
|
18 |
|
18 |
use Modern::Perl; |
19 |
use Modern::Perl; |
19 |
use Test::More tests => 1; |
20 |
use Test::More tests => 3; |
20 |
|
21 |
|
|
|
22 |
use t::lib::Mocks; |
21 |
use Koha::AuthUtils qw/hash_password/; |
23 |
use Koha::AuthUtils qw/hash_password/; |
22 |
|
24 |
|
23 |
my $hash1 = hash_password('password'); |
25 |
my $hash1 = hash_password('password'); |
24 |
my $hash2 = hash_password('password'); |
26 |
my $hash2 = hash_password('password'); |
25 |
|
27 |
|
26 |
ok($hash1 ne $hash2, 'random salts used when generating password hash'); |
28 |
ok($hash1 ne $hash2, 'random salts used when generating password hash'); |
27 |
- |
29 |
|
|
|
30 |
subtest 'is_password_valid' => sub { |
31 |
plan tests => 12; |
32 |
|
33 |
my ( $is_valid, $error ); |
34 |
|
35 |
t::lib::Mocks::mock_preference('RequireStrongPassword', 0); |
36 |
t::lib::Mocks::mock_preference('minPasswordLength', 0); |
37 |
( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( '12' ); |
38 |
is( $is_valid, 0, 'min password size should be 3' ); |
39 |
is( $error, 'too_short', 'min password size should be 3' ); |
40 |
( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( ' 123' ); |
41 |
is( $is_valid, 0, 'password should not contain leading spaces' ); |
42 |
is( $error, 'has_whitespaces', 'password should not contain leading spaces' ); |
43 |
( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( '123 ' ); |
44 |
is( $is_valid, 0, 'password should not contain trailing spaces' ); |
45 |
is( $error, 'has_whitespaces', 'password should not contain trailing spaces' ); |
46 |
( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( '123' ); |
47 |
is( $is_valid, 1, 'min password size should be 3' ); |
48 |
|
49 |
t::lib::Mocks::mock_preference('RequireStrongPassword', 1); |
50 |
t::lib::Mocks::mock_preference('minPasswordLength', 8); |
51 |
( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( '12345678' ); |
52 |
is( $is_valid, 0, 'password should be strong' ); |
53 |
is( $error, 'too_weak', 'password should be strong' ); |
54 |
( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( 'abcd1234' ); |
55 |
is( $is_valid, 0, 'strong password should contain uppercase' ); |
56 |
is( $error, 'too_weak', 'strong password should contain uppercase' ); |
57 |
|
58 |
( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( 'abcD1234' ); |
59 |
is( $is_valid, 1, 'strong password should contain uppercase' ); |
60 |
}; |
61 |
|
62 |
subtest 'generate_password' => sub { |
63 |
plan tests => 1; |
64 |
t::lib::Mocks::mock_preference('RequireStrongPassword', 1); |
65 |
t::lib::Mocks::mock_preference('minPasswordLength', 8); |
66 |
my $all_valid = 1; |
67 |
for ( 1 .. 10 ) { |
68 |
my $password = Koha::AuthUtils::generate_password; |
69 |
my ( $is_valid, undef ) = Koha::AuthUtils::is_password_valid( $password ); |
70 |
$all_valid = 0 unless $is_valid; |
71 |
} |
72 |
is ( $all_valid, 1, 'generate_password should generate valid passwords' ); |
73 |
}; |