Commit Graph

573 Commits

Author SHA1 Message Date
Katie Smith
a8d3b0952f Add MMG_INBOUND_SMS_AUTH config variable and auth check
Checks authentication header value on inbound SMS requests from
MMG  against a list of allowed API keys set in the application
config.

At the moment, we're only logging the attempts without aborting the
requests. Once this is rolled out to production and we've checked
the logs we'll switch on the aborts and add the tests for 401 and 403
responses.

This work has already been done for Firetext in a previous PR:
https://github.com/alphagov/notifications-api/pull/1409
2017-12-14 13:37:50 +00:00
venusbb
cef8d6e294 use callback queue 2017-12-13 11:55:08 +00:00
venusbb
1c1cdbdf7c Merge branch 'master' of https://github.com/alphagov/notifications-api into vb-callback-receipt-1 2017-12-05 10:49:05 +00:00
venusbb
5482ee4fe7 - wrap apply_async parameter notification_id in a str() argument
- check if service_callback_api exist before putting tasks on queue
- create_service_callback_api in tests before asserting if send_delivery_status_to_service has been called.
2017-12-04 17:58:38 +00:00
Leo Hemsted
88c878c83e don't hit the query to get daily msg stats if redis is disabled 2017-12-04 11:12:26 +00:00
venusbb
771ce9e2bc fixed code style 2017-12-01 22:24:53 +00:00
venusbb
096657799c Added send delivery status to SES callbacks 2017-12-01 21:13:01 +00:00
venusbb
a604fb82bb added sms delivery status callback 2017-12-01 21:11:56 +00:00
Richard Chapman
5f25d3162a Disable Redis for Staging added statsd for post methods
- Disable Redis as there is a current connection limit of 256 which
 could slow down the request if they are all used
 - Added statd to methods in the post to help spot any bottlenecks
2017-12-01 15:41:53 +00:00
Rebecca Law
8aa94af5d7 Stop populating the notification to sender mapping table when creating a notificaiton. 2017-11-29 16:47:23 +00:00
Leo Hemsted
28d5f9b87f flake8 - remove unused imports and ensure they're always at the top of the file 2017-11-28 14:28:01 +00:00
venusbb
3945007d24 add reply-to-text to user/rest persist notifications 2017-11-27 14:36:54 +00:00
venusbb
a97d946d2d Merge branch 'master' of https://github.com/alphagov/notifications-api into add-reply-to-notifications 2017-11-27 13:53:37 +00:00
Rebecca Law
530f2e7f6a Update invite user endpoint to set the reply_to_text on the notification.
Update v1 post notifications to set the reply_to_text on the notification.
2017-11-27 12:30:50 +00:00
Alexey Bezhan
1971d7d4b3 Merge pull request #1425 from alphagov/enable-firetext-inbound-sms-auth
Abort unauthenticated requests for Firetext inbound SMS
2017-11-27 10:45:34 +00:00
Rebecca Law
5450af661e Merge branch 'master' into add-reply-to-notifications 2017-11-27 10:40:02 +00:00
Rebecca Law
d779751bae Set reply_to_text for letter notifications posted to /notifications/letter 2017-11-24 16:17:25 +00:00
Alexey Bezhan
4d48421767 Abort unauthenticated requests for Firetext inbound SMS
Switches on authentication checks for Firetext inbound SMS callbacks.

This should only be released once Firetext callback URLs have been
updated with authentication details.
2017-11-23 17:17:37 +00:00
Rebecca Law
e0d0b2f4fd Merge branch 'add-reply-to-notifications' of github.com:alphagov/notifications-api into add-reply-to-notifications 2017-11-23 16:57:17 +00:00
Rebecca Law
75d99ea397 [WIP] 2017-11-23 16:01:05 +00:00
Leo Hemsted
f3d129b0d8 fix 500s when inbound msgs sent from alphanumerics rather than normal phone numbers 2017-11-23 15:22:18 +00:00
Rebecca Law
df2d3a95ae [WIP] 2017-11-23 14:55:49 +00:00
Alexey Bezhan
5e53d781e0 Add FIRETEXT_INBOUND_SMS_AUTH config variable and auth check
Checks authentication header value on inbound SMS requests from
Firetext against a list of allowed API keys set in the application
config.

