From 7ca4aeef4b5cfe3b1fda5ad7030429ca604df3a4 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 1 Jun 2023 13:42:03 +0000 Subject: [PATCH] Bug 33879: Add unit test to show problem Content-Type: text/plain; charset=utf-8 Test plan: Run t/db_dependent/Auth.t without second patch. Should fail: # got: 'opac' # expected: 'intranet' Signed-off-by: Marcel de Rooy --- t/db_dependent/Auth.t | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/t/db_dependent/Auth.t b/t/db_dependent/Auth.t index 5c2aad72d4..6051f89918 100755 --- a/t/db_dependent/Auth.t +++ b/t/db_dependent/Auth.t @@ -1,7 +1,4 @@ #!/usr/bin/perl -# -# This Koha test module is a stub! -# Add more tests here!!! use Modern::Perl; @@ -10,7 +7,7 @@ use CGI qw ( -utf8 ); use Test::MockObject; use Test::MockModule; use List::MoreUtils qw/all any none/; -use Test::More tests => 17; +use Test::More tests => 18; use Test::Warn; use t::lib::Mocks; use t::lib::TestBuilder; @@ -981,4 +978,28 @@ subtest 'create_basic_session tests' => sub { is( $session->param('interface'), 'intranet', 'Staff interface gets converted to intranet' ); }; +subtest 'check_cookie_auth overwriting interface already set' => sub { + plan tests => 2; + + t::lib::Mocks::mock_preference( 'SessionRestrictionByIP', 0 ); + + my $patron = $builder->build_object({ class => 'Koha::Patrons' }); + 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', 'opac' ); + $session->flush; + + C4::Context->interface('intranet'); + C4::Auth::check_cookie_auth( $session->id ); + is( C4::Context->interface, 'intranet', 'cookie_auth did not overwrite' ); + delete $C4::Context::context->{interface}; + C4::Auth::check_cookie_auth( $session->id ); + is( C4::Context->interface, 'opac', 'cookie_auth did use interface from cookie' ); + + t::lib::Mocks::mock_preference( 'SessionRestrictionByIP', 1 ); +}; + $schema->storage->txn_rollback; -- 2.30.2