Files
notifications-admin/tests/app/main/views/test_headers.py
T

48 lines
1.8 KiB
Python
Raw Normal View History

2019-04-10 17:20:51 +01:00
def test_owasp_useful_headers_set(
client,
mocker,
mock_get_service_and_organisation_counts,
):
mocker.patch('app.get_logo_cdn_domain', return_value='static-logos.test.com')
2016-01-07 13:58:38 +00:00
2017-02-03 12:07:21 +00:00
response = client.get('/')
2017-07-24 15:20:40 +01:00
2016-01-07 13:58:38 +00:00
assert response.status_code == 200
assert response.headers['X-Frame-Options'] == 'deny'
assert response.headers['X-Content-Type-Options'] == 'nosniff'
assert response.headers['X-XSS-Protection'] == '1; mode=block'
2016-07-05 07:12:21 +01:00
assert response.headers['Content-Security-Policy'] == (
2018-11-29 11:29:52 +00:00
"default-src 'self' static.example.com 'unsafe-inline';"
"script-src 'self' static.example.com *.google-analytics.com 'unsafe-inline' 'unsafe-eval' data:;"
2017-11-06 10:25:30 +00:00
"connect-src 'self' *.google-analytics.com;"
2016-07-05 07:12:21 +01:00
"object-src 'self';"
2018-11-29 11:29:52 +00:00
"font-src 'self' static.example.com data:;"
"img-src "
"'self' static.example.com *.google-analytics.com *.notifications.service.gov.uk static-logos.test.com data:;"
2018-08-03 17:39:58 +01:00
"frame-src 'self' www.youtube.com;"
2016-07-05 07:12:21 +01:00
)
2018-05-25 10:18:39 +01:00
2019-04-10 17:20:51 +01:00
def test_headers_non_ascii_characters_are_replaced(
client,
mocker,
mock_get_service_and_organisation_counts,
):
mocker.patch('app.get_logo_cdn_domain', return_value='static-logos۾.test.com')
2018-05-25 10:18:39 +01:00
response = client.get('/')
assert response.status_code == 200
assert response.headers['Content-Security-Policy'] == (
2018-11-29 11:29:52 +00:00
"default-src 'self' static.example.com 'unsafe-inline';"
"script-src 'self' static.example.com *.google-analytics.com 'unsafe-inline' 'unsafe-eval' data:;"
2018-05-25 10:18:39 +01:00
"connect-src 'self' *.google-analytics.com;"
"object-src 'self';"
2018-11-29 11:29:52 +00:00
"font-src 'self' static.example.com data:;"
"img-src "
"'self' static.example.com *.google-analytics.com *.notifications.service.gov.uk static-logos??.test.com data:;"
2018-08-03 17:39:58 +01:00
"frame-src 'self' www.youtube.com;"
2018-05-25 10:18:39 +01:00
)