aboutsummaryrefslogtreecommitdiffstats
path: root/t/app
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2019-11-25 13:59:08 +0000
committerMatthew Somerville <matthew@mysociety.org>2019-11-25 13:59:08 +0000
commite64110f3ee50f6d8f4b3e04df7ed6cd6443c114f (patch)
tree473064952ce207e8c3852d6d1e953888d0498dc7 /t/app
parent3936729479271dc84edf01e0ff840125a61eeb84 (diff)
parenta1b76bb7873c002a987132280395093d03992b13 (diff)
Merge branch 'csp-uk'
Diffstat (limited to 't/app')
-rw-r--r--t/app/01app.t31
1 files changed, 29 insertions, 2 deletions
diff --git a/t/app/01app.t b/t/app/01app.t
index 7b933973b..50617d491 100644
--- a/t/app/01app.t
+++ b/t/app/01app.t
@@ -17,7 +17,6 @@ use charnames ':full';
ok( request('/')->is_success, 'Request should succeed' );
-SKIP: {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'tester' ],
}, sub {
@@ -25,6 +24,34 @@ FixMyStreet::override_config {
my $num = "12( | )345";
like $page, qr/$num/;
};
-}
+
+subtest 'CSP header' => sub {
+ my $res = request('/');
+ is $res->header('Content-Security-Policy'), undef, 'None by default';
+
+ FixMyStreet::override_config {
+ CONTENT_SECURITY_POLICY => 1,
+ }, sub {
+ my $res = request('/');
+ like $res->header('Content-Security-Policy'), qr/script-src 'self' 'unsafe-inline' 'nonce-[^']*' ; object-src 'none'; base-uri 'none'/,
+ 'Default CSP header if requested';
+ };
+
+ FixMyStreet::override_config {
+ CONTENT_SECURITY_POLICY => 'www.example.org',
+ }, sub {
+ my $res = request('/');
+ like $res->header('Content-Security-Policy'), qr/script-src 'self' 'unsafe-inline' 'nonce-[^']*' www.example.org; object-src 'none'; base-uri 'none'/,
+ 'With 3P domains if given';
+ };
+
+ FixMyStreet::override_config {
+ CONTENT_SECURITY_POLICY => [ 'www.example.org' ],
+ }, sub {
+ my $res = request('/');
+ like $res->header('Content-Security-Policy'), qr/script-src 'self' 'unsafe-inline' 'nonce-[^']*' www.example.org; object-src 'none'; base-uri 'none'/,
+ 'With 3P domains if given';
+ };
+};
done_testing();