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

MPP-3932: Add flag 'developer_mode', use to simulate complaint and log notifications #5090

Merged
merged 19 commits into from
Oct 15, 2024

Conversation

jwhitlock
Copy link
Member

Add a new waffle flag 'developer_mode', that enables additional logging for the user. This logging goes beyond our user privacy policy, so it should only be enabled for Relay staff with consent. In addition, special mask labels are used to limit logging for forwarded emails.

For forwarded mail, the mask label is used to determine developer actions. If the mask contains DEV:simulate_complaint (no spaces), then the mail is forwarded to the AWS complaint simulator address instead of the user's real address. If the mask contains DEV: (which includes (DEV:simulate_complaint)), the received notification itself is logged, using zlib.compress and base64.a85encode to reduce the size. If the encoded notification is more than 1024 bytes, the message is split over several log lines.

For complaints, any complaint notification for the user is logged. When we can reliably detect the mask, we may change this to use the mask label to further limit logging.

How to test:

I wrote tests for the new functionality in handling forwards and complaints.
I refactored the ComplaintHandlingTest to add the mail element to all test complaint notifications, and to use the forwarded "russian spam" fixture instead of the incoming version. This required some other changes to mock a Date header, added by SES when forwarding the email.

I did not manually test this code. I plan to test it on the dev server, where we can set flags and debug the results.

@jwhitlock jwhitlock requested a review from groovecoder October 11, 2024 16:49
emails/views.py Outdated
Comment on lines 1001 to 1003
notification_gza85 = base64.a85encode(
zlib.compress(json.dumps(notification).encode()), wrapcol=1024, pad=True
).decode("ascii")
Copy link
Member

Choose a reason for hiding this comment

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

quesgestion (non-blocking): can this sequence of base64, zlib, and json calls be moved into a helper function format_notification_for_log that can help with re-using it exactly the same way each time? E.g., in the test code?

@jwhitlock
Copy link
Member Author

Added emails.utils.encode_dict_gza85 and emails.utils.decode_dict_gza85. I'll merge after tests pass.

@jwhitlock jwhitlock enabled auto-merge October 15, 2024 15:58
@jwhitlock jwhitlock added this pull request to the merge queue Oct 15, 2024
Merged via the queue into main with commit c74a6de Oct 15, 2024
29 checks passed
@jwhitlock jwhitlock deleted the add-developer-mode-flag-mpp-3932 branch October 15, 2024 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants