Files
notifications-admin/tests/app/test_zap_security_fixes.py

53 lines
2.1 KiB
Python
Raw Normal View History

2025-07-31 13:38:50 -04:00
def test_csp_no_unsafe_eval(
client_request, mocker, mock_get_service_and_organization_counts
):
2025-07-31 11:39:58 -04:00
"""Check that unsafe-eval was removed from CSP"""
mocker.patch("app.notify_client.user_api_client.UserApiClient.deactivate_user")
client_request.logout()
2025-07-31 13:38:50 -04:00
response = client_request.get_response(".index")
csp = response.headers.get("Content-Security-Policy", "")
2025-07-31 11:39:58 -04:00
assert "'unsafe-eval'" not in csp
2025-07-31 13:38:50 -04:00
def test_no_duplicate_form_action(
client_request, mocker, mock_get_service_and_organization_counts
):
2025-07-31 11:39:58 -04:00
"""Check that form-action only appears once in CSP"""
mocker.patch("app.notify_client.user_api_client.UserApiClient.deactivate_user")
client_request.logout()
2025-07-31 13:38:50 -04:00
response = client_request.get_response(".index")
csp = response.headers.get("Content-Security-Policy", "")
2025-07-31 11:39:58 -04:00
# Count how many times form-action appears
2025-07-31 13:38:50 -04:00
count = csp.count("form-action")
2025-07-31 11:39:58 -04:00
assert count == 1
2025-07-31 13:38:50 -04:00
def test_cross_origin_embedder_policy_set_to_credentialless(
client_request, mocker, mock_get_service_and_organization_counts
):
2025-07-31 12:47:40 -04:00
"""Check that Cross-Origin-Embedder-Policy is set to 'credentialless' for YouTube compatibility"""
2025-07-31 11:39:58 -04:00
mocker.patch("app.notify_client.user_api_client.UserApiClient.deactivate_user")
client_request.logout()
2025-07-31 13:38:50 -04:00
response = client_request.get_response(".index")
2025-07-31 11:39:58 -04:00
2025-07-31 13:38:50 -04:00
assert response.headers.get("Cross-Origin-Embedder-Policy") == "credentialless"
2025-07-31 12:47:40 -04:00
2025-07-31 13:38:50 -04:00
def test_permissions_policy_allows_youtube_features(
client_request, mocker, mock_get_service_and_organization_counts
):
2025-07-31 12:47:40 -04:00
"""Check that Permissions-Policy allows necessary features for YouTube embeds"""
mocker.patch("app.notify_client.user_api_client.UserApiClient.deactivate_user")
client_request.logout()
2025-07-31 13:38:50 -04:00
response = client_request.get_response(".index")
2025-07-31 12:47:40 -04:00
2025-07-31 13:38:50 -04:00
permissions_policy = response.headers.get("Permissions-Policy", "")
2025-07-31 12:47:40 -04:00
2025-07-31 13:38:50 -04:00
assert (
'accelerometer=(self "https://www.youtube-nocookie.com")' in permissions_policy
)
2025-07-31 12:47:40 -04:00
assert 'autoplay=(self "https://www.youtube-nocookie.com")' in permissions_policy
assert 'gyroscope=(self "https://www.youtube-nocookie.com")' in permissions_policy