Commit Graph

6938 Commits

Author SHA1 Message Date
David McDonald
148a5ab456 Refactor dates being passed around
I believe this way is nicer to read, we don't have to change between
datetimes and strings and back.
2020-02-21 15:01:19 +00:00
David McDonald
6226d9e122 Don't send test letters to dvla to print 2020-02-21 15:01:19 +00:00
David McDonald
7578e01b3b Test cases explicitely
In previous tests we check that we can deal with files that end in `pdf`
in various forms of upper and lowercase. I've moved the testing of this
behaviour into it's own test so that's explicit and not just implied
that we care about behaviour on the casing of filenames.

Note however that s3 is case sensitive and we upload all our files in
upper case so technically we'd never expect to see a file ending in
`pdf`. I've updated some of our test data to reflect this but didn't
bother doing it everywhere. I've left the test in anyway but it could be
argued that is is redundant as we don't ever expect to see that case
anyway.
2020-02-21 15:01:19 +00:00
David McDonald
5c5eb8a96a Remove unneeded check that notification is in created state
We instead rely on the fact that only files being passed into this
function we already know are in the created state
2020-02-21 15:01:19 +00:00
David McDonald
dc9bf757a8 Change which letters we want to be sent to look at all days
Previously, when running the `collate_letter_pdfs_for_day` task, we
would only send letters that were created between 5:30pm yesterday and
5:30 today.

Now we send letters that were created before 5:30pm today and that are
still waiting to be sent. This will help us automatically attempt to
send letters that may have fallen through the gaps and not been sent the
previous day when they should have been.