At the moment, we're only logging the attempts without aborting the
requests. Once this is rolled out to production and we've checked
the logs we'll switch on the aborts and add the tests for 401 and 403
responses.
2017-11-22 09:54:42 +00:00
Venus Bailey
10f3bc24f0 Merge pull request #1404 from alphagov/vb-test-token
Inbound sms pre-implementation test 1
2017-11-20 09:30:50 +00:00
venusbb
d70fdbb5c2 no auth check 2017-11-17 15:57:41 +00:00
venusbb
12a99f9a7f Verify authorisation header being send 2017-11-17 14:36:28 +00:00
Leo Hemsted
d2154451e5 update research mode email callbacks to add process-ses-response task to queue
this involved:
* moving that task to callback_tasks to prevent circular imports
* updating the dummy research mode callbacks (with actual SNS messages from the
  ses simulator emails)
* refactoring tests
2017-11-17 13:41:45 +00:00
Leo Hemsted
890604990d remove unneccessary ses endpoint tests 2017-11-17 10:31:34 +00:00
Leo Hemsted
5855adf826 removed unused HTTP ses callback handler 2017-11-16 17:53:19 +00:00
Leo Hemsted
1f317b6717 log the bounce message from SES 2017-11-16 17:46:58 +00:00
Rebecca Law
fe6bafcfb2 Update the from number in the response of post notification. 2017-11-10 14:17:29 +00:00
Chris Hill-Scott
4761d852e9 Fix escaping in inbound text messages from MMG
One of our providers gives us messages with special characters escaped,
ie a newline comes through as `\n`, not a literal newline. We shouldn’t
be showing these backslashes to any of our users. We also have examples
of real inbound messages containing `👍` and `’`, so we should continue
to display these properly.

It’s a bit tricky, because the strings we get from this provider are a
mixture of escape sequences (eg `\n`) and unicode characters (eg `😨`).
So we have to first convert the unicode character `😨` into an escape
sequence, `\U0001f628` in this example. We do this by encoding with
the `raw_unicode_escape` codec:

> Latin-1 encoding with \uXXXX and \UXXXXXXXX for other code points.
> Existing backslashes are not escaped in any way. It is used in the
> Python pickle protocol.

– https://docs.python.org/3/library/codecs.html#text-encodings

Then we turn this back into a string using the `unicode_escape` codec,
which transforms all escape sequences into their literal representations
(eg `\U0001f628` becomes `😨` and `\n` becomes a newline).
2017-11-08 13:32:30 +00:00
Rebecca Law
168231f3ce Downgrade the error message to a warning. 2017-11-03 12:09:20 +00:00
Rebecca Law
efe0f3b99b Downgrade error to warning 2017-11-03 10:15:09 +00:00
Rebecca Law
f5e79302cd Remove NotificationStatistics
NotificationStatistics was added as a spike but didn't work out as expected. This is finally removing all that unused code.
I'll drop the table in the next PR
2017-11-01 15:02:50 +00:00
Rebecca Law
830619194e Renamed some tests.
Fix some imports.
Added test for a function
2017-11-01 11:01:20 +00:00
Rebecca Law
4eec11b633 Added an optional parameter in the form for POST /v2/notifications/sms and /service/<service_id>/send-notification to pass in the SMS sender id.
The send_sms_to_provider still needs to use the SMS sender being passed in to the POST.

As part of https://www.pivotaltracker.com/story/show/152106587
2017-10-30 13:36:49 +00:00
Richard Chapman
d6cff97b7b Review Changes
- Updated the retry and max_retries of the process_ses_results celery
task to be the same as other retry strategies in that file
- Provided a message with the 200 to be similar to how other responses
are handled
2017-10-26 12:23:19 +01:00
Richard Chapman
0494ef3ea7 Removed the HTTP error and arguments from notification_ses_callback.py
In preparation for moving the SNS notification to an SES queue remove
the HTTP errors codes and arguments as the method will now be run by
a celery task. Also made the callback http method return more generic
codes as this will be removed in the longer term.

- Removed errors and arguments returned from process_ses_response
- Updated tests
2017-10-26 12:23:19 +01:00
Athanasios Voutsadakis
3443dcea53 Temporary test fix
This should be removed when the SES endpoint is removed
2017-10-26 12:14:33 +01:00
Athanasios Voutsadakis
644b31ba75 Update tests 2017-10-26 12:14:33 +01:00
Athanasios Voutsadakis
892eaede13 We no longer have guaranteed access to a request context 2017-10-26 12:14:33 +01:00
Athanasios Voutsadakis
865cb6656e Allow for both an endpoint callback and SQS consumption 2017-10-26 12:14:33 +01:00
Chris Hill-Scott
5b3e77ba87 Make missing personalisation error consistent
In other places the text we use for this error message is "Missing personalisation: name, date, thing". See:
- 72b108b694/app/template/rest.py (L125)
- 717c0510a3/app/notifications/rest.py (L206)
- 05a179c6ef/app/v2/template/post_template.py (L38)

