Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1358 Redact personalization when in final state #2272

Merged
merged 16 commits into from
Jan 29, 2025
Merged
2 changes: 2 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
fileignoreconfig:
- filename: app/celery/process_ses_receipts_tasks.py
checksum: 3e7ce740725d4c904663c34102a5bb3587ffec3991ffb1a6919b1b9cf8327267
- filename: app/dao/api_key_dao.py
checksum: c44cbd8ae02fb1d551a1f0941365c11977564a6444950ee2b0282ee4b5fd1314
- filename: app/schema_validation/__init__.py
Expand Down
5 changes: 3 additions & 2 deletions app/celery/process_ses_receipts_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
HTTP_TIMEOUT,
KEY_TYPE_NORMAL,
NOTIFICATION_DELIVERED,
NOTIFICATION_SENDING,
NOTIFICATION_PENDING,
NOTIFICATION_PERMANENT_FAILURE,
NOTIFICATION_SENDING,
NOTIFICATION_STATUS_TYPES_COMPLETED,
NOTIFICATION_TEMPORARY_FAILURE,
STATUS_REASON_RETRYABLE,
STATUS_REASON_UNREACHABLE,
Expand Down Expand Up @@ -205,7 +206,7 @@ def process_ses_results( # noqa: C901 (too complex 14 > 10)
)
return

if incoming_status in (NOTIFICATION_PERMANENT_FAILURE, NOTIFICATION_DELIVERED):
if incoming_status in NOTIFICATION_STATUS_TYPES_COMPLETED:
mchlwellman marked this conversation as resolved.
Show resolved Hide resolved
notification.personalisation = {k: '<redacted>' for k in notification.personalisation}
mchlwellman marked this conversation as resolved.
Show resolved Hide resolved

# This is a test of the new status. Is it a bounce?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,23 +541,23 @@ def test_get_include_payload_status_exception(notify_api, mocker, sample_notific
@pytest.mark.serial
def test_process_delivery_status_redacts_personalisation(
mocker,
notify_db_session,
sample_delivery_status_result_message,
sample_template,
sample_notification,
):
"""
Test that the Celery task will redact personalisation if the delivery status is in a final state.
"""
sample_notification(
notification = sample_notification(
template=sample_template(content='Test ((foo))'),
reference='SMyyy',
mchlwellman marked this conversation as resolved.
Show resolved Hide resolved
sent_at=datetime.now(timezone.utc),
status=NOTIFICATION_SENDING,
personalisation={'foo': 'bar'},
)

mocker.patch('app.celery.process_delivery_status_result_tasks._get_include_payload_status', returns=True)
process_delivery_status(event=sample_delivery_status_result_message)
mchlwellman marked this conversation as resolved.
Show resolved Hide resolved

notification = dao_get_notification_by_reference('SMyyy')
notify_db_session.session.refresh(notification)
assert notification.personalisation == {'foo': '<redacted>'}
5 changes: 3 additions & 2 deletions tests/app/celery/test_process_pinpoint_receipt_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,15 @@ def test_process_pinpoint_callback_message_parse_exception(

def test_process_pinpoint_results_notification_final_status_personalisation(
mocker,
notify_db_session,
sample_template,
sample_notification,
):
mock_callback = mocker.patch('app.celery.process_delivery_status_result_tasks.check_and_queue_callback_task')

test_reference = str(uuid4())
template = sample_template(content='Hello ((name))')
sample_notification(
notification = sample_notification(
template=template,
reference=test_reference,
sent_at=datetime.now(timezone.utc),
Expand All @@ -375,6 +376,6 @@ def test_process_pinpoint_results_notification_final_status_personalisation(
reference=test_reference, event_type='_SMS.SUCCESS', record_status='DELIVERED'
)
)
notification = notifications_dao.dao_get_notification_by_reference(test_reference)
notify_db_session.session.refresh(notification)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤌

assert notification.personalisation == {'name': '<redacted>'}
mock_callback.assert_called_once()