diff --git a/app/celery/tasks.py b/app/celery/tasks.py index 436def14d..e96d7e3d8 100644 --- a/app/celery/tasks.py +++ b/app/celery/tasks.py @@ -486,6 +486,7 @@ def send_inbound_sms_to_service(self, inbound_sms_id, service_id): inbound_id=inbound_sms_id) data = { "id": str(inbound_sms.id), + # TODO: should we be validating and formatting the phone number here? "source_number": inbound_sms.user_number, "destination_number": inbound_sms.notify_number, "message": inbound_sms.content, diff --git a/app/notifications/receive_notifications.py b/app/notifications/receive_notifications.py index 3167134e3..22a7fe61e 100644 --- a/app/notifications/receive_notifications.py +++ b/app/notifications/receive_notifications.py @@ -2,7 +2,7 @@ from urllib.parse import unquote import iso8601 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.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): - 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 if provider_date: diff --git a/requirements.txt b/requirements.txt index 8d69902c5..8b5cb9f35 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,6 +26,6 @@ notifications-python-client==4.6.0 awscli>=1.11,<1.12 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 diff --git a/tests/app/notifications/test_receive_notification.py b/tests/app/notifications/test_receive_notification.py index 7f784135c..fbd190a50 100644 --- a/tests/app/notifications/test_receive_notification.py +++ b/tests/app/notifications/test_receive_notification.py @@ -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): response = firetext_post(client, data, auth=bool(auth), password=auth) 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'