Previously we solved the problem of letters that had fallen the gap by
having to run the task with a date parameter for example
`collate_letter_pdfs_for_day('2020-02-18'). We no longer need this date
parameter as we will always look back across previous days too for
letters that still need sending.

Note, we have to change from using the pagination `list_objects_v2` to
instead getting each individual notification from s3. We reduce load by
using `HEAD` rather than `GET` but this will still greatly increase the
number of API calls. We acknowledge there will be a small cost to this,
say 50p for 5000 letters and think this is tolerable. Boto3 also handles
retries itself so if when making one of the many HEAD requests, there is
a networking blip then it should be retried automatically for us.
2020-02-21 15:01:19 +00:00
David McDonald
7a0dca61da Remove unused argument 2020-02-21 15:01:19 +00:00
David McDonald
bcc0fc433d Merge pull request #2722 from alphagov/fix-json
Transform list to json so it can be used read by json.loads
2020-02-21 13:51:42 +00:00
David McDonald
a13b17a7c9 Transform list to json so it can be used read by json.loads 2020-02-21 13:41:08 +00:00
David McDonald
d60c4e46d1 Merge pull request #2721 from alphagov/rotate-keys
Allow multiple keys for the `ADMIN_CLIENT_SECRET`
2020-02-21 13:23:33 +00:00
David McDonald
2dc5550159 Change variable name to make more descriptive
Also remove unnecessary if statement
Also add manifest change to make sure relevant environment variables
makes it into the app
2020-02-20 15:48:15 +00:00
David McDonald
2967fdce08 Make test more accurate
So we are really testing the functionality the test says it is, rather
than potentially being misled by using an incorrect key as the secret
2020-02-20 13:49:31 +00:00
David McDonald
7246306447 Support multiple secrets for ADMIN_CLIENT_SECRETS
This will allow us to accept two different ones and therefore allow us
to rotate the secret that the admin client is sending to the API

Due to how the notifications-python-client throws exceptions, we run
into exactly the same issue with not being able to distinguish if a
`TokenDecodeError` is thrown because the token was encrypted with a
different secret key or if because there was a different error when
decoding. I've copied the TODO from `requires_auth` as this is exactly
the same issue.

I've also added a test case for functionality that was missing for an
out of date admin token (old IAT).
2020-02-20 13:47:39 +00:00
David McDonald
52d3df49d4 Make ADMIN_CLIENT_SECRET a list of a single secret
And support this change across our code. Note, this is a halfway step
where it is not a list rather than a string but still only supports a
single secret, ie one item in the list.
2020-02-20 13:43:10 +00:00
Leo Hemsted
9eefb54d27 Merge pull request #2720 from alphagov/remove-error-log
remove error log from dao_utils
2020-02-20 13:33:13 +00:00
Leo Hemsted
11fb9da32c remove error log from dao_utils
we don't need it here - as exceptions are re-raised, they will be logged
additionally by error handlers further up. All this exception logger
tells us is that service names are already in use, which isn't something
we're really interested in.
2020-02-20 12:09:18 +00:00
Rebecca Law
f7f6be56c7 Merge pull request #2715 from alphagov/add-stats
Add statsd annotations for the fact table queries.
2020-02-19 09:51:53 +00:00
Pea M. Tyczynska
5cd27aee2c Merge pull request #2716 from alphagov/fix-reset-password
Fix reset password flow
2020-02-18 15:09:16 +00:00
Pea Tyczynska
e794300ff3 Fix reset password flow
It was broken because of unhappy marshmallow schema and flag name
mismatch
2020-02-18 14:59:46 +00:00
Rebecca Law
291c6d6dc9 Add statsd annotations for the fact table queries. 2020-02-18 14:33:17 +00:00
David McDonald
ce253a990b Merge pull request #2701 from alphagov/jwt-nightmare
Catch uncaught JWT exceptions
2020-02-14 14:34:11 +00:00
David McDonald
f861da1843 Improve text for error messages 2020-02-14 14:15:41 +00:00
David McDonald
7a019df5a2 Catch previously uncaught jwt exceptions added in python client 5.5.0
This fixes the test in the previous commit and means we will catch other
unexpected jwt errors which are now raised as `TokenError`s and raise an
AuthError based on this.

This will stop us serving 5xx to users when we don't catch an exception.

Also runs make freeze-requirements
2020-02-14 14:14:13 +00:00
David McDonald
ba21d04080 Add test case for uncaught jwt exception 2020-02-14 14:10:12 +00:00
Leo Hemsted
c71de8d62a Merge pull request #2714 from alphagov/docs-in-the-db
Docs in the db
2020-02-13 14:55:39 +00:00
Leo Hemsted
ef8fe35fa0 Merge pull request #2707 from alphagov/pyup-scheduled-update-2020-02-05
Scheduled weekly dependency update for week 05
2020-02-13 14:13:10 +00:00
Leo Hemsted
a97948574a remove unused pytest flags 2020-02-13 12:52:12 +00:00
Leo Hemsted
9e84fb2a00 pin marshmallow to <v3
also, fix pyup comment syntax. descriptions in pyup comments need to
have an additional # prefix
2020-02-13 12:52:12 +00:00
pyup-bot
bbeb66398d pyup updates
Update cffi from 1.13.1 to 1.13.2
Update jsonschema from 3.1.1 to 3.2.0
Update marshmallow-sqlalchemy from 0.19.0 to 0.21.0
Update marshmallow from 2.20.2 to 3.4.0
Update sqlalchemy from 1.3.10 to 1.3.13
Update notifications-python-client from 5.4.1 to 5.5.1
2020-02-13 12:49:12 +00:00
Leo Hemsted
1694395b17 record document count when processing api notifications
if someone doesn't send any documents, set the value to None. If it's
not specified, it defaults to None anyway.
2020-02-13 12:43:06 +00:00
Leo Hemsted
743acf71e4 add nullable document_count field to Notifications
intention is for this to be null, 1, or many, based on how many
documents were linked to within the message. nullable column, so that it
doesn't require a lengthy access exclusive lock on the table when
creating.
2020-02-13 12:42:53 +00:00
David McDonald
fe19aef441 Merge pull request #2712 from alphagov/boto
use original `boto`
2020-02-13 11:51:10 +00:00
David McDonald
5a3d2e3162 Use the original version of boto
We aren't aware of any reason we need to use our fork of boto anymore.
We therefore swap to use `celery[sqs]` which brings in the original
version of boto and we can remove our use of the fork.

This has been tested by running the celery app and seeing it connect to
sqs and grab messages off a queue.
2020-02-12 15:30:02 +00:00
David McDonald
3dcac18849 Use correct exception for boto3
We use boto3 for our interaction with s3. Therefore if an expection is
thrown it will be thrown from the botocore library (which boto3 is built
on top of).

I have copied
app/aws/s3.py::file_exists for an example of this exception catching.
2020-02-12 15:28:46 +00:00
Rebecca Law
755c47c0c1 Merge pull request #2711 from alphagov/remove-unused-methods
Remove unused methods.
2020-02-11 16:58:05 +00:00
Rebecca Law
8445775be0 Remove unused methods.
A new endpoint to return the last date a template was used which means the old endpoint can be removed.
2020-02-07 15:50:54 +00:00
Pea M. Tyczynska
9cd433349c Merge pull request #2706 from alphagov/change-when-we-validate-email-access
Validate email access based on code_type and not auth_type
2020-02-06 14:31:08 +00:00
David McDonald
4d719e8f9d Merge pull request #2709 from alphagov/delete-old-task
Remove task that no longer runs
2020-02-06 13:11:12 +00:00
Rebecca Law
865e06e1a9 Merge pull request #2710 from alphagov/fix-last-used-bug
Fix None type error in last-used endpoint.
2020-02-06 11:51:21 +00:00
Rebecca Law
09f798ea14 Fix None type error in last-used endpoint. 2020-02-06 11:39:40 +00:00
David McDonald
a14d5f0225 Remove task that no longer runs
We no longer puts files in these s3 buckets (and have in fact deleted
the buckets) therefore this task is redundant and can be removed.
2020-02-06 10:57:43 +00:00
Rebecca Law
32082521ee Merge pull request #2708 from alphagov/change-last-used-query
Added a new endpoint to return the last used date for a template.
2020-02-06 10:02:26 +00:00
Rebecca Law
dec42b06cc Simplify the code in the query.
The date in the notifications table should always be the most recent date for the template.
Removed the template_type param for the query as well.
Simplified the tests.
2020-02-05 16:43:17 +00:00
Rebecca Law
3a32c35dd2 Added a new endpoint to return the last used date for a template.
The existing endpoint returned a whole notification for the last time the template was used. But this only takes into account data in the last week. This new methods allows us to be specific about when the template was last used if ever but looking into the ft_notification_status table as well.
2020-02-05 13:03:54 +00:00
Pea Tyczynska
79c456e60c Format email_access_validated_at when serializing
This is to bring it in line with other serialized dates in User
model, like logged_in_at and password_changed_at.

Also get rid of check if password_changed_at has value, as
it is a non-nullable column, so it needs to always have value.

Also set a default value for email_access_validated_at, to bring
it in line with other non-nullable columns.
2020-02-04 16:45:09 +00:00
Leo Hemsted
f4b137c658 Merge pull request #2666 from alphagov/gunicorn-bump
bump gunicorn to v20
2020-02-04 14:45:05 +00:00
Leo Hemsted
8d837eff0e bump gunicorn to v20
v20 brings in a host of changes, including a fix for
https://github.com/benoitc/gunicorn/issues/1847, which was stopping us
upgrading before
2020-02-04 14:21:56 +00:00
Pea Tyczynska
0132d76c16 Validate email access based on code_type anot auth_type
when verifying the code is correct. This way if user has sms_auth
and we send them verification code to validate their email access,
and they click the link in the email, their access will be validated
correctly.
2020-01-31 17:19:24 +00:00
Pea M. Tyczynska
0f6e8c330d Merge pull request #2705 from alphagov/populate-email-access-validated-at
Populate email_access_validated_at_column and make it non-nullable
2020-01-31 14:09:58 +00:00
Pea Tyczynska
558edff597 Populate email_access_validated_at_column and make it non-nullable 2020-01-31 10:59:54 +00:00
Pea M. Tyczynska
8f31d6c7b4 Merge pull request #2704 from alphagov/fix_migration
Simplify the first migration, we will do execute statements later
2020-01-30 17:41:58 +00:00