Bug 18442: Add a test
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 21 Apr 2017 21:44:05 +0000 (18:44 -0300)
committerJulian Maurice <julian.maurice@biblibre.com>
Mon, 22 May 2017 09:27:40 +0000 (11:27 +0200)
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
(cherry picked from commit 9bf8142ee77dbacceca0cb17ed5f56ec07b3771c)
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
(cherry picked from commit 6fa7c7d2bf7767427f9ccb421fe966097cbd34d7)
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>

C4/Auth.pm
t/db_dependent/Auth.t

index 06ba7fd..f427299 100644 (file)
@@ -1019,6 +1019,7 @@ sub checkauth {
 
             # $return: 1 = valid user, 2 = superlibrarian
             if ($return) {
+                # If DB user is logged in
                 $userid ||= $q_userid if $return == 2;
 
                 #_session_log(sprintf "%20s from %16s logged in  at %30s.\n", $userid,$ENV{'REMOTE_ADDR'},(strftime '%c', localtime));
index e0187b2..28f71db 100644 (file)
@@ -32,7 +32,7 @@ $schema->storage->txn_begin;
 
 subtest 'checkauth() tests' => sub {
 
-    plan tests => 1;
+    plan tests => 2;
 
     my $patron = $builder->build({ source => 'Borrower', value => { flags => undef } })->{userid};
 
@@ -46,6 +46,20 @@ subtest 'checkauth() tests' => sub {
 
     is( $userid, undef, 'checkauth() returns undef for userid if no logged in user (Bug 18275)' );
 
+    my $db_user_id = C4::Context->config('user');
+    my $db_user_pass = C4::Context->config('pass');
+    $cgi = Test::MockObject->new();
+    $cgi->mock( 'cookie', sub { return; } );
+    $cgi->mock( 'param', sub {
+            my ( $self, $param ) = @_;
+            if ( $param eq 'userid' ) { return $db_user_id; }
+            elsif ( $param eq 'password' ) { return $db_user_pass; }
+            else { return; }
+        });
+    ( $userid, $cookie, $sessionID, $flags ) = C4::Auth::checkauth( $cgi, $authnotrequired );
+    is ( $userid, $db_user_id, 'If DB user is logging in, it should be considered as logged in, i.e. checkauth return the relevant userid' );
+    C4::Context->_new_userenv; # For next tests
+
 };
 
 my $hash1 = hash_password('password');