3 use Test::More tests => 27;
5 diag("Tests open-ils.auth.login");
7 use strict; use warnings;
8 use OpenILS::Utils::TestUtils;
9 use OpenILS::Application::AppUtils;
10 use OpenSRF::Utils::Cache;
11 use Digest::MD5 qw/md5_hex/;
12 our $U = "OpenILS::Application::AppUtils";
14 OpenILS::Utils::TestUtils->new->bootstrap;
16 my $resp = $U->simplereq(
18 'open-ils.auth.login', {
20 password => 'demo123',
25 is($resp->{textcode}, 'SUCCESS', 'Admin username login OK');
27 my $authtoken = $resp->{payload}->{authtoken};
28 ok($authtoken, 'Have an authtoken');
30 $resp = $U->simplereq(
32 'open-ils.auth.session.retrieve', $authtoken);
35 (ref($resp) && !$U->event_code($resp) && $resp->usrname eq 'admin'),
36 'Able to retrieve session'
39 $resp = $U->simplereq(
41 'open-ils.auth.login', {
43 password => 'demo123x', # bad password
48 isnt($resp->{textcode}, 'SUCCESS', 'Admin bad password rejected');
50 $resp = $U->simplereq(
52 'open-ils.auth.login', {
53 barcode => '99999381970',
54 password => 'montyc1234',
59 is($resp->{textcode}, 'SUCCESS', '99999381970 login OK');
61 $resp = $U->simplereq(
63 'open-ils.auth.login', {
64 identifier => 'br1mclark',
65 password => 'montyc1234',
70 is($resp->{textcode}, 'SUCCESS', 'Identifier check for br1mclark OK');
72 foreach my $i (1..15) {
73 $resp = $U->simplereq(
75 'open-ils.auth.login', {
76 identifier => 'br1mclark',
77 password => 'justplainwrong',
81 isnt($resp->{textcode}, 'SUCCESS', "Attempt $i: wrong password br1mclark does not work");
84 $resp = $U->simplereq(
86 'open-ils.auth.login', {
87 identifier => 'br1mclark',
88 password => 'montyc1234',
92 isnt($resp->{textcode}, 'SUCCESS', '... and consequently multiple failed attempts block');
95 my $cache = OpenSRF::Utils::Cache->new("global", 0);
96 $cache->delete_cache('oils_auth_br1mclark_count');
99 my $new_pwd = 'password%';
101 my $user = $U->simplereq(
103 'open-ils.actor.user.fleshed.retrieve_by_barcode',
107 $user->passwd($new_pwd);
108 $resp = $U->simplereq(
110 'open-ils.actor.patron.update',
114 isa_ok($resp, 'Fieldmapper::actor::user', 'test password updated');
116 my $seed = $U->simplereq(
118 'open-ils.auth.authenticate.init',
121 ok(defined $seed, 'Got an auth seed');
123 my $hashed_pwd = md5_hex($seed . md5_hex($new_pwd));
124 $resp = $U->simplereq(
126 'open-ils.auth.authenticate.complete',
128 username => 'br1mclark',
129 password => $hashed_pwd,
133 is($resp->{textcode}, 'SUCCESS', '.complete succeeds when password contains %');
135 $resp = $U->simplereq(
137 'open-ils.auth.login', {
138 identifier => 'br1mclark',
139 password => $new_pwd,
143 is($resp->{textcode}, 'SUCCESS', '.login succeeds when password contains %');
146 my $restored_user = $U->simplereq(
148 'open-ils.actor.user.fleshed.retrieve_by_barcode',
152 $restored_user->passwd('montyc1234');
153 $resp = $U->simplereq(
155 'open-ils.actor.patron.update',
159 isa_ok($resp, 'Fieldmapper::actor::user', 'test password reverted');