Bug 16154: CGI->multi_param - Declare a list
[koha.git] / t / Auth_with_shibboleth.t
index 0a39b9b..0c34fc5 100644 (file)
@@ -1,17 +1,41 @@
 #!/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' }, );
@@ -36,6 +60,7 @@ sub mockedConfig {
 }
 
 ### Mock ->preference
+my $OPACBaseURL = "testopac.com";
 $context->mock( 'preference', \&mockedPref );
 
 sub mockedPref {
@@ -43,7 +68,7 @@ sub mockedPref {
     my $return;
 
     if ( $param eq 'OPACBaseURL' ) {
-        $return = "testopac.com";
+        $return = $OPACBaseURL;
     }
 
     return $return;
@@ -144,7 +169,7 @@ subtest "get_login_shib tests" => sub {
     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
@@ -192,7 +217,9 @@ subtest "checkpw_shib tests" => sub {
     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" );
@@ -205,6 +232,8 @@ subtest "checkpw_shib tests" => sub {
     }
     [
         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/
     ],
@@ -214,8 +243,26 @@ subtest "checkpw_shib tests" => sub {
 };
 
 ## _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