Lines 17-32
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::MockModule; |
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 |
|
|
|
35 |
our $output_module = Test::MockModule->new('C4::Output'); |
36 |
|
30 |
my $query = CGI->new(); |
37 |
my $query = CGI->new(); |
31 |
my $cookie; |
38 |
my $cookie; |
32 |
my $output = 'foobarbaz'; |
39 |
my $output = 'foobarbaz'; |
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'); |
100 |
like($stdout, qr/Access-control-allow-origin: https:\/\/koha-community\.org/, 'Header set to https://koha-community.org'); |
94 |
close STDOUT; |
101 |
close STDOUT; |
95 |
}; |
102 |
}; |
|
|
103 |
|
104 |
subtest 'output_and_exit_if_error() tests' => sub { |
105 |
plan tests => 1; |
106 |
|
107 |
$output_module->mock( |
108 |
'output_and_exit', |
109 |
sub { |
110 |
my ( $query, $cookie, $template, $error ) = @_; |
111 |
is( $error, 'wrong_csrf_token', 'Got right error message' ); |
112 |
} |
113 |
); |
114 |
|
115 |
t::lib::Mocks::mock_config( 'pluginsdir', [ C4::Context::temporary_directory ] ); |
116 |
my ( $fh, $fn ) = tempfile( SUFFIX => '.tt', UNLINK => 1, DIR => C4::Context::temporary_directory ); |
117 |
print $fh qq|[% blocking_error %]|; |
118 |
close $fh; |
119 |
|
120 |
my $query = CGI->new(); |
121 |
$query->param('csrf_token',''); |
122 |
my ( $template, $loggedinuser, $cookies ) = get_template_and_user( |
123 |
{ |
124 |
template_name => $fn, |
125 |
query => $query, |
126 |
type => "intranet", |
127 |
authnotrequired => 1, |
128 |
} |
129 |
); |
130 |
# Next call triggers test in the mocked sub |
131 |
output_and_exit_if_error($query, $cookie, $template, { check => 'csrf_token' }); |
132 |
}; |