Bug 33879: Add unit test to show problem

Test plan:
Run t/db_dependent/Auth.t without second patch.
Should fail:
    #          got: 'opac'
    #     expected: 'intranet'

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Björn Nylén <bjorn.nylen@ub.lu.se>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit a7fda38647)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 5377331f46)
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
This commit is contained in:
Marcel de Rooy 2023-06-01 13:42:03 +00:00 committed by Matt Blenkinsop
parent a9b50d6b57
commit 335f3ed00a
1 changed files with 25 additions and 4 deletions

View File

@ -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;
@ -942,4 +939,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', 'check_cookie_auth did not overwrite' );
delete $C4::Context::context->{interface}; # clear context interface
C4::Auth::check_cookie_auth( $session->id );
is( C4::Context->interface, 'opac', 'check_cookie_auth used interface from session when context interface was empty' );
t::lib::Mocks::mock_preference( 'SessionRestrictionByIP', 1 );
};
$schema->storage->txn_rollback;