Bugzilla – Attachment 154745 Details for
Bug 34513
Authenticated users can bypass permissions and view some privileged pages
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34513: Add checkauth unit test for resetting auth state when changing users
Bug-34513-Add-checkauth-unit-test-for-resetting-au.patch (text/plain), 2.91 KB, created by
Nick Clemens (kidclamp)
on 2023-08-24 18:21:21 UTC
(
hide
)
Description:
Bug 34513: Add checkauth unit test for resetting auth state when changing users
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2023-08-24 18:21:21 UTC
Size:
2.91 KB
patch
obsolete
>From 2e206f38be54ba265a08bccc1ca2cd2f5117a37c Mon Sep 17 00:00:00 2001 >From: David Cook <dcook@prosentient.com.au> >Date: Wed, 16 Aug 2023 02:51:43 +0000 >Subject: [PATCH] Bug 34513: Add checkauth unit test for resetting auth state > when changing users > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > t/db_dependent/Auth.t | 44 ++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 43 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Auth.t b/t/db_dependent/Auth.t >index 5de81401e1..3f25e3f917 100755 >--- a/t/db_dependent/Auth.t >+++ b/t/db_dependent/Auth.t >@@ -41,7 +41,7 @@ $schema->storage->txn_begin; > > subtest 'checkauth() tests' => sub { > >- plan tests => 8; >+ plan tests => 9; > > my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => undef } }); > >@@ -152,6 +152,48 @@ subtest 'checkauth() tests' => sub { > }; > }; > >+ subtest 'Reset auth state when changing users' => sub { >+ #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) >+ plan tests => 2; >+ my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => undef } }); >+ >+ my $session = C4::Auth::get_session(); >+ $session->param( 'number', $patron->id ); >+ $session->param( 'id', $patron->userid ); >+ $session->param( 'ip', '1.2.3.4' ); >+ $session->param( 'lasttime', time() ); >+ $session->param( 'interface', 'intranet' ); >+ $session->flush; >+ my $sessionID = $session->id; >+ C4::Context->_new_userenv($sessionID); >+ >+ my ( $return ) = C4::Auth::check_cookie_auth( $sessionID, undef, { skip_version_check => 1, remote_addr => '1.2.3.4' } ); >+ is( $return, 'ok', 'Patron authenticated' ); >+ >+ my $mock1 = Test::MockModule->new('C4::Auth'); >+ $mock1->mock( 'safe_exit', sub {return 'safe_exit_redirect'} ); >+ my $mock2 = Test::MockModule->new('CGI'); >+ $mock2->mock( 'request_method', 'POST' ); >+ $mock2->mock( 'cookie', sub { return $sessionID; } ); # oversimplified.. >+ my $cgi = CGI->new; >+ >+ $cgi->param( -name => 'userid', -value => 'Bond' ); >+ $cgi->param( -name => 'password', -value => 'James Bond' ); >+ $cgi->param( -name => 'koha_login_context', -value => 1 ); >+ my ( @return, $stdout ); >+ { >+ local *STDOUT; >+ local %ENV; >+ $ENV{REMOTE_ADDR} = '1.2.3.4'; >+ open STDOUT, '>', \$stdout; >+ @return = C4::Auth::checkauth( $cgi, 0, {} ); >+ close STDOUT; >+ } >+ is( $return[0], 'safe_exit_redirect', 'Changing to non-existent user causes a redirect to login'); >+ }; >+ >+ > subtest 'While still logged in, relogin with another user' => sub { > plan tests => 6; > >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 34513
:
154357
|
154439
|
154440
|
154743
|
154744
|
154745
|
154746
|
154781
|
154782
|
154783
|
154784