mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
Added a way to handle complaint responses from SES.
At this point we are just logging the message so that we can confirm the contents of the SES message. refer to: https://www.pivotaltracker.com/story/show/157969699
This commit is contained in:
@@ -38,6 +38,10 @@ def process_ses_response(ses_request):
|
|||||||
notification_type = ses_message['bounce']['bounceType'] # permanent or not
|
notification_type = ses_message['bounce']['bounceType'] # permanent or not
|
||||||
else:
|
else:
|
||||||
notification_type = 'Temporary'
|
notification_type = 'Temporary'
|
||||||
|
if notification_type == 'Complaint':
|
||||||
|
current_app.logger.info("Complaint from SES: \n{}".format(ses_message))
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
aws_response_dict = get_aws_responses(notification_type)
|
aws_response_dict = get_aws_responses(notification_type)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|||||||
@@ -32,6 +32,13 @@ def test_process_ses_results_retry_called(notify_db, mocker):
|
|||||||
assert mocked.call_count != 0
|
assert mocked.call_count != 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_process_ses_results_in_complaint(notify_db, mocker):
|
||||||
|
mocked = mocker.patch("app.dao.notifications_dao.update_notification_status_by_reference")
|
||||||
|
response = json.loads(ses_complaint_callback())
|
||||||
|
process_ses_results(response=response)
|
||||||
|
assert mocked.call_count == 0
|
||||||
|
|
||||||
|
|
||||||
def ses_notification_callback():
|
def ses_notification_callback():
|
||||||
return '{\n "Type" : "Notification",\n "MessageId" : "ref1",' \
|
return '{\n "Type" : "Notification",\n "MessageId" : "ref1",' \
|
||||||
'\n "TopicArn" : "arn:aws:sns:eu-west-1:123456789012:testing",' \
|
'\n "TopicArn" : "arn:aws:sns:eu-west-1:123456789012:testing",' \
|
||||||
@@ -56,3 +63,18 @@ def ses_notification_callback():
|
|||||||
'dd426d95ee9390147a5624348ee.pem",' \
|
'dd426d95ee9390147a5624348ee.pem",' \
|
||||||
'\n "UnsubscribeURL" : "https://sns.eu-west-1.amazonaws.com/?Action=Unsubscribe&S' \
|
'\n "UnsubscribeURL" : "https://sns.eu-west-1.amazonaws.com/?Action=Unsubscribe&S' \
|
||||||
'ubscriptionArn=arn:aws:sns:eu-west-1:302763885840:preview-emails:d6aad3ef-83d6-4cf3-a470-54e2e75916da"\n}'
|
'ubscriptionArn=arn:aws:sns:eu-west-1:302763885840:preview-emails:d6aad3ef-83d6-4cf3-a470-54e2e75916da"\n}'
|
||||||
|
|
||||||
|
|
||||||
|
def ses_complaint_callback():
|
||||||
|
"""
|
||||||
|
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/notification-contents.html#complaint-object
|
||||||
|
"""
|
||||||
|
return '{\n "Type" : "Notification",\n "MessageId" : "ref1",' \
|
||||||
|
'\n "TopicArn" : "arn:aws:sns:eu-west-1:123456789012:testing",' \
|
||||||
|
'\n "Message" : "{\\"notificationType\\":\\"Complaint\\",' \
|
||||||
|
'\\"complaint\\": {\\"userAgent\\":\\"AnyCompany Feedback Loop (V0.01)\\",' \
|
||||||
|
'\\"complainedRecipients\\":[{\\"emailAddress\\":\\"recipient1@example.com\\"}],' \
|
||||||
|
'\\"complaintFeedbackType\\":\\"abuse\\", ' \
|
||||||
|
'\\"arrivalDate\\":\\"2009-12-03T04:24:21.000-05:00\\", ' \
|
||||||
|
'\\"timestamp\\":\\"2012-05-25T14:59:38.623Z\\", ' \
|
||||||
|
'\\"feedbackId\\":\\"someSESID\\"}}"\n}'
|
||||||
|
|||||||
Reference in New Issue
Block a user