mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 14:09:20 -04:00
Respect template’s redaction preference
If a template has the `redact_personalisation` flag set, then this commit removes the personalisation from the notification before rehydrating the template. We’re doing this because we have a need to not show things like one time passwords or two factor codes when we show the content of messages. By passing through empty personalisation, and the `redact_missing` flag, the `Template` instance will make use of the work done in: - [x] https://github.com/alphagov/notifications-utils/pull/171
This commit is contained in:
@@ -8,7 +8,7 @@ from bs4 import BeautifulSoup
|
||||
|
||||
from app.main.views.jobs import get_time_left, get_status_filters
|
||||
from tests import notification_json
|
||||
from tests.conftest import SERVICE_ONE_ID
|
||||
from tests.conftest import SERVICE_ONE_ID, mock_get_notifications
|
||||
from tests.app.test_utils import normalize_spaces
|
||||
from freezegun import freeze_time
|
||||
|
||||
@@ -321,3 +321,27 @@ def test_html_contains_notification_id(
|
||||
notifications = page.tbody.find_all('tr')
|
||||
for tr in notifications:
|
||||
assert uuid.UUID(tr.attrs['id'])
|
||||
|
||||
|
||||
def test_redacts_templates_that_should_be_redacted(
|
||||
client_request,
|
||||
mocker,
|
||||
active_user_with_permissions,
|
||||
mock_get_detailed_service,
|
||||
):
|
||||
_notifications_mock = mock_get_notifications(
|
||||
mocker,
|
||||
active_user_with_permissions,
|
||||
template_content="hello ((name))",
|
||||
personalisation={'name': 'Jo'},
|
||||
redact_personalisation=True,
|
||||
)
|
||||
page = client_request.get(
|
||||
'main.view_notifications',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
message_type='sms',
|
||||
)
|
||||
|
||||
assert normalize_spaces(page.select('tbody tr th')[0].text) == (
|
||||
'07123456789 hello hidden'
|
||||
)
|
||||
|
||||
@@ -57,3 +57,37 @@ def test_notification_status_page_shows_details(
|
||||
service_one['id'],
|
||||
fake_uuid
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('template_redaction_setting, expected_content', [
|
||||
(False, 'service one: hello Jo'),
|
||||
(True, 'service one: hello hidden'),
|
||||
])
|
||||
@freeze_time("2016-01-01 11:09:00.061258")
|
||||
def test_notification_status_page_respects_redaction(
|
||||
client_request,
|
||||
mocker,
|
||||
service_one,
|
||||
fake_uuid,
|
||||
template_redaction_setting,
|
||||
expected_content,
|
||||
):
|
||||
|
||||
_mock_get_notification = mock_get_notification(
|
||||
mocker,
|
||||
fake_uuid,
|
||||
redact_personalisation=template_redaction_setting,
|
||||
)
|
||||
|
||||
page = client_request.get(
|
||||
'main.view_notification',
|
||||
service_id=service_one['id'],
|
||||
notification_id=fake_uuid
|
||||
)
|
||||
|
||||
assert normalize_spaces(page.select('.sms-message-wrapper')[0].text) == expected_content
|
||||
|
||||
_mock_get_notification.assert_called_with(
|
||||
service_one['id'],
|
||||
fake_uuid,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user