fix tests

This commit is contained in:
jimmoffet
2022-09-30 10:59:48 -04:00
parent 1161e2c6cb
commit 48af6f7c23
8 changed files with 20 additions and 80 deletions

View File

@@ -71,7 +71,6 @@ test: ## Run tests
freeze-requirements: ## Pin all requirements including sub dependencies into requirements.txt freeze-requirements: ## Pin all requirements including sub dependencies into requirements.txt
pip install --upgrade pip-tools pip install --upgrade pip-tools
pip-compile requirements.in pip-compile requirements.in
pip install -r requirements.txt
.PHONY: audit .PHONY: audit
audit: audit:
@@ -138,11 +137,11 @@ cf-deploy-api-db-migration:
cf push notifications-api --no-route -f ${CF_MANIFEST_PATH} cf push notifications-api --no-route -f ${CF_MANIFEST_PATH}
rm ${CF_MANIFEST_PATH} rm ${CF_MANIFEST_PATH}
cf run-task notify-api-alt --command="flask db upgrade" --name api_db_migration cf run-task notifications-api --command="flask db upgrade" --name api_db_migration
.PHONY: cf-check-api-db-migration-task .PHONY: cf-check-api-db-migration-task
cf-check-api-db-migration-task: ## Get the status for the last notifications-api task cf-check-api-db-migration-task: ## Get the status for the last notifications-api task
@cf curl /v3/apps/`cf app --guid notify-api-alt`/tasks?order_by=-created_at | jq -r ".resources[0].state" @cf curl /v3/apps/`cf app --guid notifications-api`/tasks?order_by=-created_at | jq -r ".resources[0].state"
.PHONY: cf-rollback .PHONY: cf-rollback
cf-rollback: ## Rollbacks the app to the previous release cf-rollback: ## Rollbacks the app to the previous release

View File

@@ -1,15 +1,15 @@
import enum import enum
import traceback
from datetime import datetime, timedelta from datetime import datetime, timedelta
from json import decoder from json import decoder
import iso8601 import iso8601
import requests import requests
import traceback
from celery.exceptions import Retry from celery.exceptions import Retry
from flask import Blueprint, current_app, json, jsonify, request from flask import Blueprint, current_app, json, jsonify, request
from sqlalchemy.orm.exc import NoResultFound from sqlalchemy.orm.exc import NoResultFound
from app import notify_celery, statsd_client, redis_store from app import notify_celery, redis_store, statsd_client
from app.celery.validate_sns import validate_sns_message from app.celery.validate_sns import validate_sns_message
from app.config import QueueNames from app.config import QueueNames
from app.dao import notifications_dao from app.dao import notifications_dao

View File

@@ -2,15 +2,14 @@ import base64
import re import re
from urllib.parse import urlparse from urllib.parse import urlparse
import requests
import oscrypto.asymmetric import oscrypto.asymmetric
import oscrypto.errors import oscrypto.errors
import requests
import six
from app import redis_store from app import redis_store
from app.config import Config from app.config import Config
import six
USE_CACHE = True USE_CACHE = True
VALIDATE_ARN = True VALIDATE_ARN = True
VALID_SNS_TOPICS = Config.VALID_SNS_TOPICS VALID_SNS_TOPICS = Config.VALID_SNS_TOPICS

View File

@@ -23,62 +23,6 @@ INBOUND_SMS_COUNTER = Counter(
['provider'] ['provider']
) )
@receive_notifications_blueprint.route('/notifications/sms/receive/sns', methods=['POST'])
def receive_sns_sms():
"""
{
"originationNumber":"+14255550182",
"destinationNumber":"+12125550101",
"messageKeyword":"JOIN", # this is optional
"messageBody":"EXAMPLE",
"inboundMessageId":"cae173d2-66b9-564c-8309-21f858e9fb84",
"previousPublishedMessageId":"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
}
"""
post_data = request.get_json()
# validate sns from common module, WILL ALSO NEED TO AUTO-SUBSCRIBE... raise errors appropriately
# TODO modify this for AWS SNS
inbound_number = strip_leading_forty_four(post_data['Number'])
service = fetch_potential_service(inbound_number, 'sns')
if not service:
# since this is an issue with our service <-> number mapping, or no inbound_sms service permission
# we should still tell SNS that we received it successfully
current_app.logger.warning(f"Mapping between service id and inbound number is broken, or service does not have permission to receive inbound sms")
return jsonify({
"status": "ok"
}), 200
INBOUND_SMS_COUNTER.labels("sns").inc()
content = format_mmg_message(post_data["Message"])
from_number = post_data['MSISDN']
provider_ref = post_data["ID"]
date_received = post_data.get('DateRecieved')
provider_name = "sns"
inbound_payload = {}
# TODO fill inbound_payload and spread like create_inbound_sms_object(service, **inbound_payload)
inbound = create_inbound_sms_object(service,
content=format_mmg_message(post_data["Message"]),
from_number=from_number,
provider_ref=provider_ref,
date_received=date_received,
provider_name=provider_name)
# TODO ensure inbound sms callback endpoints are accessible and functioning for notify api users
# tasks.send_inbound_sms_to_service.apply_async([str(inbound.id), str(service.id)], queue=QueueNames.NOTIFY)
current_app.logger.debug(
'{} received inbound SMS with reference {} from SNS'.format(service.id, inbound.provider_reference))
return jsonify({
"status": "ok"
}), 200
@receive_notifications_blueprint.route('/notifications/sms/receive/mmg', methods=['POST']) @receive_notifications_blueprint.route('/notifications/sms/receive/mmg', methods=['POST'])
def receive_mmg_sms(): def receive_mmg_sms():

