Lines 18-24
Link Here
|
18 |
|
18 |
|
19 |
use Modern::Perl; |
19 |
use Modern::Perl; |
20 |
|
20 |
|
21 |
use Test::More tests => 6; |
21 |
use Test::More tests => 4; |
22 |
use Test::Mojo; |
22 |
use Test::Mojo; |
23 |
|
23 |
|
24 |
use t::lib::TestBuilder; |
24 |
use t::lib::TestBuilder; |
Lines 45-68
my $password = 'thePassword123';
Link Here
|
45 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
45 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
46 |
my $userid = $librarian->userid; |
46 |
my $userid = $librarian->userid; |
47 |
|
47 |
|
48 |
subtest 'password validation - success' => sub { |
|
|
49 |
|
50 |
plan tests => 3; |
51 |
|
52 |
$schema->storage->txn_begin; |
53 |
|
54 |
my $json = { |
55 |
"userid" => $userid, |
56 |
"password" => $password, |
57 |
}; |
58 |
|
59 |
$t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => $json ) |
60 |
->status_is(204) |
61 |
->content_is(q{}); |
62 |
|
63 |
$schema->storage->txn_rollback; |
64 |
}; |
65 |
|
66 |
subtest 'password validation - account lock out' => sub { |
48 |
subtest 'password validation - account lock out' => sub { |
67 |
|
49 |
|
68 |
plan tests => 6; |
50 |
plan tests => 6; |
Lines 72-79
subtest 'password validation - account lock out' => sub {
Link Here
|
72 |
t::lib::Mocks::mock_preference( 'FailedLoginAttempts', 1 ); |
54 |
t::lib::Mocks::mock_preference( 'FailedLoginAttempts', 1 ); |
73 |
|
55 |
|
74 |
my $json = { |
56 |
my $json = { |
75 |
"userid" => $userid, |
57 |
identifier => $userid, |
76 |
"password" => "bad", |
58 |
password => "bad", |
77 |
}; |
59 |
}; |
78 |
|
60 |
|
79 |
$t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => $json ) |
61 |
$t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => $json ) |
Lines 89-131
subtest 'password validation - account lock out' => sub {
Link Here
|
89 |
$schema->storage->txn_rollback; |
71 |
$schema->storage->txn_rollback; |
90 |
}; |
72 |
}; |
91 |
|
73 |
|
92 |
|
|
|
93 |
subtest 'password validation - bad userid' => sub { |
94 |
|
95 |
plan tests => 3; |
96 |
|
97 |
$schema->storage->txn_begin; |
98 |
|
99 |
my $json = { |
100 |
"userid" => '1234567890abcdefghijklmnopqrstuvwxyz@koha-community.org', |
101 |
"password" => $password, |
102 |
}; |
103 |
|
104 |
$t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => $json ) |
105 |
->status_is(400) |
106 |
->json_is({ error => q{Validation failed} }); |
107 |
|
108 |
$schema->storage->txn_rollback; |
109 |
}; |
110 |
|
111 |
subtest 'password validation - bad password' => sub { |
112 |
|
113 |
plan tests => 3; |
114 |
|
115 |
$schema->storage->txn_begin; |
116 |
|
117 |
my $json = { |
118 |
"userid" => $userid, |
119 |
"password" => 'bad', |
120 |
}; |
121 |
|
122 |
$t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => $json ) |
123 |
->status_is(400) |
124 |
->json_is({ error => q{Validation failed} }); |
125 |
|
126 |
$schema->storage->txn_rollback; |
127 |
}; |
128 |
|
129 |
subtest 'password validation - unauthorized user' => sub { |
74 |
subtest 'password validation - unauthorized user' => sub { |
130 |
|
75 |
|
131 |
plan tests => 3; |
76 |
plan tests => 3; |
Lines 143-150
subtest 'password validation - unauthorized user' => sub {
Link Here
|
143 |
my $userid = $patron->userid; |
88 |
my $userid = $patron->userid; |
144 |
|
89 |
|
145 |
my $json = { |
90 |
my $json = { |
146 |
"userid" => $userid, |
91 |
identifier => $userid, |
147 |
"password" => "test", |
92 |
password => "test", |
148 |
}; |
93 |
}; |
149 |
|
94 |
|
150 |
$t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => $json ) |
95 |
$t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => $json ) |
Lines 160-167
subtest 'password validation - unauthenticated user' => sub {
Link Here
|
160 |
$schema->storage->txn_begin; |
105 |
$schema->storage->txn_begin; |
161 |
|
106 |
|
162 |
my $json = { |
107 |
my $json = { |
163 |
"userid" => "banana", |
108 |
identifier => "banana", |
164 |
"password" => "test", |
109 |
password => "test", |
165 |
}; |
110 |
}; |
166 |
|
111 |
|
167 |
$t->post_ok( "/api/v1/auth/password/validation" => json => $json ) |
112 |
$t->post_ok( "/api/v1/auth/password/validation" => json => $json ) |
Lines 171-174
subtest 'password validation - unauthenticated user' => sub {
Link Here
|
171 |
$schema->storage->txn_rollback; |
116 |
$schema->storage->txn_rollback; |
172 |
}; |
117 |
}; |
173 |
|
118 |
|
|
|
119 |
subtest 'Password validation - authorized requests tests' => sub { |
120 |
|
121 |
plan tests => 9; |
122 |
|
123 |
$schema->storage->txn_begin; |
124 |
|
125 |
my $json = { |
126 |
identifier => $librarian->userid, |
127 |
password => $password, |
128 |
}; |
129 |
|
130 |
$t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => $json ) |
131 |
->status_is(204, 'Validating using `cardnumber` works') |
132 |
->content_is(q{}); |
133 |
|
134 |
$json = { |
135 |
identifier => $librarian->cardnumber, |
136 |
password => $password, |
137 |
}; |
138 |
|
139 |
$t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => $json ) |
140 |
->status_is(204, 'Validating using `cardnumber` works') |
141 |
->content_is(q{}); |
142 |
|
143 |
$json = { |
144 |
identifier => 'banana', |
145 |
password => $password, |
146 |
}; |
147 |
|
148 |
$t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => $json ) |
149 |
->status_is(400, 'Validating using and invalid identifier fails') |
150 |
->json_is({ error => q{Validation failed} }); |
151 |
|
152 |
$schema->storage->txn_rollback; |
153 |
}; |
154 |
|
174 |
$schema->storage->txn_rollback; |
155 |
$schema->storage->txn_rollback; |
175 |
- |
|
|