From e47dbc0caaa5086bcacd3f71b9fbe7903b7b58cf Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 10 Aug 2020 12:26:33 +0100 Subject: [PATCH] Add tests to check permission-restricted broadcast pages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some pages should only be shown to users who have permission to send or approve broadcasts. This commit adds a test to ensure that this is true, and that we don’t accidentally regress the checks for this permission. --- tests/app/main/views/test_broadcast.py | 59 ++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tests/app/main/views/test_broadcast.py b/tests/app/main/views/test_broadcast.py index 8c828c240..6c726f0cc 100644 --- a/tests/app/main/views/test_broadcast.py +++ b/tests/app/main/views/test_broadcast.py @@ -75,6 +75,63 @@ def test_broadcast_pages_403_without_permission( ) +@pytest.mark.parametrize('endpoint, extra_args, expected_get_status, expected_post_status', ( + ( + '.broadcast', + {'template_id': sample_uuid}, + 403, 405, + ), + ( + '.preview_broadcast_areas', {'broadcast_message_id': sample_uuid}, + 403, 405, + ), + ( + '.choose_broadcast_library', {'broadcast_message_id': sample_uuid}, + 403, 405, + ), + ( + '.choose_broadcast_area', {'broadcast_message_id': sample_uuid, 'library_slug': 'countries'}, + 403, 403, + ), + ( + '.remove_broadcast_area', {'broadcast_message_id': sample_uuid, 'area_slug': 'england'}, + 403, 405, + ), + ( + '.preview_broadcast_message', {'broadcast_message_id': sample_uuid}, + 403, 403, + ), + ( + '.cancel_broadcast_message', {'broadcast_message_id': sample_uuid}, + 403, 403, + ), +)) +def test_broadcast_pages_403_for_user_without_permission( + mocker, + client_request, + service_one, + active_user_view_permissions, + endpoint, + extra_args, + expected_get_status, + expected_post_status, +): + service_one['permissions'] += ['broadcast'] + mocker.patch('app.user_api_client.get_user', return_value=active_user_view_permissions) + client_request.get( + endpoint, + service_id=SERVICE_ONE_ID, + _expected_status=expected_get_status, + **extra_args + ) + client_request.post( + endpoint, + service_id=SERVICE_ONE_ID, + _expected_status=expected_post_status, + **extra_args + ) + + def test_dashboard_redirects_to_broadcast_dashboard( client_request, service_one, @@ -94,6 +151,7 @@ def test_dashboard_redirects_to_broadcast_dashboard( def test_empty_broadcast_dashboard( client_request, service_one, + active_user_view_permissions, mock_get_no_broadcast_messages, mock_get_service_templates_when_no_templates_exist, ): @@ -157,6 +215,7 @@ def test_broadcast_dashboard( def test_broadcast_dashboard_json( logged_in_client, service_one, + active_user_view_permissions, mock_get_broadcast_messages, ): service_one['permissions'] += ['broadcast']