View File

@@ -21,7 +21,6 @@ RUN apt-get update \
openssh-client \ openssh-client \
procps \ procps \
sudo \ sudo \
swig \
tldr \ tldr \
unzip \ unzip \
vim \ vim \

View File

@@ -1,7 +1,6 @@
--- ---
applications: applications:
- name: notify-api-alt - name: notifications-api-((env))
buildpack: https://github.com/cloudfoundry/python-buildpack.git#v1.7.58 buildpack: https://github.com/cloudfoundry/python-buildpack.git#v1.7.58
instances: 1 instances: 1
memory: 1G memory: 1G
@@ -9,29 +8,29 @@ applications:
health-check-type: process health-check-type: process
health-check-invocation-timeout: 1 health-check-invocation-timeout: 1
routes: routes:
- route: notify-api-alt.app.cloud.gov - route: notifications-api.app.cloud.gov
- route: notifications-api-((env)).apps.internal
services: services:
- api-alt-psql - notifications-api-rds-((env))
- api-alt-redis - notifications-api-redis-((env))
- notifications-api-csv-upload-bucket-((env))
- notifications-api-contact-list-bucket-((env))
env: env:
BP_PIP_VERSION: latest
NOTIFY_APP_NAME: api NOTIFY_APP_NAME: api
NOTIFY_LOG_PATH: /home/vcap/logs/app.log NOTIFY_LOG_PATH: /home/vcap/logs/app.log
FLASK_APP: application.py FLASK_APP: application.py
FLASK_ENV: production FLASK_ENV: production
DEPLOY_ENV: ((env))
NOTIFY_ENVIRONMENT: live NOTIFY_ENVIRONMENT: live
API_HOST_NAME: https://notify-api-alt.app.cloud.gov API_HOST_NAME: https://notifications-api.app.cloud.gov
ADMIN_BASE_URL: https://notify-admin-alt.app.cloud.gov ADMIN_BASE_URL: https://notifications-admin.app.cloud.gov
NOTIFICATION_QUEUE_PREFIX: notify_alt_
REDIS_ENABLED: true
STATSD_HOST: localhost STATSD_HOST: localhost
INTERNAL_CLIENT_API_KEYS: '{"notify-admin":["((ADMIN_CLIENT_SECRET))"]}'
# Credentials variables # Credentials variables
INTERNAL_CLIENT_API_KEYS: '{"notify-admin":["((ADMIN_CLIENT_SECRET))"]}'
ADMIN_CLIENT_SECRET: ((ADMIN_CLIENT_SECRET)) ADMIN_CLIENT_SECRET: ((ADMIN_CLIENT_SECRET))
DANGEROUS_SALT: ((DANGEROUS_SALT)) DANGEROUS_SALT: ((DANGEROUS_SALT))
SECRET_KEY: ((SECRET_KEY)) SECRET_KEY: ((SECRET_KEY))

View File

@@ -25,7 +25,7 @@ lxml==4.9.1
defusedxml==0.7.1 defusedxml==0.7.1
Werkzeug==2.1.1 Werkzeug==2.1.1
python-dotenv==0.20.0 python-dotenv==0.20.0
oscrypto oscrypto==1.3.0
notifications-python-client==6.3.0 notifications-python-client==6.3.0

View File

@@ -71,7 +71,7 @@ def test_notifications_ses_400_with_certificate(client):
def test_notifications_ses_200_autoconfirms_subscription(client, mocker): def test_notifications_ses_200_autoconfirms_subscription(client, mocker):
mocker.patch("app.celery.process_ses_receipts_tasks.valid_sns_message", return_value=True) mocker.patch("app.celery.process_ses_receipts_tasks.validate_sns_message", return_value=True)
requests_mock = mocker.patch("requests.get") requests_mock = mocker.patch("requests.get")
data = json.dumps({"Type": "SubscriptionConfirmation", "SubscribeURL": "https://foo"}) data = json.dumps({"Type": "SubscriptionConfirmation", "SubscribeURL": "https://foo"})
response = client.post( response = client.post(
@@ -85,7 +85,7 @@ def test_notifications_ses_200_autoconfirms_subscription(client, mocker):
def test_notifications_ses_200_call_process_task(client, mocker): def test_notifications_ses_200_call_process_task(client, mocker):
mocker.patch("app.celery.process_ses_receipts_tasks.valid_sns_message", return_value=True) mocker.patch("app.celery.process_ses_receipts_tasks.validate_sns_message", return_value=True)
process_mock = mocker.patch("app.celery.process_ses_receipts_tasks.process_ses_results.apply_async") process_mock = mocker.patch("app.celery.process_ses_receipts_tasks.process_ses_results.apply_async")
data = {"Type": "Notification", "foo": "bar"} data = {"Type": "Notification", "foo": "bar"}
json_data = json.dumps(data) json_data = json.dumps(data)