|
Lines 24-34
use Test::NoWarnings;
Link Here
|
| 24 |
use Test::More tests => 3; |
24 |
use Test::More tests => 3; |
| 25 |
use Test::Warn; |
25 |
use Test::Warn; |
| 26 |
|
26 |
|
|
|
27 |
use File::Basename qw(dirname); |
| 27 |
use HTTP::Request::Common; |
28 |
use HTTP::Request::Common; |
| 28 |
use Plack::Builder; |
29 |
use Plack::Builder; |
| 29 |
use Plack::Util; |
30 |
use Plack::Util; |
| 30 |
use Plack::Test; |
31 |
use Plack::Test; |
| 31 |
|
32 |
|
|
|
33 |
use C4::Templates; |
| 34 |
|
| 32 |
use t::lib::Mocks; |
35 |
use t::lib::Mocks; |
| 33 |
|
36 |
|
| 34 |
use_ok("Koha::Middleware::ContentSecurityPolicy"); |
37 |
use_ok("Koha::Middleware::ContentSecurityPolicy"); |
|
Lines 50-58
subtest 'test Content-Security-Policy header' => sub {
Link Here
|
| 50 |
# Set nonce |
53 |
# Set nonce |
| 51 |
Koha::ContentSecurityPolicy->new->nonce($test_nonce); |
54 |
Koha::ContentSecurityPolicy->new->nonce($test_nonce); |
| 52 |
|
55 |
|
|
|
56 |
t::lib::Mocks::mock_config( 'opachtdocs', C4::Context->config('intranetdir') . '/t/mock_templates/opac-tmpl' ); |
| 57 |
|
| 53 |
my $env = {}; |
58 |
my $env = {}; |
| 54 |
my $app = sub { |
59 |
my $app = sub { |
| 55 |
my $resp = [ |
60 |
require Koha::Plugins; # this should probably be "use Koha::Plugins;" in C4::Templates instead |
|
|
61 |
my $template = C4::Templates::gettemplate( 'opac-csp.tt', 'opac' ); |
| 62 |
my $resp = [ |
| 56 |
200, |
63 |
200, |
| 57 |
[ |
64 |
[ |
| 58 |
'Content-Type', |
65 |
'Content-Type', |
|
Lines 60-66
subtest 'test Content-Security-Policy header' => sub {
Link Here
|
| 60 |
'Content-Length', |
67 |
'Content-Length', |
| 61 |
12 |
68 |
12 |
| 62 |
], |
69 |
], |
| 63 |
[ Koha::ContentSecurityPolicy->new->nonce ] |
70 |
[ $template->output ] |
| 64 |
]; |
71 |
]; |
| 65 |
return $resp; |
72 |
return $resp; |
| 66 |
}; |
73 |
}; |
|
Lines 79-85
subtest 'test Content-Security-Policy header' => sub {
Link Here
|
| 79 |
"Response contains Content-Security-Policy header with the expected value" |
86 |
"Response contains Content-Security-Policy header with the expected value" |
| 80 |
); |
87 |
); |
| 81 |
is( |
88 |
is( |
| 82 |
$res->content, $test_nonce, |
89 |
$res->content, '<script nonce="' . $test_nonce . '">' . "\n" . '</script>' . "\n", |
| 83 |
"Response contains generated nonce in the body" |
90 |
"Response contains generated nonce in the body" |
| 84 |
); |
91 |
); |
| 85 |
|
92 |
|