|
Lines 129-135
subtest 'password validation - unauthenticated user' => sub {
Link Here
|
| 129 |
|
129 |
|
| 130 |
subtest 'Password validation - authorized requests tests' => sub { |
130 |
subtest 'Password validation - authorized requests tests' => sub { |
| 131 |
|
131 |
|
| 132 |
plan tests => 24; |
132 |
plan tests => 25; |
| 133 |
|
133 |
|
| 134 |
$schema->storage->txn_begin; |
134 |
$schema->storage->txn_begin; |
| 135 |
|
135 |
|
|
Lines 216-221
subtest 'Password validation - authorized requests tests' => sub {
Link Here
|
| 216 |
->status_is( 400, 'Passing both parameters forbidden' ) |
216 |
->status_is( 400, 'Passing both parameters forbidden' ) |
| 217 |
->json_is( { error => 'Bad request. Only one identifier attribute can be passed.' } ); |
217 |
->json_is( { error => 'Bad request. Only one identifier attribute can be passed.' } ); |
| 218 |
|
218 |
|
|
|
219 |
subtest 'TrackLastPatronActivityTriggers tests' => sub { |
| 220 |
|
| 221 |
plan tests => 12; |
| 222 |
|
| 223 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { lastseen => undef } } ); |
| 224 |
my $patron_password = 'thePassword123'; |
| 225 |
$patron->set_password( { password => $patron_password, skip_validation => 1 } ); |
| 226 |
|
| 227 |
# to avoid interference |
| 228 |
t::lib::Mocks::mock_preference( 'FailedLoginAttempts', 99 ); |
| 229 |
|
| 230 |
# All good but TrackLastPatronActivity disabled |
| 231 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'api_verify' ); |
| 232 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', 0 ); |
| 233 |
|
| 234 |
$t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => |
| 235 |
{ identifier => $patron->userid, password => $patron_password } )->status_is( 201, 'Validation works' ); |
| 236 |
|
| 237 |
# read patron from the DB |
| 238 |
$patron->discard_changes(); |
| 239 |
is( $patron->lastseen, undef, "'lastseen' flag untouched if TrackLastPatronActivity is disabled" ); |
| 240 |
|
| 241 |
# TrackLastPatronActivity enabled but api_verify disabled |
| 242 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login' ); |
| 243 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', 1 ); |
| 244 |
|
| 245 |
$patron->lastseen(undef)->store(); |
| 246 |
$t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => |
| 247 |
{ identifier => $patron->userid, password => $patron_password } )->status_is( 201, 'Validation works' ); |
| 248 |
|
| 249 |
# read patron from the DB |
| 250 |
$patron->discard_changes(); |
| 251 |
is( |
| 252 |
$patron->lastseen, undef, |
| 253 |
"'lastseen' flag untouched if TrackLastPatronActivity enabled but no 'api_verify' in TrackLastPatronActivityTriggers" |
| 254 |
); |
| 255 |
|
| 256 |
# good scenario |
| 257 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'api_verify' ); |
| 258 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', 1 ); |
| 259 |
|
| 260 |
$patron->lastseen(undef)->store(); |
| 261 |
$t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => |
| 262 |
{ identifier => $patron->userid, password => 'wrong password :-D' } ) |
| 263 |
->status_is( 400, 'Validation failed due to bad password' ); |
| 264 |
|
| 265 |
# read patron from the DB |
| 266 |
$patron->discard_changes(); |
| 267 |
is( $patron->lastseen, undef, "'lastseen' flag not updated as validation failed" ); |
| 268 |
|
| 269 |
$patron->lastseen(undef)->store(); |
| 270 |
$t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => |
| 271 |
{ identifier => $patron->userid, password => $patron_password } )->status_is( 201, 'Validation works' ); |
| 272 |
|
| 273 |
# read patron from the DB |
| 274 |
$patron->discard_changes(); |
| 275 |
ok( |
| 276 |
$patron->lastseen, |
| 277 |
"'lastseen' flag updated if TrackLastPatronActivity and TrackLastPatronActivityTriggers includes 'api_verify'" |
| 278 |
); |
| 279 |
}; |
| 280 |
|
| 219 |
$schema->storage->txn_rollback; |
281 |
$schema->storage->txn_rollback; |
| 220 |
}; |
282 |
}; |
| 221 |
|
283 |
|
| 222 |
- |
|
|