mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
Merge pull request #1128 from alphagov/http-custom-header
Http custom header
This commit is contained in:
@@ -52,13 +52,18 @@ def restrict_ip_sms():
|
|||||||
ip_list = ip_route.split(',')
|
ip_list = ip_route.split(',')
|
||||||
if len(ip_list) >= 3:
|
if len(ip_list) >= 3:
|
||||||
ip = ip_list[len(ip_list) - 3]
|
ip = ip_list[len(ip_list) - 3]
|
||||||
current_app.logger.info("Inbound sms ip route list {}".format(ip_route))
|
current_app.logger.info("Inbound sms ip route list {}"
|
||||||
|
.format(ip_route))
|
||||||
|
|
||||||
|
# Temporary custom header for route security - to experiment if the header passes through
|
||||||
|
if request.headers.get("X-Custom-forwarder"):
|
||||||
|
current_app.logger.info("X-Custom-forwarder {}".format(request.headers.get("X-Custom-forwarder")))
|
||||||
|
|
||||||
if ip in current_app.config.get('SMS_INBOUND_WHITELIST'):
|
if ip in current_app.config.get('SMS_INBOUND_WHITELIST'):
|
||||||
current_app.logger.info("Inbound sms ip addresses {} passed ".format(ip))
|
current_app.logger.info("Inbound sms ip addresses {} passed ".format(ip))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
current_app.logger.info("Inbound sms ip addresses {} blocked ".format(ip))
|
current_app.logger.info("Inbound sms ip addresses blocked {}".format(ip))
|
||||||
return
|
return
|
||||||
# raise AuthError('Unknown source IP address from the SMS provider', 403)
|
# raise AuthError('Unknown source IP address from the SMS provider', 403)
|
||||||
|
|
||||||
|
|||||||
@@ -351,7 +351,7 @@ def test_reject_invalid_ips(restrict_ip_sms_app):
|
|||||||
assert exc_info.value.short_message == 'Unknown source IP address from the SMS provider'
|
assert exc_info.value.short_message == 'Unknown source IP address from the SMS provider'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(reason='Currently not blocking invalid IPs', strict=True)
|
@pytest.mark.xfail(reason='Currently not blocking invalid senders', strict=True)
|
||||||
def test_illegitimate_ips(restrict_ip_sms_app):
|
def test_illegitimate_ips(restrict_ip_sms_app):
|
||||||
with pytest.raises(AuthError) as exc_info:
|
with pytest.raises(AuthError) as exc_info:
|
||||||
restrict_ip_sms_app.get(
|
restrict_ip_sms_app.get(
|
||||||
@@ -361,4 +361,4 @@ def test_illegitimate_ips(restrict_ip_sms_app):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
assert exc_info.value.short_message == 'Unknown source IP address from the SMS provider'
|
assert exc_info.value.short_message == 'Unknown IP route not from known SMS provider'
|
||||||
|
|||||||
Reference in New Issue
Block a user