Check ip unit test and modify ways to parse IP address

This commit is contained in:
venusbb
2017-07-04 17:31:40 +01:00
parent 2ff9204a61
commit c182ceca90
2 changed files with 49 additions and 4 deletions

View File

@@ -46,10 +46,10 @@ def requires_no_auth():
def restrict_ip_sms():
ip = ''
if request.headers.getlist("X-Forwarded-For"):
ip0 = request.headers.getlist("X-Forwarded-For")
ip1 = ip0.split(',')
ip = ip1[0]
if request.headers.get("X-Forwarded-For"):
# X-Forwarded-For looks like "203.0.113.195, 70.41.3.18, 150.172.238.178"
ip_list = request.headers.get("X-Forwarded-For")
ip = ip_list.split(',')[0].strip()
if ip in current_app.config.get('ALLOW_IP_INBOUND_SMS'):
current_app.logger.info("Inbound sms ip addresses {} passed ".format(ip))