From ab5b7c20a7516d81442c08962b634ea26cc06688 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Mon, 27 Nov 2017 16:52:52 +0000 Subject: [PATCH] Use sms sender or reply to email address of the Notify service in create_2fa_code depending on message type. --- app/user/rest.py | 8 ++++++-- tests/app/user/test_rest_verify.py | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/user/rest.py b/app/user/rest.py index 6a264e7fe..4b4e9c943 100644 --- a/app/user/rest.py +++ b/app/user/rest.py @@ -214,7 +214,11 @@ def create_2fa_code(template_id, user_to_send_to, secret_code, recipient, person # save the code in the VerifyCode table create_user_code(user_to_send_to, secret_code, template.template_type) - + reply_to = None + if template.template_type == SMS_TYPE: + reply_to = template.service.get_default_sms_sender() + elif template.template_type == EMAIL_TYPE: + reply_to = template.service.get_default_reply_to_email_address() saved_notification = persist_notification( template_id=template.id, template_version=template.version, @@ -224,7 +228,7 @@ def create_2fa_code(template_id, user_to_send_to, secret_code, recipient, person notification_type=template.template_type, api_key_id=None, key_type=KEY_TYPE_NORMAL, - reply_to_text=template.service.get_default_sms_sender() + reply_to_text=reply_to ) # Assume that we never want to observe the Notify service's research mode # setting for this notification - we still need to be able to log into the diff --git a/tests/app/user/test_rest_verify.py b/tests/app/user/test_rest_verify.py index adf39aa96..d361987d6 100644 --- a/tests/app/user/test_rest_verify.py +++ b/tests/app/user/test_rest_verify.py @@ -357,6 +357,7 @@ def test_send_user_email_code(admin_request, mocker, sample_user, email_2fa_code _expected_status=204 ) noti = Notification.query.one() + assert noti.reply_to_text == email_2fa_code_template.service.get_default_reply_to_email_address() assert noti.to == sample_user.email_address assert str(noti.template_id) == current_app.config['EMAIL_2FA_TEMPLATE_ID'] assert noti.personalisation['name'] == 'Test User'