3 use Test::More tests => 4;
5 diag("Simple tests against the open-ils.auth service, memcached, and the stock test data.");
11 use OpenSRF::AppSession;
12 use Digest::MD5 qw(md5_hex);
13 use OpenILS::Application::AppUtils;
14 use OpenSRF::Utils::SettingsClient;
17 our $cache = "OpenSRF::Utils::Cache";
18 our $apputils = "OpenILS::Application::AppUtils";
23 #----------------------------------------------------------------
25 #----------------------------------------------------------------
27 my ($pkg, $file, $line, $sub) = _caller();
29 die "Script halted with error ".
30 "($pkg : $file : $line : $sub):\n" . shift() . "\n";
33 #----------------------------------------------------------------
34 # This is not the function you're looking for
35 #----------------------------------------------------------------
37 my ($pkg, $file, $line, $sub) = caller(2);
39 ($pkg, $file, $line) = caller(1);
42 return ($pkg, $file, $line, $sub);
45 #----------------------------------------------------------------
46 # Connect to the servers
47 #----------------------------------------------------------------
49 my $config = `osrf_config --sysconfdir`;
51 $config .= '/opensrf_core.xml';
52 err("Bootstrap config required") unless $config;
53 OpenSRF::System->bootstrap_client( config_file => $config );
56 #----------------------------------------------------------------
57 # Get a handle for the memcache object
58 #----------------------------------------------------------------
61 $memcache = $cache->new('global') unless $memcache;
65 #----------------------------------------------------------------
66 # Is the given object an OILS event?
67 #----------------------------------------------------------------
70 if( $e and ref($e) eq 'HASH' ) {
71 return 1 if defined($e->{ilsevent});
76 #----------------------------------------------------------------
77 # If the given object is an event, this prints the event info
78 # and exits the script
79 #----------------------------------------------------------------
82 my ($pkg, $file, $line, $sub) = _caller();
83 if(oils_is_event($evt)) {
84 if($evt->{ilsevent}) {
85 diag("\nReceived Event($pkg : $file : $line : $sub): \n" . Dumper($evt));
91 #----------------------------------------------------------------
92 # Login to the auth server and set the global $authtoken var
93 #----------------------------------------------------------------
95 my( $username, $password, $type ) = @_;
99 my $seed = $apputils->simplereq( 'open-ils.auth',
100 'open-ils.auth.authenticate.init', $username );
101 err("No auth seed") unless $seed;
103 my $response = $apputils->simplereq( 'open-ils.auth',
104 'open-ils.auth.authenticate.complete',
105 { username => $username,
106 password => md5_hex($seed . md5_hex($password)),
109 err("No auth response returned on login") unless $response;
111 oils_event_die($response);
113 $authtime = $response->{payload}->{authtime};
114 $authtoken = $response->{payload}->{authtoken};
115 diag("authtime is $authtime, authtoken is $authtoken");
119 #----------------------------------------------------------------
120 # Destroys the login session on the server
121 #----------------------------------------------------------------
123 $apputils->simplereq(
125 'open-ils.auth.session.delete', (@_ ? shift : $authtoken) );
128 #----------------------------------------------------------------
129 # var $response = simplereq( $service, $method, @params );
130 #----------------------------------------------------------------
131 sub simplereq { return $apputils->simplereq(@_); }
132 sub osrf_request { return $apputils->simplereq(@_); }
134 #----------------------------------------------------------------
135 # The tests... assumes stock sample data, full-auto install by
136 # eg_wheezy_installer.sh, etc.
137 #----------------------------------------------------------------
140 oils_login('admin','demo123','staff');
149 'Default authtime for staff login is 7200 seconds'
153 my $cached_obj = $memcache->get_cache("oils_auth_$authtoken");
157 'Can retrieve authtoken from memcached'
162 $cached_obj = $memcache->get_cache("oils_auth_$authtoken");
165 'Authtoken is removed from memcached after logout'