2019-04-10 17:20:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_owasp_useful_headers_set(
|
2022-01-04 15:40:42 +00:00
|
|
|
client_request,
|
2019-04-10 17:20:51 +01:00
|
|
|
mocker,
|
|
|
|
|
mock_get_service_and_organisation_counts,
|
|
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
client_request.logout()
|
|
|
|
|
response = client_request.get_response('.index')
|
2017-07-24 15:20:40 +01:00
|
|
|
|
2016-01-07 13:58:38 +00:00
|
|
|
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 "
|
2020-07-06 10:53:14 +01:00
|
|
|
"'self' static.example.com *.tile.openstreetmap.org *.google-analytics.com"
|
|
|
|
|
" *.notifications.service.gov.uk static-logos.test.com data:;"
|
2019-12-19 13:43:44 +00:00
|
|
|
"frame-src 'self' www.youtube-nocookie.com;"
|
2016-07-05 07:12:21 +01:00
|
|
|
)
|
2020-12-03 10:52:25 +00:00
|
|
|
assert response.headers['Link'] == (
|
|
|
|
|
'<https://static.example.com>; rel=dns-prefetch, '
|
|
|
|
|
'<https://static.example.com>; rel=preconnect'
|
|
|
|
|
)
|
2018-05-25 10:18:39 +01:00
|
|
|
|
|
|
|
|
|
2019-04-10 17:20:51 +01:00
|
|
|
def test_headers_non_ascii_characters_are_replaced(
|
2022-01-04 15:40:42 +00:00
|
|
|
client_request,
|
2019-04-10 17:20:51 +01:00
|
|
|
mocker,
|
|
|
|
|
mock_get_service_and_organisation_counts,
|
|
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
client_request.logout()
|
2022-01-26 14:44:33 +00:00
|
|
|
mocker.patch.dict(
|
|
|
|
|
'app.current_app.config',
|
|
|
|
|
values={'LOGO_CDN_DOMAIN': 'static-logos۾.test.com'},
|
|
|
|
|
)
|
2018-05-25 10:18:39 +01:00
|
|
|
|
2022-01-04 15:40:42 +00:00
|
|
|
response = client_request.get_response('.index')
|
2018-05-25 10:18:39 +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:;"
|
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:;"
|
2020-07-06 10:53:14 +01:00
|
|
|
"img-src"
|
|
|
|
|
" 'self' static.example.com *.tile.openstreetmap.org *.google-analytics.com"
|
|
|
|
|
" *.notifications.service.gov.uk static-logos??.test.com data:;"
|
2019-12-19 13:43:44 +00:00
|
|
|
"frame-src 'self' www.youtube-nocookie.com;"
|
2018-05-25 10:18:39 +01:00
|
|
|
)
|