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

(-)a/t/db_dependent/Auth.t (-2 / +44 lines)
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 => 6;
44
    plan tests => 7;
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 'While still logged in, relogin with another user' => sub {
156
        plan tests => 4;
157
        my $patron = $builder->build_object({ class => 'Koha::Patrons', value => {} });
158
        my $patron2 = $builder->build_object({ class => 'Koha::Patrons', value => {} });
159
        # Create 'former' session
160
        my $session = C4::Auth::get_session();
161
        $session->param( 'number',       $patron->id );
162
        $session->param( 'id',           $patron->userid );
163
        $session->param( 'ip',           '1.2.3.4' );
164
        $session->param( 'lasttime',     time() );
165
        $session->param( 'interface',    'opac' );
166
        $session->flush;
167
        my $sessionID = $session->id;
168
        C4::Context->_new_userenv($sessionID);
169
170
        my ( $return ) = C4::Auth::check_cookie_auth( $sessionID, undef, { skip_version_check => 1, remote_addr => '1.2.3.4' } );
171
        is( $return, 'ok', 'Former session in shape now' );
172
173
        my $mock1 = Test::MockModule->new('C4::Auth')->mock( 'safe_exit', sub {} );
174
        my $mock2 = Test::MockModule->new('CGI')     ->mock( 'request_method', 'POST' )
175
                                                     ->mock( 'cookie', sub { return $sessionID; } ); # oversimplified..
176
        my $cgi = CGI->new;
177
        my $password = 'Incr3d1blyZtr@ng93$';
178
        $patron2->set_password({ password => $password });
179
        $cgi->param( -name => 'userid',             -value => $patron2->userid );
180
        $cgi->param( -name => 'password',           -value => $password );
181
        $cgi->param( -name => 'koha_login_context', -value => 1 );
182
        my @return;
183
        {
184
            local *STDOUT;
185
            local %ENV;
186
            $ENV{REMOTE_ADDR} = '1.2.3.4';
187
            my $stdout;
188
            open STDOUT, '>', \$stdout;
189
            @return = C4::Auth::checkauth( $cgi, 0, {} );
190
            close STDOUT;
191
        }
192
        # Note: We can test return values from checkauth here since we mocked the safe_exit after the Redirect 303
193
        is( $return[0], $patron2->userid, 'Login of patron2 approved' );
194
        isnt( $return[2], $sessionID, 'Did not return previous session ID' );
195
        ok( $return[2], 'New session ID not empty' );
196
    };
197
155
    subtest 'Two-factor authentication' => sub {
198
    subtest 'Two-factor authentication' => sub {
156
        plan tests => 18;
199
        plan tests => 18;
157
200
158
- 

Return to bug 31908