Bug 34513: Add checkauth unit test for resetting auth state when changing users
Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> (cherry picked from commitabbbc5924d
) Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com> (cherry picked from commit6c1b969a1f
) Signed-off-by: Jacob O'Mara <jacob.omara@ptfs-europe.com>
This commit is contained in:
parent
e8e75e58a0
commit
5cca53bdfa
1 changed files with 11 additions and 13 deletions
|
@ -41,7 +41,7 @@ $schema->storage->txn_begin;
|
||||||
|
|
||||||
subtest 'checkauth() tests' => sub {
|
subtest 'checkauth() tests' => sub {
|
||||||
|
|
||||||
plan tests => 8;
|
plan tests => 9;
|
||||||
|
|
||||||
my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => undef } });
|
my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => undef } });
|
||||||
|
|
||||||
|
@ -153,31 +153,29 @@ subtest 'checkauth() tests' => sub {
|
||||||
};
|
};
|
||||||
|
|
||||||
subtest 'Reset auth state when changing users' => sub {
|
subtest 'Reset auth state when changing users' => sub {
|
||||||
|
|
||||||
#NOTE: It's easiest to detect this when changing to a non-existent user, since
|
#NOTE: It's easiest to detect this when changing to a non-existent user, since
|
||||||
#that should trigger a redirect to login (instead of returning a session cookie)
|
#that should trigger a redirect to login (instead of returning a session cookie)
|
||||||
plan tests => 2;
|
plan tests => 2;
|
||||||
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => undef } } );
|
my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => undef } });
|
||||||
|
|
||||||
my $session = C4::Auth::get_session();
|
my $session = C4::Auth::get_session();
|
||||||
$session->param( 'number', $patron->id );
|
$session->param( 'number', $patron->id );
|
||||||
$session->param( 'id', $patron->userid );
|
$session->param( 'id', $patron->userid );
|
||||||
$session->param( 'ip', '1.2.3.4' );
|
$session->param( 'ip', '1.2.3.4' );
|
||||||
$session->param( 'lasttime', time() );
|
$session->param( 'lasttime', time() );
|
||||||
$session->param( 'interface', 'intranet' );
|
$session->param( 'interface', 'intranet' );
|
||||||
$session->flush;
|
$session->flush;
|
||||||
my $sessionID = $session->id;
|
my $sessionID = $session->id;
|
||||||
C4::Context->_new_userenv($sessionID);
|
C4::Context->_new_userenv($sessionID);
|
||||||
|
|
||||||
my ($return) =
|
my ( $return ) = C4::Auth::check_cookie_auth( $sessionID, undef, { skip_version_check => 1, remote_addr => '1.2.3.4' } );
|
||||||
C4::Auth::check_cookie_auth( $sessionID, undef, { skip_version_check => 1, remote_addr => '1.2.3.4' } );
|
|
||||||
is( $return, 'ok', 'Patron authenticated' );
|
is( $return, 'ok', 'Patron authenticated' );
|
||||||
|
|
||||||
my $mock1 = Test::MockModule->new('C4::Auth');
|
my $mock1 = Test::MockModule->new('C4::Auth');
|
||||||
$mock1->mock( 'safe_exit', sub { return 'safe_exit_redirect' } );
|
$mock1->mock( 'safe_exit', sub {return 'safe_exit_redirect'} );
|
||||||
my $mock2 = Test::MockModule->new('CGI');
|
my $mock2 = Test::MockModule->new('CGI');
|
||||||
$mock2->mock( 'request_method', 'POST' );
|
$mock2->mock( 'request_method', 'POST' );
|
||||||
$mock2->mock( 'cookie', sub { return $sessionID; } ); # oversimplified..
|
$mock2->mock( 'cookie', sub { return $sessionID; } ); # oversimplified..
|
||||||
my $cgi = CGI->new;
|
my $cgi = CGI->new;
|
||||||
|
|
||||||
$cgi->param( -name => 'userid', -value => 'Bond' );
|
$cgi->param( -name => 'userid', -value => 'Bond' );
|
||||||
|
@ -192,7 +190,7 @@ subtest 'checkauth() tests' => sub {
|
||||||
@return = C4::Auth::checkauth( $cgi, 0, {} );
|
@return = C4::Auth::checkauth( $cgi, 0, {} );
|
||||||
close STDOUT;
|
close STDOUT;
|
||||||
}
|
}
|
||||||
is( $return[0], 'safe_exit_redirect', 'Changing to non-existent user causes a redirect to login' );
|
is( $return[0], 'safe_exit_redirect', 'Changing to non-existent user causes a redirect to login');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue