mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 23:41:17 -05:00
Change MMG username to look at env variable
This commit is contained in:
@@ -49,6 +49,7 @@ def extract_notify_config(notify_config):
|
|||||||
os.environ['SMS_INBOUND_WHITELIST'] = json.dumps(notify_config['credentials']['allow_ip_inbound_sms'])
|
os.environ['SMS_INBOUND_WHITELIST'] = json.dumps(notify_config['credentials']['allow_ip_inbound_sms'])
|
||||||
os.environ['FIRETEXT_INBOUND_SMS_AUTH'] = json.dumps(notify_config['credentials']['firetext_inbound_sms_auth'])
|
os.environ['FIRETEXT_INBOUND_SMS_AUTH'] = json.dumps(notify_config['credentials']['firetext_inbound_sms_auth'])
|
||||||
os.environ['MMG_INBOUND_SMS_AUTH'] = json.dumps(notify_config['credentials']['mmg_inbound_sms_auth'])
|
os.environ['MMG_INBOUND_SMS_AUTH'] = json.dumps(notify_config['credentials']['mmg_inbound_sms_auth'])
|
||||||
|
os.environ['MMG_INBOUND_SMS_USERNAME'] = json.dumps(notify_config['credentials']['mmg_inbound_sms_username'])
|
||||||
os.environ['ROUTE_SECRET_KEY_1'] = notify_config['credentials']['route_secret_key_1']
|
os.environ['ROUTE_SECRET_KEY_1'] = notify_config['credentials']['route_secret_key_1']
|
||||||
os.environ['ROUTE_SECRET_KEY_2'] = notify_config['credentials']['route_secret_key_2']
|
os.environ['ROUTE_SECRET_KEY_2'] = notify_config['credentials']['route_secret_key_2']
|
||||||
|
|
||||||
|
|||||||
@@ -301,6 +301,7 @@ class Config(object):
|
|||||||
SMS_INBOUND_WHITELIST = json.loads(os.environ.get('SMS_INBOUND_WHITELIST', '[]'))
|
SMS_INBOUND_WHITELIST = json.loads(os.environ.get('SMS_INBOUND_WHITELIST', '[]'))
|
||||||
FIRETEXT_INBOUND_SMS_AUTH = json.loads(os.environ.get('FIRETEXT_INBOUND_SMS_AUTH', '[]'))
|
FIRETEXT_INBOUND_SMS_AUTH = json.loads(os.environ.get('FIRETEXT_INBOUND_SMS_AUTH', '[]'))
|
||||||
MMG_INBOUND_SMS_AUTH = json.loads(os.environ.get('MMG_INBOUND_SMS_AUTH', '[]'))
|
MMG_INBOUND_SMS_AUTH = json.loads(os.environ.get('MMG_INBOUND_SMS_AUTH', '[]'))
|
||||||
|
MMG_INBOUND_SMS_USERNAME = json.loads(os.environ.get('MMG_INBOUND_SMS_USERNAME', '[]'))
|
||||||
|
|
||||||
ROUTE_SECRET_KEY_1 = os.environ.get('ROUTE_SECRET_KEY_1', '')
|
ROUTE_SECRET_KEY_1 = os.environ.get('ROUTE_SECRET_KEY_1', '')
|
||||||
ROUTE_SECRET_KEY_2 = os.environ.get('ROUTE_SECRET_KEY_2', '')
|
ROUTE_SECRET_KEY_2 = os.environ.get('ROUTE_SECRET_KEY_2', '')
|
||||||
@@ -378,6 +379,7 @@ class Test(Config):
|
|||||||
SMS_INBOUND_WHITELIST = ['203.0.113.195']
|
SMS_INBOUND_WHITELIST = ['203.0.113.195']
|
||||||
FIRETEXT_INBOUND_SMS_AUTH = ['testkey']
|
FIRETEXT_INBOUND_SMS_AUTH = ['testkey']
|
||||||
MMG_INBOUND_SMS_AUTH = ['testkey']
|
MMG_INBOUND_SMS_AUTH = ['testkey']
|
||||||
|
MMG_INBOUND_SMS_USERNAME = ['username']
|
||||||
TEMPLATE_PREVIEW_API_HOST = 'http://localhost:9999'
|
TEMPLATE_PREVIEW_API_HOST = 'http://localhost:9999'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ def receive_mmg_sms():
|
|||||||
if not auth:
|
if not auth:
|
||||||
current_app.logger.warning("Inbound sms (MMG) no auth header")
|
current_app.logger.warning("Inbound sms (MMG) no auth header")
|
||||||
# abort(401)
|
# abort(401)
|
||||||
elif auth.username != 'mmg_co_2017' or auth.password not in current_app.config['MMG_INBOUND_SMS_AUTH']:
|
elif auth.username not in current_app.config['MMG_INBOUND_SMS_USERNAME'] \
|
||||||
|
or auth.password not in current_app.config['MMG_INBOUND_SMS_AUTH']:
|
||||||
current_app.logger.warning("Inbound sms (MMG) incorrect username ({}) or password".format(auth.username))
|
current_app.logger.warning("Inbound sms (MMG) incorrect username ({}) or password".format(auth.username))
|
||||||
# abort(403)
|
# abort(403)
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ def mmg_post(client, data, auth=True, password='testkey'):
|
|||||||
]
|
]
|
||||||
|
|
||||||
if auth:
|
if auth:
|
||||||
auth_value = base64.b64encode("notify:{}".format(password).encode('utf-8')).decode('utf-8')
|
auth_value = base64.b64encode("username:{}".format(password).encode('utf-8')).decode('utf-8')
|
||||||
headers.append(('Authorization', 'Basic ' + auth_value))
|
headers.append(('Authorization', 'Basic ' + auth_value))
|
||||||
|
|
||||||
return client.post(
|
return client.post(
|
||||||
@@ -438,7 +438,15 @@ def test_mmg_inbound_sms_auth(notify_db_session, notify_api, client, mocker, aut
|
|||||||
service_name='b', inbound_number='07111111111', service_permissions=[EMAIL_TYPE, SMS_TYPE, INBOUND_SMS_TYPE]
|
service_name='b', inbound_number='07111111111', service_permissions=[EMAIL_TYPE, SMS_TYPE, INBOUND_SMS_TYPE]
|
||||||
)
|
)
|
||||||
|
|
||||||
data = "source=07999999999&destination=07111111111&message=this is a message&time=2017-01-01 12:00:00"
|
data = {
|
||||||
|
"ID": "1234",
|
||||||
|
"MSISDN": "07111111111",
|
||||||
|
"Message": "Some message to notify",
|
||||||
|
"Trigger": "Trigger?",
|
||||||
|
"Number": "testing",
|
||||||
|
"Channel": "SMS",
|
||||||
|
"DateRecieved": "2012-06-27 12:33:00"
|
||||||
|
}
|
||||||
|
|
||||||
with set_config(notify_api, 'MMG_INBOUND_SMS_AUTH', keys):
|
with set_config(notify_api, 'MMG_INBOUND_SMS_AUTH', keys):
|
||||||
response = mmg_post(client, data, auth=bool(auth), password=auth)
|
response = mmg_post(client, data, auth=bool(auth), password=auth)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ def notify_config():
|
|||||||
'allow_ip_inbound_sms': ['111.111.111.111', '100.100.100.100'],
|
'allow_ip_inbound_sms': ['111.111.111.111', '100.100.100.100'],
|
||||||
'firetext_inbound_sms_auth': ['testkey'],
|
'firetext_inbound_sms_auth': ['testkey'],
|
||||||
'mmg_inbound_sms_auth': ['testkey'],
|
'mmg_inbound_sms_auth': ['testkey'],
|
||||||
|
'mmg_inbound_sms_username': ['username'],
|
||||||
'route_secret_key_1': "key_1",
|
'route_secret_key_1': "key_1",
|
||||||
'route_secret_key_2': ""
|
'route_secret_key_2': ""
|
||||||
}
|
}
|
||||||
@@ -240,6 +241,13 @@ def test_mmg_inbound_sms_auth_config():
|
|||||||
assert os.environ['MMG_INBOUND_SMS_AUTH'] == json.dumps(['testkey'])
|
assert os.environ['MMG_INBOUND_SMS_AUTH'] == json.dumps(['testkey'])
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ')
|
||||||
|
def test_mmg_inbound_sms_username_config():
|
||||||
|
extract_cloudfoundry_config()
|
||||||
|
|
||||||
|
assert os.environ['MMG_INBOUND_SMS_USERNAME'] == json.dumps(['username'])
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ')
|
@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ')
|
||||||
def test_performance_platform_config():
|
def test_performance_platform_config():
|
||||||
extract_cloudfoundry_config()
|
extract_cloudfoundry_config()
|
||||||
|
|||||||
Reference in New Issue
Block a user