]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/live_t/24-lp1710949-login-api.t
LP#1710949: add tests for blocking after failed attempts
[working/Evergreen.git] / Open-ILS / src / perlmods / live_t / 24-lp1710949-login-api.t
1 #!perl
2
3 use Test::More tests => 22;
4
5 diag("Tests open-ils.auth.login");
6
7 use strict; use warnings;
8 use OpenILS::Utils::TestUtils;
9 use OpenILS::Application::AppUtils;
10 use OpenSRF::Utils::Cache;
11 our $U = "OpenILS::Application::AppUtils";
12
13 OpenILS::Utils::TestUtils->new->bootstrap;
14
15 my $resp = $U->simplereq(
16     'open-ils.auth',
17     'open-ils.auth.login', {
18         username => 'admin',
19         password => 'demo123',
20         type => 'staff'
21     }
22 );
23
24 is($resp->{textcode}, 'SUCCESS', 'Admin username login OK');
25
26 my $authtoken = $resp->{payload}->{authtoken};
27 ok($authtoken, 'Have an authtoken');
28
29 $resp = $U->simplereq(
30     'open-ils.auth',
31     'open-ils.auth.session.retrieve', $authtoken);
32
33 ok( 
34     (ref($resp) && !$U->event_code($resp) && $resp->usrname eq 'admin'), 
35     'Able to retrieve session'
36 );
37
38 $resp = $U->simplereq(
39     'open-ils.auth',
40     'open-ils.auth.login', {
41         username => 'admin',
42         password => 'demo123x', # bad password
43         type => 'staff'
44     }
45 );
46
47 isnt($resp->{textcode}, 'SUCCESS', 'Admin bad password rejected');
48
49 $resp = $U->simplereq(
50     'open-ils.auth',
51     'open-ils.auth.login', {
52         barcode => '99999381970',
53         password => 'montyc1234',
54         type => 'staff'
55     }
56 );
57
58 is($resp->{textcode}, 'SUCCESS', '99999381970 login OK');
59
60 $resp = $U->simplereq(
61     'open-ils.auth',
62     'open-ils.auth.login', {
63         identifier => 'br1mclark',
64         password => 'montyc1234',
65         type => 'staff'
66     }
67 );
68
69 is($resp->{textcode}, 'SUCCESS', 'Identifier check for br1mclark OK');
70
71 foreach my $i (1..15) {
72     $resp = $U->simplereq(
73         'open-ils.auth',
74         'open-ils.auth.login', {
75             identifier => 'br1mclark',
76             password => 'justplainwrong',
77             type => 'staff'
78         }
79     );
80     isnt($resp->{textcode}, 'SUCCESS', "Attempt $i: wrong password br1mclark does not work");
81 }
82
83 $resp = $U->simplereq(
84     'open-ils.auth',
85     'open-ils.auth.login', {
86         identifier => 'br1mclark',
87         password => 'montyc1234',
88         type => 'staff'
89     }
90 );
91 isnt($resp->{textcode}, 'SUCCESS', '... and consequently multiple failed attempts block');
92
93 # and clean up
94 my $cache = OpenSRF::Utils::Cache->new("global", 0);
95 $cache->delete_cache('oils_auth_br1mclark_count');