mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05:00
Merge pull request #1233 from GSA/notify-api-1135
Exception Investigation: app.authentication.auth:AuthError
This commit is contained in:
@@ -62,22 +62,30 @@ class ResponseHeaderMiddleware(object):
|
|||||||
self._app = app
|
self._app = app
|
||||||
|
|
||||||
def __call__(self, environ, start_response):
|
def __call__(self, environ, start_response):
|
||||||
req = NotifyRequest(environ)
|
try:
|
||||||
|
req = NotifyRequest(environ)
|
||||||
|
|
||||||
def rewrite_response_headers(status, headers, exc_info=None):
|
def rewrite_response_headers(status, headers, exc_info=None):
|
||||||
lower_existing_header_names = frozenset(
|
lower_existing_header_names = frozenset(
|
||||||
name.lower() for name, value in headers
|
name.lower() for name, value in headers
|
||||||
)
|
)
|
||||||
|
|
||||||
if TRACE_ID_HEADER.lower() not in lower_existing_header_names:
|
if TRACE_ID_HEADER.lower() not in lower_existing_header_names:
|
||||||
headers.append((TRACE_ID_HEADER, str(req.trace_id)))
|
headers.append((TRACE_ID_HEADER, str(req.trace_id)))
|
||||||
|
|
||||||
if SPAN_ID_HEADER.lower() not in lower_existing_header_names:
|
if SPAN_ID_HEADER.lower() not in lower_existing_header_names:
|
||||||
headers.append((SPAN_ID_HEADER, str(req.span_id)))
|
headers.append((SPAN_ID_HEADER, str(req.span_id)))
|
||||||
|
|
||||||
return start_response(status, headers, exc_info)
|
return start_response(status, headers, exc_info)
|
||||||
|
|
||||||
return self._app(environ, rewrite_response_headers)
|
return self._app(environ, rewrite_response_headers)
|
||||||
|
except BaseException as be: # noqa
|
||||||
|
if "AuthError" in str(be): # notify-api-1135
|
||||||
|
current_app.logger.error(be)
|
||||||
|
elif "AttributeError" in str(be): # notify-api-1394
|
||||||
|
current_app.logger.error(be)
|
||||||
|
else:
|
||||||
|
raise be
|
||||||
|
|
||||||
|
|
||||||
def init_app(app):
|
def init_app(app):
|
||||||
|
|||||||
@@ -330,7 +330,7 @@ def test_should_send_sms_with_downgraded_content(notify_db_session, mocker):
|
|||||||
template=template,
|
template=template,
|
||||||
)
|
)
|
||||||
db_notification.personalisation = {"misc": placeholder}
|
db_notification.personalisation = {"misc": placeholder}
|
||||||
db_notification.reply_to_text = 'testing'
|
db_notification.reply_to_text = "testing"
|
||||||
|
|
||||||
mocker.patch("app.aws_sns_client.send_sms")
|
mocker.patch("app.aws_sns_client.send_sms")
|
||||||
|
|
||||||
@@ -622,7 +622,7 @@ def test_should_update_billable_units_and_status_according_to_research_mode_and_
|
|||||||
billable_units=0,
|
billable_units=0,
|
||||||
status=NotificationStatus.CREATED,
|
status=NotificationStatus.CREATED,
|
||||||
key_type=key_type,
|
key_type=key_type,
|
||||||
reply_to_text='testing',
|
reply_to_text="testing",
|
||||||
)
|
)
|
||||||
mocker.patch("app.aws_sns_client.send_sms")
|
mocker.patch("app.aws_sns_client.send_sms")
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
@@ -786,7 +786,10 @@ def test_send_sms_to_provider_should_use_normalised_to(mocker, client, sample_te
|
|||||||
)
|
)
|
||||||
send_mock = mocker.patch("app.aws_sns_client.send_sms")
|
send_mock = mocker.patch("app.aws_sns_client.send_sms")
|
||||||
notification = create_notification(
|
notification = create_notification(
|
||||||
template=sample_template, to_field="+12028675309", normalised_to="2028675309", reply_to_text='testing'
|
template=sample_template,
|
||||||
|
to_field="+12028675309",
|
||||||
|
normalised_to="2028675309",
|
||||||
|
reply_to_text="testing",
|
||||||
)
|
)
|
||||||
|
|
||||||
mock_s3 = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
|
mock_s3 = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
|
||||||
@@ -862,7 +865,10 @@ def test_send_sms_to_provider_should_return_template_if_found_in_redis(
|
|||||||
|
|
||||||
send_mock = mocker.patch("app.aws_sns_client.send_sms")
|
send_mock = mocker.patch("app.aws_sns_client.send_sms")
|
||||||
notification = create_notification(
|
notification = create_notification(
|
||||||
template=sample_template, to_field="+447700900855", normalised_to="447700900855", reply_to_text='testing'
|
template=sample_template,
|
||||||
|
to_field="+447700900855",
|
||||||
|
normalised_to="447700900855",
|
||||||
|
reply_to_text="testing",
|
||||||
)
|
)
|
||||||
|
|
||||||
mock_s3 = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
|
mock_s3 = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
|
||||||
|
|||||||
Reference in New Issue
Block a user