Skip to content

Commit

Permalink
complaintFeedbackType is not required
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhitlock committed Nov 6, 2024
1 parent 43607a9 commit f730078
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
27 changes: 9 additions & 18 deletions emails/tests/views_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1494,23 +1494,23 @@ def test_minimal_complaint(self):
message = {
"complaint": {
"complainedRecipients": [{"emailAddress": "[email protected]"}],
"complaintFeedbackType": "abuse",
},
"mail": {"commonHeaders": {"from": ["[email protected]"]}},
}
complaint_data = _get_complaint_data(message)
with self.assertNoLogs(ERROR_LOG):
complaint_data = _get_complaint_data(message)
assert complaint_data == RawComplaintData(
complained_recipients=[("[email protected]", {})],
from_addresses=["[email protected]"],
subtype="",
user_agent="",
feedback_type="abuse",
feedback_type="",
)

def test_no_complained_recipients_error_logged(self):
"""When complaint.complainedRecipients is missing, an error is logged."""
message = {
"complaint": {"complaintFeedbackType": "abuse"},
"complaint": {},
"mail": {"commonHeaders": {"from": ["[email protected]"]}},
}
with self.assertLogs(ERROR_LOG) as error_logs:
Expand All @@ -1520,12 +1520,12 @@ def test_no_complained_recipients_error_logged(self):
(err_log,) = error_logs.records
assert err_log.msg == "_get_complaint_data: Unexpected message format"
assert getattr(err_log, "missing_key") == "complainedRecipients"
assert getattr(err_log, "found_keys") == "complaintFeedbackType"
assert getattr(err_log, "found_keys") == ""

def test_empty_complained_recipients_error_logged(self):
"""When complaint.complainedRecipients is empty, an error is logged."""
message = {
"complaint": {"complainedRecipients": [], "complaintFeedbackType": "abuse"},
"complaint": {"complainedRecipients": []},
"mail": {"commonHeaders": {"from": ["[email protected]"]}},
}
with self.assertLogs(ERROR_LOG) as error_logs:
Expand All @@ -1543,7 +1543,6 @@ def test_wrong_complained_recipients_error_logged(self):
message = {
"complaint": {
"complainedRecipients": [{"foo": "bar"}],
"complaintFeedbackType": "abuse",
},
"mail": {"commonHeaders": {"from": ["[email protected]"]}},
}
Expand All @@ -1561,7 +1560,6 @@ def test_no_mail_error_logged(self):
message = {
"complaint": {
"complainedRecipients": [{"emailAddress": "[email protected]"}],
"complaintFeedbackType": "abuse",
},
}
with self.assertLogs(ERROR_LOG) as error_logs:
Expand All @@ -1578,7 +1576,6 @@ def test_no_common_headers_error_logged(self):
message = {
"complaint": {
"complainedRecipients": [{"emailAddress": "[email protected]"}],
"complaintFeedbackType": "abuse",
},
"mail": {},
}
Expand All @@ -1596,7 +1593,6 @@ def test_no_from_header_error_logged(self):
message = {
"complaint": {
"complainedRecipients": [{"emailAddress": "[email protected]"}],
"complaintFeedbackType": "abuse",
},
"mail": {"commonHeaders": {}},
}
Expand All @@ -1609,23 +1605,18 @@ def test_no_from_header_error_logged(self):
assert getattr(err_log, "missing_key") == "from"
assert getattr(err_log, "found_keys") == ""

def test_no_feedback_type_error_logged(self):
"""If the From header entry is missing, an error is logged."""
def test_no_feedback_type_not_an_error(self):
"""If the feedback type is missing, no error is logged"""
message = {
"complaint": {
"complainedRecipients": [{"emailAddress": "[email protected]"}],
},
"mail": {"commonHeaders": {"from": ["[email protected]"]}},
}
with self.assertLogs(ERROR_LOG) as error_logs:
with self.assertNoLogs(ERROR_LOG):
complaint_data = _get_complaint_data(message)
assert complaint_data.feedback_type == ""

(err_log,) = error_logs.records
assert err_log.msg == "_get_complaint_data: Unexpected message format"
assert getattr(err_log, "missing_key") == "complaintFeedbackType"
assert getattr(err_log, "found_keys") == "complainedRecipients"


class GatherComplainersTest(TestCase):
"""
Expand Down
4 changes: 2 additions & 2 deletions emails/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1866,8 +1866,8 @@ def get_or_log(
raw_from_addresses = []
from_addresses = [parseaddr(addr)[1] for addr in raw_from_addresses]

feedback_type, _ = get_or_log("complaintFeedbackType", complaint, str)

# Only present when set
feedback_type = complaint.get("complaintFeedbackType", "")
# Only present when destination is on account suppression list
subtype = complaint.get("complaintSubType", "")
# Only present for feedback reports
Expand Down

0 comments on commit f730078

Please sign in to comment.