| 
      
            Lines 41-47
          $schema->storage->txn_begin;
      
      
        Link Here
      
     | 
  
        
          | 41 | 
           | 
          41 | 
           | 
        
        
          | 42 | 
          subtest 'checkauth() tests' => sub { | 
          42 | 
          subtest 'checkauth() tests' => sub { | 
        
        
          | 43 | 
           | 
          43 | 
           | 
        
          
            
              | 44 | 
                  plan tests => 8;  | 
              44 | 
                  plan tests => 9;  | 
            
        
          | 45 | 
           | 
          45 | 
           | 
        
        
          | 46 | 
              my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => undef } }); | 
          46 | 
              my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => undef } }); | 
        
        
          | 47 | 
           | 
          47 | 
           | 
        
  
    | 
      
            Lines 152-157
          subtest 'checkauth() tests' => sub {
      
      
        Link Here
      
     | 
  
        
          | 152 | 
                  };  | 
          152 | 
                  };  | 
        
        
          | 153 | 
              };  | 
          153 | 
              };  | 
        
        
          | 154 | 
           | 
          154 | 
           | 
        
            
               | 
               | 
              155 | 
                  subtest 'Reset auth state when changing users' => sub { | 
            
            
              | 156 | 
                      #NOTE: It's easiest to detect this when changing to a non-existent user, since  | 
            
            
              | 157 | 
                      #that should trigger a redirect to login (instead of returning a session cookie)  | 
            
            
              | 158 | 
                      plan tests => 2;  | 
            
            
              | 159 | 
                      my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => undef } }); | 
            
            
              | 160 | 
               | 
            
            
              | 161 | 
                      my $session = C4::Auth::get_session();  | 
            
            
              | 162 | 
                      $session->param( 'number',       $patron->id );  | 
            
            
              | 163 | 
                      $session->param( 'id',           $patron->userid );  | 
            
            
              | 164 | 
                      $session->param( 'ip',           '1.2.3.4' );  | 
            
            
              | 165 | 
                      $session->param( 'lasttime',     time() );  | 
            
            
              | 166 | 
                      $session->param( 'interface',    'intranet' );  | 
            
            
              | 167 | 
                      $session->flush;  | 
            
            
              | 168 | 
                      my $sessionID = $session->id;  | 
            
            
              | 169 | 
                      C4::Context->_new_userenv($sessionID);  | 
            
            
              | 170 | 
               | 
            
            
              | 171 | 
                      my ( $return ) = C4::Auth::check_cookie_auth( $sessionID, undef, { skip_version_check => 1, remote_addr => '1.2.3.4' } ); | 
            
            
              | 172 | 
                      is( $return, 'ok', 'Patron authenticated' );  | 
            
            
              | 173 | 
               | 
            
            
              | 174 | 
                      my $mock1 = Test::MockModule->new('C4::Auth'); | 
            
            
              | 175 | 
                      $mock1->mock( 'safe_exit', sub {return 'safe_exit_redirect'} ); | 
            
            
              | 176 | 
                      my $mock2 = Test::MockModule->new('CGI'); | 
            
            
              | 177 | 
                      $mock2->mock( 'request_method', 'POST' );  | 
            
            
              | 178 | 
                      $mock2->mock( 'cookie', sub { return $sessionID; } ); # oversimplified.. | 
            
            
              | 179 | 
                      my $cgi = CGI->new;  | 
            
            
              | 180 | 
               | 
            
            
              | 181 | 
                      $cgi->param( -name => 'userid',             -value => 'Bond' );  | 
            
            
              | 182 | 
                      $cgi->param( -name => 'password',           -value => 'James Bond' );  | 
            
            
              | 183 | 
                      $cgi->param( -name => 'koha_login_context', -value => 1 );  | 
            
            
              | 184 | 
                      my ( @return, $stdout );  | 
            
            
              | 185 | 
                      { | 
            
            
              | 186 | 
                          local *STDOUT;  | 
            
            
              | 187 | 
                          local %ENV;  | 
            
            
              | 188 | 
                          $ENV{REMOTE_ADDR} = '1.2.3.4'; | 
            
            
              | 189 | 
                          open STDOUT, '>', \$stdout;  | 
            
            
              | 190 | 
                          @return = C4::Auth::checkauth( $cgi, 0, {} ); | 
            
            
              | 191 | 
                          close STDOUT;  | 
            
            
              | 192 | 
                      }  | 
            
            
              | 193 | 
                      is( $return[0], 'safe_exit_redirect', 'Changing to non-existent user causes a redirect to login');  | 
            
            
              | 194 | 
                  };  | 
            
            
              | 195 | 
               | 
            
            
              | 196 | 
               | 
            
        
          | 155 | 
              subtest 'While still logged in, relogin with another user' => sub { | 
          197 | 
              subtest 'While still logged in, relogin with another user' => sub { | 
        
        
          | 156 | 
                  plan tests => 6;  | 
          198 | 
                  plan tests => 6;  | 
        
        
          | 157 | 
           | 
          199 | 
           | 
        
            
              | 158 | 
              -   | 
               | 
               |