Lines 17-30
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 7; |
20 |
use Test::More tests => 8; |
21 |
use Test::Warn; |
21 |
use Test::Warn; |
|
|
22 |
use Test::Trap; |
23 |
|
24 |
use File::Temp qw/tempfile/; |
22 |
use CGI qw ( -utf8 ); |
25 |
use CGI qw ( -utf8 ); |
23 |
|
26 |
|
|
|
27 |
use C4::Auth qw( get_template_and_user ); |
28 |
|
24 |
use t::lib::Mocks; |
29 |
use t::lib::Mocks; |
25 |
|
30 |
|
26 |
BEGIN { |
31 |
BEGIN { |
27 |
use_ok('C4::Output', qw( output_html_with_http_headers parametrized_url )); |
32 |
use_ok('C4::Output', qw( output_html_with_http_headers output_and_exit_if_error parametrized_url )); |
28 |
} |
33 |
} |
29 |
|
34 |
|
30 |
my $query = CGI->new(); |
35 |
my $query = CGI->new(); |
Lines 93-95
subtest 'output_with_http_headers() tests' => sub {
Link Here
|
93 |
like($stdout, qr/Access-control-allow-origin: https:\/\/koha-community\.org/, 'Header set to https://koha-community.org'); |
98 |
like($stdout, qr/Access-control-allow-origin: https:\/\/koha-community\.org/, 'Header set to https://koha-community.org'); |
94 |
close STDOUT; |
99 |
close STDOUT; |
95 |
}; |
100 |
}; |
96 |
- |
101 |
|
|
|
102 |
subtest 'output_and_exit_if_error() tests' => sub { |
103 |
|
104 |
plan tests => 2; |
105 |
|
106 |
t::lib::Mocks::mock_config( 'pluginsdir', [ C4::Context::temporary_directory ] ); |
107 |
my ( $fh, $fn ) = tempfile( SUFFIX => '.tt', UNLINK => 1, DIR => C4::Context::temporary_directory ); |
108 |
print $fh qq|[% blocking_error %]|; |
109 |
close $fh; |
110 |
|
111 |
my $query = CGI->new(); |
112 |
$query->param('csrf_token',''); |
113 |
my ( $template, $loggedinuser, $cookies ) = get_template_and_user( |
114 |
{ |
115 |
template_name => $fn, |
116 |
query => $query, |
117 |
type => "intranet", |
118 |
authnotrequired => 1, |
119 |
} |
120 |
); |
121 |
|
122 |
my @r = trap { output_and_exit_if_error($query, $cookie, $template, { check => 'csrf_token' }) }; |
123 |
is ( $trap->exit, 0, 'Expecting &output_and_exit_if_error to exit with 0' ); |
124 |
like ( $trap->stdout, qr/wrong_csrf_token/, 'Expecting wrong_csrf_token' ); |
125 |
}; |