|
Lines 32-57
$schema->storage->txn_begin;
Link Here
|
| 32 |
my $category1 = $builder->build_object( |
32 |
my $category1 = $builder->build_object( |
| 33 |
{ |
33 |
{ |
| 34 |
class => 'Koha::Patron::Categories', |
34 |
class => 'Koha::Patron::Categories', |
| 35 |
value => { min_password_length => 15, require_strong_password => 1 } |
35 |
value => { min_password_length => 15, require_strong_password => 1, passwordpolicy => '' } |
| 36 |
} |
36 |
} |
| 37 |
); |
37 |
); |
| 38 |
my $category2 = $builder->build_object( |
38 |
my $category2 = $builder->build_object( |
| 39 |
{ |
39 |
{ |
| 40 |
class => 'Koha::Patron::Categories', |
40 |
class => 'Koha::Patron::Categories', |
| 41 |
value => { min_password_length => 5, require_strong_password => undef } |
41 |
value => { min_password_length => 5, require_strong_password => undef, passwordpolicy => '' } |
| 42 |
} |
42 |
} |
| 43 |
); |
43 |
); |
| 44 |
my $category3 = $builder->build_object( |
44 |
my $category3 = $builder->build_object( |
| 45 |
{ |
45 |
{ |
| 46 |
class => 'Koha::Patron::Categories', |
46 |
class => 'Koha::Patron::Categories', |
| 47 |
value => { min_password_length => undef, require_strong_password => 1 } |
47 |
value => { min_password_length => undef, require_strong_password => 1, passwordpolicy => '' } |
| 48 |
} |
48 |
} |
| 49 |
); |
49 |
); |
| 50 |
my $category4 = $builder->build_object( |
50 |
my $category4 = $builder->build_object( |
| 51 |
{ |
51 |
{ |
| 52 |
class => 'Koha::Patron::Categories', |
52 |
class => 'Koha::Patron::Categories', |
| 53 |
value => |
53 |
value => |
| 54 |
{ min_password_length => undef, require_strong_password => undef } |
54 |
{ min_password_length => undef, require_strong_password => undef, passwordpolicy => '' } |
| 55 |
} |
55 |
} |
| 56 |
); |
56 |
); |
| 57 |
|
57 |
|
|
Lines 63-70
my $p_15l_weak = '0123456789abcdf';
Link Here
|
| 63 |
my $p_5l_strong = 'Abc12'; |
63 |
my $p_5l_strong = 'Abc12'; |
| 64 |
my $p_15l_strong = '0123456789AbCdF'; |
64 |
my $p_15l_strong = '0123456789AbCdF'; |
| 65 |
|
65 |
|
|
|
66 |
# Password policy simplenumeric |
| 67 |
my $category_simple = $builder->build_object({ |
| 68 |
class => 'Koha::Patron::Categories', |
| 69 |
value => { min_password_length => 4, passwordpolicy => 'simplenumeric' }, |
| 70 |
}); |
| 71 |
|
| 72 |
# Password policy alphanumeric |
| 73 |
my $category_alpha = $builder->build_object({ |
| 74 |
class => 'Koha::Patron::Categories', |
| 75 |
value => { min_password_length => 5, passwordpolicy => 'alphanumeric' }, |
| 76 |
}); |
| 77 |
|
| 78 |
# Password policy complex |
| 79 |
my $category_complex = $builder->build_object({ |
| 80 |
class => 'Koha::Patron::Categories', |
| 81 |
value => { min_password_length => 6, passwordpolicy => 'complex' }, |
| 82 |
}); |
| 83 |
|
| 66 |
subtest 'is_password_valid for category' => sub { |
84 |
subtest 'is_password_valid for category' => sub { |
| 67 |
plan tests => 15; |
85 |
plan tests => 16; |
| 68 |
|
86 |
|
| 69 |
my ( $is_valid, $error ); |
87 |
my ( $is_valid, $error ); |
| 70 |
|
88 |
|
|
Lines 121-130
subtest 'is_password_valid for category' => sub {
Link Here
|
| 121 |
'Koha::Exceptions::Password::NoCategoryProvided', |
139 |
'Koha::Exceptions::Password::NoCategoryProvided', |
| 122 |
'Category should always be provided'; |
140 |
'Category should always be provided'; |
| 123 |
|
141 |
|
|
|
142 |
subtest 'password policies' => sub { |
| 143 |
|
| 144 |
t::lib::Mocks::mock_preference('RequireStrongPassword', 0); |
| 145 |
t::lib::Mocks::mock_preference('minPasswordLength', 4); |
| 146 |
|
| 147 |
#test simplenumeric password policy |
| 148 |
( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( '1234', $category_simple ); |
| 149 |
is ( $is_valid, 1, 'simplenumeric password should contain only numbers' ); |
| 150 |
( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( 'A123', $category_simple ); |
| 151 |
is ( $is_valid, 0, 'simplenumeric password should not contain alphabets' ); |
| 152 |
is($error, 'simple_policy_mismatch', 'error "simple_policy_mismatch" raised'); |
| 153 |
( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( '!234', $category_simple ); |
| 154 |
is ( $is_valid, 0, 'simplenumeric password should not contain non-special characters' ); |
| 155 |
( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( '123', $category_simple ); |
| 156 |
is ( $is_valid, 0, 'simplenumeric password follows "min_password_length" value' ); |
| 157 |
|
| 158 |
#test alphanumeric |
| 159 |
( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( 'A1234', $category_alpha ); |
| 160 |
is ( $is_valid, 1, 'alphanumeric password should contain both numbers and non-special characters' ); |
| 161 |
( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( '12345', $category_alpha ); |
| 162 |
is ( $is_valid, 0, 'alphanumeric password must contain at least one uppercase character' ); |
| 163 |
is($error, 'alpha_policy_mismatch', 'error "alpha_policy_mismatch" raised'); |
| 164 |
( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( 'A123', $category_alpha ); |
| 165 |
is ( $is_valid, 0, 'alphanumeric password follows "min_password_length" value'); |
| 166 |
|
| 167 |
#test complex |
| 168 |
( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( 'As!123', $category_complex ); |
| 169 |
is ( $is_valid, 1, 'complex password should contain numbers, lower and uppercase characters and special characters' ); |
| 170 |
( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( 'A12345', $category_complex ); |
| 171 |
is ( $is_valid, 0, 'complex password must contain numbers, lower and uppercase characters and special characters' ); |
| 172 |
is($error, 'complex_policy_mismatch', 'error "complex_policy_mismatch" raised'); |
| 173 |
( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( 'As!12', $category_complex ); |
| 174 |
is ( $is_valid, 0, 'complex password follows "min_password_length" value' ); |
| 175 |
} |
| 124 |
}; |
176 |
}; |
| 125 |
|
177 |
|
| 126 |
subtest 'generate_password for category' => sub { |
178 |
subtest 'generate_password for category' => sub { |
| 127 |
plan tests => 5; |
179 |
plan tests => 6; |
| 128 |
|
180 |
|
| 129 |
my ( $is_valid, $error ); |
181 |
my ( $is_valid, $error ); |
| 130 |
|
182 |
|
|
Lines 159-164
subtest 'generate_password for category' => sub {
Link Here
|
| 159 |
'Koha::Exceptions::Password::NoCategoryProvided', |
211 |
'Koha::Exceptions::Password::NoCategoryProvided', |
| 160 |
'Category should always be provided'; |
212 |
'Category should always be provided'; |
| 161 |
|
213 |
|
|
|
214 |
subtest 'generate_password with password policies' => sub { |
| 215 |
|
| 216 |
t::lib::Mocks::mock_preference('RequireStrongPassword', 0); |
| 217 |
t::lib::Mocks::mock_preference('minPasswordLength', 4); |
| 218 |
|
| 219 |
my $all_valid = 1; |
| 220 |
|
| 221 |
#simplenumeric |
| 222 |
for ( 1 .. 10 ) { |
| 223 |
my $password = Koha::AuthUtils::generate_password( $category_simple );; |
| 224 |
my ( $is_valid, undef ) = Koha::AuthUtils::is_password_valid( $password, $category_simple ); |
| 225 |
$all_valid = 0 unless $is_valid; |
| 226 |
} |
| 227 |
is ( $all_valid, 1, 'generate_password should generate valid passwords with simplenumeric policy' ); |
| 228 |
|
| 229 |
#alphanumeric |
| 230 |
for ( 1 .. 10 ) { |
| 231 |
my $password = Koha::AuthUtils::generate_password( $category_alpha ); |
| 232 |
my ( $is_valid, undef ) = Koha::AuthUtils::is_password_valid( $password, $category_alpha ); |
| 233 |
$all_valid = 0 unless $is_valid; |
| 234 |
} |
| 235 |
is ( $all_valid, 1, 'generate_password should generate valid passwords with alphanumeric policy' ); |
| 236 |
|
| 237 |
#complex |
| 238 |
for ( 1 .. 10 ) { |
| 239 |
my $password = Koha::AuthUtils::generate_password( $category_complex ); |
| 240 |
my ( $is_valid, undef ) = Koha::AuthUtils::is_password_valid( $password, $category_complex ); |
| 241 |
$all_valid = 0 unless $is_valid; |
| 242 |
} |
| 243 |
is ( $all_valid, 1, 'generate_password should generate valid passwords with complex policy' ); |
| 244 |
} |
| 162 |
}; |
245 |
}; |
| 163 |
|
246 |
|
| 164 |
$schema->storage->txn_rollback; |
247 |
$schema->storage->txn_rollback; |