Bugzilla – Attachment 152630 Details for
Bug 30524
Add base framework for dealing with CSRF in Koha
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30524: Unit tests
Bug-30524-Unit-tests.patch (text/plain), 2.02 KB, created by
Martin Renvoize (ashimema)
on 2023-06-23 10:54:54 UTC
(
hide
)
Description:
Bug 30524: Unit tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2023-06-23 10:54:54 UTC
Size:
2.02 KB
patch
obsolete
>From 0cadab3d8dd26b9b52982542535d383fdae4f124 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Fri, 23 Jun 2023 11:52:28 +0100 >Subject: [PATCH] Bug 30524: Unit tests > >--- > t/Output.t | 34 ++++++++++++++++++++++++++++++++-- > 1 file changed, 32 insertions(+), 2 deletions(-) > >diff --git a/t/Output.t b/t/Output.t >index 02218deadd..c9b202f3dc 100755 >--- a/t/Output.t >+++ b/t/Output.t >@@ -17,14 +17,19 @@ > > use Modern::Perl; > >-use Test::More tests => 7; >+use Test::More tests => 8; > use Test::Warn; >+use Test::Trap; >+ >+use File::Temp qw/tempfile/; > use CGI qw ( -utf8 ); > >+use C4::Auth qw( get_template_and_user ); >+ > use t::lib::Mocks; > > BEGIN { >- use_ok('C4::Output', qw( output_html_with_http_headers parametrized_url )); >+ use_ok('C4::Output', qw( output_html_with_http_headers output_and_exit_if_error parametrized_url )); > } > > my $query = CGI->new(); >@@ -93,3 +98,28 @@ subtest 'output_with_http_headers() tests' => sub { > like($stdout, qr/Access-control-allow-origin: https:\/\/koha-community\.org/, 'Header set to https://koha-community.org'); > close STDOUT; > }; >+ >+subtest 'output_and_exit_if_error() tests' => sub { >+ >+ plan tests => 2; >+ >+ t::lib::Mocks::mock_config( 'pluginsdir', [ C4::Context::temporary_directory ] ); >+ my ( $fh, $fn ) = tempfile( SUFFIX => '.tt', UNLINK => 1, DIR => C4::Context::temporary_directory ); >+ print $fh qq|[% blocking_error %]|; >+ close $fh; >+ >+ my $query = CGI->new(); >+ $query->param('csrf_token',''); >+ my ( $template, $loggedinuser, $cookies ) = get_template_and_user( >+ { >+ template_name => $fn, >+ query => $query, >+ type => "intranet", >+ authnotrequired => 1, >+ } >+ ); >+ >+ my @r = trap { output_and_exit_if_error($query, $cookie, $template, { check => 'csrf_token' }) }; >+ is ( $trap->exit, 0, 'Expecting &output_and_exit_if_error to exit with 0' ); >+ like ( $trap->stdout, qr/wrong_csrf_token/, 'Expecting wrong_csrf_token' ); >+}; >-- >2.41.0
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 30524
:
133249
|
133250
|
133420
|
138055
|
141297
|
152629
|
152630
|
152631
|
152632
|
152634
|
152635
|
152637
|
152638
|
153964
|
153965
|
153975
|
153976
|
154000
|
154038