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

54 lines
2.1 KiB
Python
Raw Normal View History

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()
mocker.patch('app.get_logo_cdn_domain', return_value='static-logos.test.com')
2016-01-07 13:58:38 +00:00
2022-01-04 15:40:42 +00:00
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:;"
"frame-src 'self' www.youtube-nocookie.com;"
2016-07-05 07:12:21 +01: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()
mocker.patch('app.get_logo_cdn_domain', return_value='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:;"
"frame-src 'self' www.youtube-nocookie.com;"
2018-05-25 10:18:39 +01:00
)