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 => 9; |
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 |
# api_verify disabled |
231 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login' ); |
232 |
|
233 |
$patron->lastseen(undef)->store(); |
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( |
240 |
$patron->lastseen, undef, |
241 |
"'lastseen' flag untouched if no 'api_verify' in TrackLastPatronActivityTriggers" |
242 |
); |
243 |
|
244 |
# good scenario |
245 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'api_verify' ); |
246 |
|
247 |
$patron->lastseen(undef)->store(); |
248 |
$t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => |
249 |
{ identifier => $patron->userid, password => 'wrong password :-D' } ) |
250 |
->status_is( 400, 'Validation failed due to bad password' ); |
251 |
|
252 |
# read patron from the DB |
253 |
$patron->discard_changes(); |
254 |
is( $patron->lastseen, undef, "'lastseen' flag not updated as validation failed" ); |
255 |
|
256 |
$patron->lastseen(undef)->store(); |
257 |
$t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => |
258 |
{ identifier => $patron->userid, password => $patron_password } )->status_is( 201, 'Validation works' ); |
259 |
|
260 |
# read patron from the DB |
261 |
$patron->discard_changes(); |
262 |
ok( |
263 |
$patron->lastseen, |
264 |
"'lastseen' flag updated TrackLastPatronActivityTriggers includes 'api_verify'" |
265 |
); |
266 |
}; |
267 |
|
219 |
$schema->storage->txn_rollback; |
268 |
$schema->storage->txn_rollback; |
220 |
}; |
269 |
}; |
221 |
|
270 |
|
222 |
- |
|
|