all tests passing

This commit is contained in:
jimmoffet
2022-10-03 20:07:42 -07:00
parent c04d1df6b3
commit fc9e4107c1
8 changed files with 118 additions and 112 deletions

View File

@@ -177,7 +177,7 @@ def handle_complaint(ses_message):
try:
reference = ses_message["mail"]["messageId"]
except KeyError as e:
current_app.logger.exception("Complaint from SES failed to get reference from message", e)
current_app.logger.exception(f"Complaint from SES failed to get reference from message with error: {e}")
return
notification = dao_get_notification_history_by_reference(reference)
ses_complaint = ses_message.get("complaint", None)

View File

@@ -32,8 +32,10 @@ DEFAULT_MAX_AGE = timedelta(days=10000)
def email_ses_callback_handler():
try:
data = sns_notification_handler(request.data, request.headers)
except Exception as e:
raise InvalidRequest("SES-SNS callback failed: invalid message type", 400)
except InvalidRequest as e:
return jsonify(
result="error", message=str(e.message)
), e.status_code
message = data.get("Message")
if "mail" in message:

View File

@@ -83,90 +83,90 @@ def receive_sns_sms():
), 200
# @receive_notifications_blueprint.route('/notifications/sms/receive/mmg', methods=['POST'])
# def receive_mmg_sms():
# """
# {
# 'MSISDN': '447123456789'
# 'Number': '40604',
# 'Message': 'some+uri+encoded+message%3A',
# 'ID': 'SOME-MMG-SPECIFIC-ID',
# 'DateRecieved': '2017-05-21+11%3A56%3A11'
# }
# """
# post_data = request.get_json()
@receive_notifications_blueprint.route('/notifications/sms/receive/mmg', methods=['POST'])
def receive_mmg_sms():
"""
{
'MSISDN': '447123456789'
'Number': '40604',
'Message': 'some+uri+encoded+message%3A',
'ID': 'SOME-MMG-SPECIFIC-ID',
'DateRecieved': '2017-05-21+11%3A56%3A11'
}
"""
post_data = request.get_json()
# auth = request.authorization
auth = request.authorization
# if not auth:
# current_app.logger.warning("Inbound sms (MMG) no auth header")
# abort(401)
# elif auth.username not in current_app.config['MMG_INBOUND_SMS_USERNAME'] \
# or auth.password not in current_app.config['MMG_INBOUND_SMS_AUTH']:
# current_app.logger.warning("Inbound sms (MMG) incorrect username ({}) or password".format(auth.username))
# abort(403)
if not auth:
current_app.logger.warning("Inbound sms (MMG) no auth header")
abort(401)
elif auth.username not in current_app.config['MMG_INBOUND_SMS_USERNAME'] \
or auth.password not in current_app.config['MMG_INBOUND_SMS_AUTH']:
current_app.logger.warning("Inbound sms (MMG) incorrect username ({}) or password".format(auth.username))
abort(403)
# inbound_number = strip_leading_forty_four(post_data['Number'])
inbound_number = strip_leading_forty_four(post_data['Number'])
# service = fetch_potential_service(inbound_number, 'mmg')
# if not service:
# # since this is an issue with our service <-> number mapping, or no inbound_sms service permission
# # we should still tell MMG that we received it successfully
# return 'RECEIVED', 200
service = fetch_potential_service(inbound_number, 'mmg')
if not service:
# since this is an issue with our service <-> number mapping, or no inbound_sms service permission
# we should still tell MMG that we received it successfully
return 'RECEIVED', 200
# INBOUND_SMS_COUNTER.labels("mmg").inc()
INBOUND_SMS_COUNTER.labels("mmg").inc()
# inbound = create_inbound_sms_object(service,
# content=format_mmg_message(post_data["Message"]),
# from_number=post_data['MSISDN'],
# provider_ref=post_data["ID"],
# date_received=post_data.get('DateRecieved'),
# provider_name="mmg")
inbound = create_inbound_sms_object(service,
content=format_mmg_message(post_data["Message"]),
from_number=post_data['MSISDN'],
provider_ref=post_data["ID"],
date_received=post_data.get('DateRecieved'),
provider_name="mmg")
# tasks.send_inbound_sms_to_service.apply_async([str(inbound.id), str(service.id)], queue=QueueNames.NOTIFY)
tasks.send_inbound_sms_to_service.apply_async([str(inbound.id), str(service.id)], queue=QueueNames.NOTIFY)
# current_app.logger.debug(
# '{} received inbound SMS with reference {} from MMG'.format(service.id, inbound.provider_reference))
# return jsonify({
# "status": "ok"
# }), 200
current_app.logger.debug(
'{} received inbound SMS with reference {} from MMG'.format(service.id, inbound.provider_reference))
return jsonify({
"status": "ok"
}), 200
# @receive_notifications_blueprint.route('/notifications/sms/receive/firetext', methods=['POST'])
# def receive_firetext_sms():
# post_data = request.form
@receive_notifications_blueprint.route('/notifications/sms/receive/firetext', methods=['POST'])
def receive_firetext_sms():
post_data = request.form
# auth = request.authorization
# if not auth:
# current_app.logger.warning("Inbound sms (Firetext) no auth header")
# abort(401)
# elif auth.username != 'notify' or auth.password not in current_app.config['FIRETEXT_INBOUND_SMS_AUTH']:
# current_app.logger.warning("Inbound sms (Firetext) incorrect username ({}) or password".format(auth.username))
# abort(403)
auth = request.authorization
if not auth:
current_app.logger.warning("Inbound sms (Firetext) no auth header")
abort(401)
elif auth.username != 'notify' or auth.password not in current_app.config['FIRETEXT_INBOUND_SMS_AUTH']:
current_app.logger.warning("Inbound sms (Firetext) incorrect username ({}) or password".format(auth.username))
abort(403)
# inbound_number = strip_leading_forty_four(post_data['destination'])
inbound_number = strip_leading_forty_four(post_data['destination'])
# service = fetch_potential_service(inbound_number, 'firetext')
# if not service:
# return jsonify({
# "status": "ok"
# }), 200
service = fetch_potential_service(inbound_number, 'firetext')
if not service:
return jsonify({
"status": "ok"
}), 200
# inbound = create_inbound_sms_object(service=service,
# content=post_data["message"],
# from_number=post_data['source'],
# provider_ref=None,
# date_received=post_data['time'],
# provider_name="firetext")
inbound = create_inbound_sms_object(service=service,
content=post_data["message"],
from_number=post_data['source'],
provider_ref=None,
date_received=post_data['time'],
provider_name="firetext")
# INBOUND_SMS_COUNTER.labels("firetext").inc()
INBOUND_SMS_COUNTER.labels("firetext").inc()
# tasks.send_inbound_sms_to_service.apply_async([str(inbound.id), str(service.id)], queue=QueueNames.NOTIFY)
# current_app.logger.debug(
# '{} received inbound SMS with reference {} from Firetext'.format(service.id, inbound.provider_reference))
# return jsonify({
# "status": "ok"
# }), 200
tasks.send_inbound_sms_to_service.apply_async([str(inbound.id), str(service.id)], queue=QueueNames.NOTIFY)
current_app.logger.debug(
'{} received inbound SMS with reference {} from Firetext'.format(service.id, inbound.provider_reference))
return jsonify({
"status": "ok"
}), 200
def format_mmg_message(message):