For some reason this part of the codebase says "Template missing personalisation: …". This is inconsistent, and also confusing because it’s the API call that’s missing the personalisation, not the template itself. 

This commit changes the error message to be consistent with the majority of the codebase, which uses the less confusing wording.
2017-10-23 14:41:49 +01:00
Rebecca Law
769a7a275b Insert a row for the mapping of notification to email_reply_to for one off notifications. 2017-10-11 16:23:31 +01:00
Richard Chapman
7974e59eb7 Changes after review. Updates to style and import order to be more consistent with other code.
Added clarification to an error message to give better debugging information.
Removed using dao_get_reply_to_by_service_id in tests to be more consistent with other code and use the test db functions or remove the need for a call altogether making the code less complex.
2017-10-05 16:50:18 +01:00
Richard Chapman
d2168b7985 Added the mapping between notification and reply to email to the database and persisted the mapping when the request is received by the end point. the end point also checks if the reply to email id exists and if not returns an error. Also added tests to test the functionality. 2017-10-05 16:50:17 +01:00
Richard Chapman
2fbe492d5c [2/10] Allow API calls to specify the reply address option (#1291)
* Added service_email_reply_to_id to the POST /v2/notifications/email and a test to test the validator

* Caught NoResultFound exception in check_service_email_reply_to_id as it was not being caught when there there was no valid service_id or reply_to_id. Fixed failing tests which were not passing due to the NoResultFound exception and added further tests to check for the good path through the code and an test to check for an invalid service_id

* Added service_email_reply_to_id to the POST /v2/notifications/email and a test to test the validator

* Caught NoResultFound exception in check_service_email_reply_to_id as it was not being caught when there there was no valid service_id or reply_to_id. Fixed failing tests which were not passing due to the NoResultFound exception and added further tests to check for the good path through the code and an test to check for an invalid service_id

* Fixed code style in validators.py to confirm with rules
Update the name of email_reply_to_id to conform better with other attributes in the schema and the resultant code in post_notifications.py
Fixed code style in test_validators.py to confirm with rules
Added tests to test_post_notifications.py to test the email_reply_to_id being present and being incorrect, it being optional is being tested by other tests.

* Added service_email_reply_to_id to the POST /v2/notifications/email and a test to test the validator

* Added service_email_reply_to_id to the POST /v2/notifications/email and a test to test the validator

* Caught NoResultFound exception in check_service_email_reply_to_id as it was not being caught when there there was no valid service_id or reply_to_id. Fixed failing tests which were not passing due to the NoResultFound exception and added further tests to check for the good path through the code and an test to check for an invalid service_id

* Caught NoResultFound exception in check_service_email_reply_to_id as it was not being caught when there there was no valid service_id or reply_to_id. Fixed failing tests which were not passing due to the NoResultFound exception and added further tests to check for the good path through the code and an test to check for an invalid service_id

* Fixed code style in validators.py to confirm with rules
Update the name of email_reply_to_id to conform better with other attributes in the schema and the resultant code in post_notifications.py
Fixed code style in test_validators.py to confirm with rules
Added tests to test_post_notifications.py to test the email_reply_to_id being present and being incorrect, it being optional is being tested by other tests.

* Minor update after manual merge to fix check style rule break in test_validators.py where a single space was introduced.

* Updates after code review. Moved the template from the exception message as it was not required and updated the error message to match the field name in the sschema for better debugging and error identification.

* Fixed test after update of exception message
2017-10-04 14:34:45 +01:00
Leo Hemsted
f3db920c71 remove jobs from letter api calls
we now no longer create a job. At the end of the post there is no
action, as we don't have any tasks to queue immediately - if it's a
real notification it'll get picked up in the evening scheduled task.

If it's a test notification, we create it with an initial status of
sending so that we can be sure it'll never get picked up - and then we
trigger the update-letter-notifications-to-sent-to-dvla task to sent
the sent-at/by.
2017-09-26 09:57:36 +01:00
Leo Hemsted
17ba8db97f remove jobs from letter api and make success/error ftp callback tasks
1. No longer create jobs when creating letters from api 🎉
2. Bulk update notifications based on the notification references after
   we send them to DVLA - either as success or as error
2017-09-26 09:57:35 +01:00