Lines 7-13
use Modern::Perl;
Link Here
|
7 |
use Test::More tests => 6; |
7 |
use Test::More tests => 6; |
8 |
use Test::MockModule; |
8 |
use Test::MockModule; |
9 |
use Test::Warn; |
9 |
use Test::Warn; |
10 |
use DBD::Mock; |
10 |
use Test::DBIx::Class {schema_class => 'Koha::Schema', connect_info => ['dbi:SQLite:dbname=:memory:','','']}; |
11 |
|
11 |
|
12 |
use CGI; |
12 |
use CGI; |
13 |
use C4::Context; |
13 |
use C4::Context; |
Lines 17-41
my $matchpoint = 'userid';
Link Here
|
17 |
my %mapping = ( 'userid' => { 'is' => 'uid' }, ); |
17 |
my %mapping = ( 'userid' => { 'is' => 'uid' }, ); |
18 |
$ENV{'uid'} = "test1234"; |
18 |
$ENV{'uid'} = "test1234"; |
19 |
|
19 |
|
20 |
#my %shibboleth = ( |
|
|
21 |
# 'matchpoint' => $matchpoint, |
22 |
# 'mapping' => \%mapping |
23 |
#); |
24 |
|
25 |
# Setup Mocks |
20 |
# Setup Mocks |
26 |
## Mock Context |
21 |
## Mock Context |
27 |
my $context = new Test::MockModule('C4::Context'); |
22 |
my $context = new Test::MockModule('C4::Context'); |
28 |
|
23 |
|
29 |
### Mock ->dbh |
|
|
30 |
$context->mock( |
31 |
'_new_dbh', |
32 |
sub { |
33 |
my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) |
34 |
|| die "Cannot create handle: $DBI::errstr\n"; |
35 |
return $dbh; |
36 |
} |
37 |
); |
38 |
|
39 |
### Mock ->config |
24 |
### Mock ->config |
40 |
$context->mock( 'config', \&mockedConfig ); |
25 |
$context->mock( 'config', \&mockedConfig ); |
41 |
|
26 |
|
Lines 64-71
sub mockedPref {
Link Here
|
64 |
return $return; |
49 |
return $return; |
65 |
} |
50 |
} |
66 |
|
51 |
|
67 |
# Convenience methods |
52 |
## Mock Database |
68 |
## Reset Context |
53 |
my $database = new Test::MockModule('Koha::Database'); |
|
|
54 |
|
55 |
### Mock ->schema |
56 |
$database->mock( 'schema', \&mockedSchema ); |
57 |
|
58 |
sub mockedSchema { |
59 |
return Schema(); |
60 |
} |
61 |
|
62 |
## Convenience method to reset config |
69 |
sub reset_config { |
63 |
sub reset_config { |
70 |
$matchpoint = 'userid'; |
64 |
$matchpoint = 'userid'; |
71 |
%mapping = ( 'userid' => { 'is' => 'uid' }, ); |
65 |
%mapping = ( 'userid' => { 'is' => 'uid' }, ); |
Lines 75-81
sub reset_config {
Link Here
|
75 |
} |
69 |
} |
76 |
|
70 |
|
77 |
# Tests |
71 |
# Tests |
78 |
my $dbh = C4::Context->dbh(); |
72 |
############################################################## |
79 |
|
73 |
|
80 |
# Can module load |
74 |
# Can module load |
81 |
use_ok('C4::Auth_with_shibboleth'); |
75 |
use_ok('C4::Auth_with_shibboleth'); |
Lines 155-175
subtest "get_login_shib tests" => sub {
Link Here
|
155 |
|
149 |
|
156 |
## checkpw_shib |
150 |
## checkpw_shib |
157 |
subtest "checkpw_shib tests" => sub { |
151 |
subtest "checkpw_shib tests" => sub { |
158 |
plan tests => 12; |
152 |
plan tests => 13; |
159 |
|
|
|
160 |
my $shib_login = 'test1234'; |
161 |
my @borrower_results = |
162 |
( [ 'cardnumber', 'userid' ], [ 'testcardnumber', 'test1234' ], ); |
163 |
$dbh->{mock_add_resultset} = \@borrower_results; |
164 |
|
153 |
|
|
|
154 |
my $shib_login; |
165 |
my ( $retval, $retcard, $retuserid ); |
155 |
my ( $retval, $retcard, $retuserid ); |
166 |
|
156 |
|
|
|
157 |
# Setup Mock Database Data |
158 |
fixtures_ok [ |
159 |
'Borrower' => [ |
160 |
[qw/cardnumber userid surname address city/], |
161 |
[qw/testcardnumber test1234 renvoize myaddress johnston/], |
162 |
], |
163 |
], |
164 |
'Installed some custom fixtures via the Populate fixture class'; |
165 |
|
167 |
# debug off |
166 |
# debug off |
168 |
$C4::Auth_with_shibboleth::debug = '0'; |
167 |
$C4::Auth_with_shibboleth::debug = '0'; |
169 |
|
168 |
|
170 |
# good user |
169 |
# good user |
|
|
170 |
$shib_login = "test1234"; |
171 |
warnings_are { |
171 |
warnings_are { |
172 |
( $retval, $retcard, $retuserid ) = checkpw_shib( $dbh, $shib_login ); |
172 |
( $retval, $retcard, $retuserid ) = checkpw_shib( $shib_login ); |
173 |
} |
173 |
} |
174 |
[], "good user with no debug"; |
174 |
[], "good user with no debug"; |
175 |
is( $retval, "1", "user authenticated" ); |
175 |
is( $retval, "1", "user authenticated" ); |
Lines 177-197
subtest "checkpw_shib tests" => sub {
Link Here
|
177 |
is( $retuserid, "test1234", "expected userid returned" ); |
177 |
is( $retuserid, "test1234", "expected userid returned" ); |
178 |
|
178 |
|
179 |
# bad user |
179 |
# bad user |
|
|
180 |
$shib_login = 'martin'; |
180 |
warnings_are { |
181 |
warnings_are { |
181 |
( $retval, $retcard, $retuserid ) = checkpw_shib( $dbh, $shib_login ); |
182 |
( $retval, $retcard, $retuserid ) = checkpw_shib( $shib_login ); |
182 |
} |
183 |
} |
183 |
[], "bad user with no debug"; |
184 |
[], "bad user with no debug"; |
184 |
is( $retval, "0", "user not authenticated" ); |
185 |
is( $retval, "0", "user not authenticated" ); |
185 |
|
186 |
|
186 |
# reset db mock |
|
|
187 |
$dbh->{mock_add_resultset} = \@borrower_results; |
188 |
|
189 |
# debug on |
187 |
# debug on |
190 |
$C4::Auth_with_shibboleth::debug = '1'; |
188 |
$C4::Auth_with_shibboleth::debug = '1'; |
191 |
|
189 |
|
192 |
# good user |
190 |
# good user |
|
|
191 |
$shib_login = "test1234"; |
193 |
warnings_exist { |
192 |
warnings_exist { |
194 |
( $retval, $retcard, $retuserid ) = checkpw_shib( $dbh, $shib_login ); |
193 |
( $retval, $retcard, $retuserid ) = checkpw_shib( $shib_login ); |
195 |
} |
194 |
} |
196 |
[ qr/checkpw_shib/, qr/User Shibboleth-authenticated as:/ ], |
195 |
[ qr/checkpw_shib/, qr/User Shibboleth-authenticated as:/ ], |
197 |
"good user with debug enabled"; |
196 |
"good user with debug enabled"; |
Lines 200-207
subtest "checkpw_shib tests" => sub {
Link Here
|
200 |
is( $retuserid, "test1234", "expected userid returned" ); |
199 |
is( $retuserid, "test1234", "expected userid returned" ); |
201 |
|
200 |
|
202 |
# bad user |
201 |
# bad user |
|
|
202 |
$shib_login = "martin"; |
203 |
warnings_exist { |
203 |
warnings_exist { |
204 |
( $retval, $retcard, $retuserid ) = checkpw_shib( $dbh, $shib_login ); |
204 |
( $retval, $retcard, $retuserid ) = checkpw_shib( $shib_login ); |
205 |
} |
205 |
} |
206 |
[ |
206 |
[ |
207 |
qr/checkpw_shib/, |
207 |
qr/checkpw_shib/, |
Lines 218-220
is( C4::Auth_with_shibboleth::_get_uri(),
Link Here
|
218 |
"https://testopac.com", "https opac uri returned" ); |
218 |
"https://testopac.com", "https opac uri returned" ); |
219 |
|
219 |
|
220 |
## _get_shib_config |
220 |
## _get_shib_config |
221 |
- |
221 |
# Internal helper function, covered in tests above |