3 use Test::More tests => 10; # XXX
5 diag("Tests RemoteAuth patron auth/retrieval");
7 use strict; use warnings;
8 use OpenILS::Utils::TestUtils;
12 use OpenILS::Utils::CStoreEditor qw/:funcs/;
13 use OpenILS::Application::AppUtils;
14 our $U = "OpenILS::Application::AppUtils";
16 OpenILS::Utils::TestUtils->new->bootstrap;
18 my $not_found = { barcode => '99999393000', password => 'nonexistentbarcode' };
19 my $expired = { barcode => '99999393001', password => 'marges1234' };
20 my $deleted = { barcode => '99999393002', password => 'homers1234' };
21 my $barred = { barcode => '99999393003', password => 'barts1234' };
22 my $valid = { barcode => '99999393004', password => 'lisas1234' };
23 my $inactive = { barcode => '99999393005', password => 'maggies1234' };
24 my $external = { barcode => '99999393100', password => 'shelbyvillem1234' };
26 # context org is SYS1, test user's home OU is BR1;
27 # use BR3 (under SYS2) to test external users
28 my $external_org = 6; # BR3
30 my $staff_login = $U->simplereq(
32 'open-ils.auth.login', {
34 password => 'demo123',
38 is($staff_login->{textcode}, 'SUCCESS', 'Staff login OK');
39 my $e = new_editor( authtoken => $staff_login->{payload}->{authtoken} );
42 my $client = LWP::UserAgent->new;
43 $client->ssl_opts( verify_hostname => 0 );
45 # my $res = $client->request( $method, $uri, $headers, $content, $request_timeout );
48 ######################################################################
51 # - validate barcode only?
52 # - validate barcode + PIN
53 # - retrieve user and check for required fields in response
56 # - valid user with username or barcode (opac.barcode_regex)
57 # - valid user with barcode prefix
58 # - valid user with barcode
64 # - user has non-blocking penalties, auth/retrieval succeeds
65 # - user has blocking penalties
66 # - user exists, but home OU is not in scope
68 # not currently supported:
69 # - AuthProxy: services should use the remote auth server directly
70 # - opted-in patrons: these are external patrons and thus not auth'd
72 ######################################################################
74 #---------------------------------------------------------------------
75 # Basic access authentication (RFC 7617)
76 #---------------------------------------------------------------------
77 # - endpoint: /api/basicauth
79 # - request: includes "Authorization: Basic <credentials>" header,
80 # credentials = Base64-encoded "id:password" string
81 # - response: HTTP 200 on success, 401 with WWW-Authenticate header
83 # - does not return patron info
84 #---------------------------------------------------------------------
86 my ($u, $password) = @_;
87 my $barcode = $u->{barcode};
88 $password ||= $u->{password};
89 my $resp = $client->get(
90 "https://localhost/api/basicauth",
91 'Authorization' => 'Basic ' . encode_base64("$barcode:$password")
96 my $basic_not_found = basic_request($not_found);
97 is ( $basic_not_found, '403', 'Basic request for nonexistent barcode correctly returned 403' );
99 my $basic_success = basic_request($valid);
100 is( $basic_success, '200', 'Basic request for valid patron OK' );
103 my $basic_invalid_pw = basic_request($valid, 'badpassword');
104 is( $basic_invalid_pw, '403', 'Basic request with invalid password correctly returned 403' );
107 my $basic_deleted = basic_request($deleted);
108 is( $basic_deleted, '403', 'Basic request for deleted user correctly returned 403' );
111 my $basic_expired = basic_request($expired);
112 is( $basic_expired, '403', 'Basic request for expired user correctly returned 403' );
115 my $basic_inactive = basic_request($inactive);
116 is( $basic_inactive, '403', 'Basic request for inactive user correctly returned 403' );
119 my $basic_barred = basic_request($barred);
120 is( $basic_barred, '403', 'Basic request for barred user correctly returned 403' );
122 # home OU is not in scope
123 my $basic_external = basic_request($external);
124 is( $basic_external, '403', 'Basic request for external user correctly returned 403' );
126 # TODO: user has blocking penalties
128 # TODO: user has non-blocking penalties, auth/retrieval succeeds
132 # TODO: EZProxy external script authentication:
133 # - endpoint: /remoteauth/ezproxy/<shortname>/<id>/<password>
134 # - client auth: none
135 # - request: GET with user and pass params, as above
136 # - response: "+VALID" if auth succeeds
139 # verify user activity based on the above tests
140 my $user = $U->fetch_user_by_barcode( $valid->{barcode} );
141 my $basic_activity = $e->search_actor_usr_activity([{usr => $user->id, etype => 1001}]);
142 ok(scalar(@$basic_activity) > 0, 'Basic request for valid patron is recorded in user activity');