View | Details | Raw Unified | Return to bug 31908
Collapse All | Expand All

(-)a/t/db_dependent/Auth.t (-2 / +44 lines)
Lines 38-44 $schema->storage->txn_begin; Link Here
38
38
39
subtest 'checkauth() tests' => sub {
39
subtest 'checkauth() tests' => sub {
40
40
41
    plan tests => 4;
41
    plan tests => 5;
42
42
43
    my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => undef } });
43
    my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => undef } });
44
44
Lines 108-113 subtest 'checkauth() tests' => sub { Link Here
108
        is( $userid, undef, 'If librarian user is used and password with GET, they should not be logged in' );
108
        is( $userid, undef, 'If librarian user is used and password with GET, they should not be logged in' );
109
    };
109
    };
110
110
111
    subtest 'While still logged in, relogin with another user' => sub {
112
        plan tests => 4;
113
        my $patron = $builder->build_object({ class => 'Koha::Patrons', value => {} });
114
        my $patron2 = $builder->build_object({ class => 'Koha::Patrons', value => {} });
115
        # Create 'former' session
116
        my $session = C4::Auth::get_session();
117
        $session->param( 'number',       $patron->id );
118
        $session->param( 'id',           $patron->userid );
119
        $session->param( 'ip',           '1.2.3.4' );
120
        $session->param( 'lasttime',     time() );
121
        $session->param( 'interface',    'opac' );
122
        $session->flush;
123
        my $sessionID = $session->id;
124
        C4::Context->_new_userenv($sessionID);
125
126
        my ( $return ) = C4::Auth::check_cookie_auth( $sessionID, undef, { skip_version_check => 1, remote_addr => '1.2.3.4' } );
127
        is( $return, 'ok', 'Former session in shape now' );
128
129
        my $mock1 = Test::MockModule->new('C4::Auth')->mock( 'safe_exit', sub {} );
130
        my $mock2 = Test::MockModule->new('CGI')     ->mock( 'request_method', 'POST' )
131
                                                     ->mock( 'cookie', sub { return $sessionID; } ); # oversimplified..
132
        my $cgi = CGI->new;
133
        my $password = 'Incr3d1blyZtr@ng93$';
134
        $patron2->set_password({ password => $password });
135
        $cgi->param( -name => 'userid',             -value => $patron2->userid );
136
        $cgi->param( -name => 'password',           -value => $password );
137
        $cgi->param( -name => 'koha_login_context', -value => 1 );
138
        my @return;
139
        {
140
            local *STDOUT;
141
            local %ENV;
142
            $ENV{REMOTE_ADDR} = '1.2.3.4';
143
            my $stdout;
144
            open STDOUT, '>', \$stdout;
145
            @return = C4::Auth::checkauth( $cgi, 0, {} );
146
            close STDOUT;
147
        }
148
        # Note: We can test return values from checkauth here since we mocked the safe_exit after the Redirect 303
149
        is( $return[0], $patron2->userid, 'Login of patron2 approved' );
150
        isnt( $return[2], $sessionID, 'Did not return previous session ID' );
151
        ok( $return[2], 'New session ID not empty' );
152
    };
153
111
    C4::Context->_new_userenv; # For next tests
154
    C4::Context->_new_userenv; # For next tests
112
155
113
};
156
};
114
- 

Return to bug 31908