mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-15 09:42:38 -05:00
fix 500s when inbound msgs sent from alphanumerics rather than normal phone numbers
This commit is contained in:
@@ -486,6 +486,7 @@ def send_inbound_sms_to_service(self, inbound_sms_id, service_id):
|
|||||||
inbound_id=inbound_sms_id)
|
inbound_id=inbound_sms_id)
|
||||||
data = {
|
data = {
|
||||||
"id": str(inbound_sms.id),
|
"id": str(inbound_sms.id),
|
||||||
|
# TODO: should we be validating and formatting the phone number here?
|
||||||
"source_number": inbound_sms.user_number,
|
"source_number": inbound_sms.user_number,
|
||||||
"destination_number": inbound_sms.notify_number,
|
"destination_number": inbound_sms.notify_number,
|
||||||
"message": inbound_sms.content,
|
"message": inbound_sms.content,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from urllib.parse import unquote
|
|||||||
|
|
||||||
import iso8601
|
import iso8601
|
||||||
from flask import jsonify, Blueprint, current_app, request, abort
|
from flask import jsonify, Blueprint, current_app, request, abort
|
||||||
from notifications_utils.recipients import validate_and_format_phone_number
|
from notifications_utils.recipients import try_validate_and_format_phone_number
|
||||||
|
|
||||||
from app import statsd_client, firetext_client, mmg_client
|
from app import statsd_client, firetext_client, mmg_client
|
||||||
from app.celery import tasks
|
from app.celery import tasks
|
||||||
@@ -109,7 +109,11 @@ def format_mmg_datetime(date):
|
|||||||
|
|
||||||
|
|
||||||
def create_inbound_sms_object(service, content, from_number, provider_ref, date_received, provider_name):
|
def create_inbound_sms_object(service, content, from_number, provider_ref, date_received, provider_name):
|
||||||
user_number = validate_and_format_phone_number(from_number, international=True)
|
user_number = try_validate_and_format_phone_number(
|
||||||
|
from_number,
|
||||||
|
international=True,
|
||||||
|
log_msg='Invalid from_number received'
|
||||||
|
)
|
||||||
|
|
||||||
provider_date = date_received
|
provider_date = date_received
|
||||||
if provider_date:
|
if provider_date:
|
||||||
|
|||||||
@@ -26,6 +26,6 @@ notifications-python-client==4.6.0
|
|||||||
awscli>=1.11,<1.12
|
awscli>=1.11,<1.12
|
||||||
awscli-cwlogs>=1.4,<1.5
|
awscli-cwlogs>=1.4,<1.5
|
||||||
|
|
||||||
git+https://github.com/alphagov/notifications-utils.git@23.0.1#egg=notifications-utils==23.0.1
|
git+https://github.com/alphagov/notifications-utils.git@23.1.0#egg=notifications-utils==23.1.0
|
||||||
|
|
||||||
git+https://github.com/alphagov/boto.git@2.43.0-patch3#egg=boto==2.43.0-patch3
|
git+https://github.com/alphagov/boto.git@2.43.0-patch3#egg=boto==2.43.0-patch3
|
||||||
|
|||||||
@@ -413,3 +413,24 @@ def test_firetext_inbound_sms_auth(notify_db_session, notify_api, client, mocker
|
|||||||
with set_config(notify_api, 'FIRETEXT_INBOUND_SMS_AUTH', keys):
|
with set_config(notify_api, 'FIRETEXT_INBOUND_SMS_AUTH', keys):
|
||||||
response = firetext_post(client, data, auth=bool(auth), password=auth)
|
response = firetext_post(client, data, auth=bool(auth), password=auth)
|
||||||
assert response.status_code == status_code
|
assert response.status_code == status_code
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_inbound_sms_object_works_with_alphanumeric_sender(sample_service_full_permissions):
|
||||||
|
data = {
|
||||||
|
'Message': 'hello',
|
||||||
|
'Number': sample_service_full_permissions.get_inbound_number(),
|
||||||
|
'MSISDN': 'ALPHANUM3R1C',
|
||||||
|
'DateRecieved': '2017-01-02+03%3A04%3A05',
|
||||||
|
'ID': 'bar',
|
||||||
|
}
|
||||||
|
|
||||||
|
inbound_sms = create_inbound_sms_object(
|
||||||
|
service=sample_service_full_permissions,
|
||||||
|
content=format_mmg_message(data["Message"]),
|
||||||
|
from_number='ALPHANUM3R1C',
|
||||||
|
provider_ref='foo',
|
||||||
|
date_received=None,
|
||||||
|
provider_name="mmg"
|
||||||
|
)
|
||||||
|
|
||||||
|
assert inbound_sms.user_number == 'ALPHANUM3R1C'
|
||||||
|
|||||||
Reference in New Issue
Block a user