#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
#
-# Add more tests here!!!
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
-use Test::More tests => 6;
+$| = 1;
+use Module::Load::Conditional qw/check_install/;
+use Test::More;
use Test::MockModule;
use Test::Warn;
-use Test::DBIx::Class {schema_class => 'Koha::Schema', connect_info => ['dbi:SQLite:dbname=:memory:','','']};
use CGI;
use C4::Context;
+BEGIN {
+ if ( check_install( module => 'Test::DBIx::Class' ) ) {
+ plan tests => 11;
+ } else {
+ plan skip_all => "Need Test::DBIx::Class"
+ }
+}
+
+use Test::DBIx::Class { schema_class => 'Koha::Schema', connect_info => ['dbi:SQLite:dbname=:memory:','',''] };
+
# Mock Variables
my $matchpoint = 'userid';
my %mapping = ( 'userid' => { 'is' => 'uid' }, );
}
### Mock ->preference
+my $OPACBaseURL = "testopac.com";
$context->mock( 'preference', \&mockedPref );
sub mockedPref {
my $return;
if ( $param eq 'OPACBaseURL' ) {
- $return = "testopac.com";
+ $return = $OPACBaseURL;
}
return $return;
is( $login, "test1234",
"good config with debug enabled, attribute value returned" );
-# bad config - with shib_ok implimented, we should never reach this sub with a bad config
+# bad config - with shib_ok implemented, we should never reach this sub with a bad config
};
## checkpw_shib
warnings_exist {
( $retval, $retcard, $retuserid ) = checkpw_shib( $shib_login );
}
- [ qr/checkpw_shib/, qr/User Shibboleth-authenticated as:/ ],
+ [ qr/checkpw_shib/, qr/koha borrower field to match: userid/,
+ qr/shibboleth attribute to match: uid/,
+ qr/User Shibboleth-authenticated as:/ ],
"good user with debug enabled";
is( $retval, "1", "user authenticated" );
is( $retcard, "testcardnumber", "expected cardnumber returned" );
}
[
qr/checkpw_shib/,
+ qr/koha borrower field to match: userid/,
+ qr/shibboleth attribute to match: uid/,
qr/User Shibboleth-authenticated as:/,
qr/not a valid Koha user/
],
};
## _get_uri
+$OPACBaseURL = "testopac.com";
+is( C4::Auth_with_shibboleth::_get_uri(),
+ "https://testopac.com", "https opac uri returned" );
+
+$OPACBaseURL = "http://testopac.com";
+my $result;
+warning_like { $result = C4::Auth_with_shibboleth::_get_uri() }
+ [ qr/Shibboleth requires OPACBaseURL to use the https protocol!/ ],
+ "improper protocol - received expected warning";
+is( $result, "https://testopac.com", "https opac uri returned" );
+
+$OPACBaseURL = "https://testopac.com";
is( C4::Auth_with_shibboleth::_get_uri(),
"https://testopac.com", "https opac uri returned" );
+$OPACBaseURL = undef;
+warning_like { $result = C4::Auth_with_shibboleth::_get_uri() }
+ [ qr/OPACBaseURL not set!/ ],
+ "undefined OPACBaseURL - received expected warning";
+is( $result, "https://", "https opac uri returned" );
+
## _get_shib_config
# Internal helper function, covered in tests above