Bugzilla – Attachment 164447 Details for
Bug 36349
Login for SCO/SCI broken by CSRF
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36349: Add tests
Bug-36349-Add-tests.patch (text/plain), 4.33 KB, created by
David Cook
on 2024-04-05 05:55:47 UTC
(
hide
)
Description:
Bug 36349: Add tests
Filename:
MIME Type:
Creator:
David Cook
Created:
2024-04-05 05:55:47 UTC
Size:
4.33 KB
patch
obsolete
>From ca79862c50f2a89cd220e2a458370ef008413fd6 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 4 Apr 2024 12:30:47 +0200 >Subject: [PATCH] Bug 36349: Add tests > >Signed-off-by: David Cook <dcook@prosentient.com.au> >--- > t/db_dependent/Auth.t | 94 ++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 93 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Auth.t b/t/db_dependent/Auth.t >index 99381c9365d..c66b2a469af 100755 >--- a/t/db_dependent/Auth.t >+++ b/t/db_dependent/Auth.t >@@ -7,7 +7,7 @@ use CGI qw ( -utf8 ); > use Test::MockObject; > use Test::MockModule; > use List::MoreUtils qw/all any none/; >-use Test::More tests => 20; >+use Test::More tests => 21; > use Test::Warn; > use t::lib::Mocks; > use t::lib::TestBuilder; >@@ -1350,6 +1350,98 @@ subtest 'AutoLocation' => sub { > > }; > >+subtest 'AutoSelfCheckAllowed' => sub { >+ plan tests => 5; >+ >+ my $query = CGI->new; >+ my $auth = Test::MockModule->new('C4::Auth'); >+ $auth->mock( 'safe_exit', sub { return } ); >+ >+ t::lib::Mocks::mock_preference( 'AutoSelfCheckAllowed', 0 ); >+ >+ # Pref is off, cannot access sco >+ { >+ # checkauth will redirect and safe_exit if not authenticated and not authorized >+ local *STDOUT; >+ my $stdout; >+ open STDOUT, '>', \$stdout; >+ my ( $template, $loggedinuser, $cookies ) = get_template_and_user( >+ { >+ template_name => "sco/sco-main.tt", >+ query => $query, >+ type => "opac", >+ flagsrequired => { self_check => "self_checkout_module" }, >+ } >+ ); >+ like( $stdout, qr{<title>\s*Log in to your account} ); >+ close STDOUT; >+ }; >+ >+ # Pref is on from here >+ t::lib::Mocks::mock_preference( 'AutoSelfCheckAllowed', 1 ); >+ >+ t::lib::Mocks::mock_preference( 'AutoSelfCheckID', '' ); >+ t::lib::Mocks::mock_preference( 'AutoSelfCheckPass', '' ); >+ >+ # Credential prefs are empty, cannot access sco >+ { >+ # checkauth will redirect and safe_exit if not authenticated and not authorized >+ local *STDOUT; >+ my $stdout; >+ open STDOUT, '>', \$stdout; >+ my ( $template, $loggedinuser, $cookies ) = get_template_and_user( >+ { >+ template_name => "sco/sco-main.tt", >+ query => $query, >+ type => "opac", >+ flagsrequired => { self_check => "self_checkout_module" }, >+ } >+ ); >+ like( $stdout, qr{<title>\s*Log in to your account} ); >+ close STDOUT; >+ }; >+ >+ my $sco_patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 0 } } ); >+ my $password = set_weak_password($sco_patron); >+ t::lib::Mocks::mock_preference( 'AutoSelfCheckID', $sco_patron->userid ); >+ t::lib::Mocks::mock_preference( 'AutoSelfCheckPass', $password ); >+ >+ # Credential pref are good but patron does not have the self_checkout_module subpermission >+ { >+ # checkauth will redirect and safe_exit if not authenticated and not authorized >+ local *STDOUT; >+ my $stdout; >+ open STDOUT, '>', \$stdout; >+ my ( $template, $loggedinuser, $cookies ) = get_template_and_user( >+ { >+ template_name => "sco/sco-main.tt", >+ query => $query, >+ type => "opac", >+ flagsrequired => { self_check => "self_checkout_module" }, >+ } >+ ); >+ like( $stdout, qr{<title>\s*Log in to your account} ); >+ close STDOUT; >+ }; >+ >+ # All good from now >+ C4::Context->dbh->do( >+ q| >+ INSERT INTO user_permissions (borrowernumber, module_bit, code) VALUES (?, ?, ?) >+ |, undef, $sco_patron->borrowernumber, 23, 'self_checkout_module' >+ ); >+ my ( $template, $loggedinuser, $cookies ) = get_template_and_user( >+ { >+ template_name => "sco/sco-main.tt", >+ query => $query, >+ type => "opac", >+ flagsrequired => { self_check => "self_checkout_module" }, >+ } >+ ); >+ is( $template->{VARS}->{logged_in_user}->id, $sco_patron->id ); >+ is( $loggedinuser, $sco_patron->id ); >+}; >+ > sub set_weak_password { > my ($patron) = @_; > my $password = 'password'; >-- >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 36349
:
163356
|
163386
|
163514
|
163552
|
163553
|
164411
|
164412
|
164444
|
164445
|
164446
| 164447