Commit Graph

3990 Commits

Author SHA1 Message Date
Ben Thorner
cd1fe0640c Improve coverage of suspend service tests
Previously these only tested with a Platform Admin user, but service
admins can suspend a service too. I've rewritten the tests to match
the 'archive_service' ones, which use the client_request fixture to
make changing the user easier.

Note that the return value of the service API client wasn't used for
anything, so it's safe to remove it from the mock.
2021-07-08 17:17:23 +01:00
Ben Thorner
301908460a Audit when a service is archived ("deleted")
This is similar to the previous commit. I've used the term 'archive'
to match the rest of the code - services aren't ever truly deleted.
2021-07-08 17:17:22 +01:00
Ben Thorner
bb4c86008a Add audit event for suspending a service
This is particularly important for broadcast services, where a rogue
service or platform admin could launch a DoS attack by suspending a
service at a critical moment when it needs to send alerts.
2021-07-08 15:29:52 +01:00
Ben Thorner
e72a260e13 Merge pull request #3947 from alphagov/allow-ccs
Allow other users to use security keys
2021-07-08 11:53:03 +01:00
Chris Hill-Scott
ceca92c84e Merge pull request #3952 from alphagov/emergency-alerts-content-review
Emergency alerts content review
2021-07-08 09:33:54 +01:00
Ben Thorner
4c2915ce86 Use API flag to give users access to WebAuthn
This allows us to roll out the feature to other users. Note that
the flag is also "True" if the user has "webauthn_auth" as their
auth type, so this is compatible with the more fine-grained check
we have on the authentication parts of the feature. We could do a
more explicit "can_use_webauthn or webauthn_auth" check here, but
the idea is that we'll be able to get rid of this flag eventually,
so I've optimised for brevity instead.

I've modified a couple of the unhappy-path tests to make it more
explicit that the flag is false, since it can be true for Platform
Admins and "normal users" alike.
2021-07-07 15:04:48 +01:00
Ben Thorner
1a4dd04ab1 Add missing tests for authentication radios
Previously we only had one test for SMS auth not being disabled on
the invite version of the form. This modifies that test to fully
check what's displayed, and adds two more for the edit version of
the form.
2021-07-07 15:04:47 +01:00
Ben Thorner
a1b4ccc246 Prevent auth type changing for any WebAuthn user
Previously we applied this restriction to Platform Admins, on the
assumption that all of them use a security key to log in. Rather
than making that assumption, we can explicitly check their login
method, which also supports rolling out the feature to more users.
2021-07-07 15:04:43 +01:00
Ben Thorner
fab58b4e4e Merge pull request #3950 from alphagov/clarify-sms-prefix
Explain about text message prefixes when editing
2021-07-07 12:35:23 +01:00
Chris Hill-Scott
2accf8434a Remove false precision from area estimates
We give estimates of the area for those who can’t see the map. These
estimates were needlessly precise, gave a false sense of accuracy and
were causing intermittent test failures between different environments.

This commit rounds them in the same way that we round the count of
phones.
2021-07-06 17:00:51 +01:00
Chris Hill-Scott
e4ca78634d Bump utils to bring in new polygon simplification
We’ve changed our simplification a bit so:
- polygons have slightly more points (see https://github.com/alphagov/notifications-utils/pull/873)
- the individual points have less precision (see https://github.com/alphagov/notifications-utils/pull/872)

Overall this reduces the size of the data we’re storing from 74MB to
63MB, and should make any pages where we are rendering lots of
coordinates load a bit quicker.
2021-07-06 17:00:50 +01:00
Katie Smith
59ed8b0f8b Update tests for new content 2021-07-06 16:42:54 +01:00
Ben Thorner
b4bd978289 Update content following review with Karl 2021-07-06 16:30:24 +01:00
Leo Hemsted
416b5c3e26 Merge pull request #3926 from alphagov/sign-in-bug
ensure user details are always in the session after entering password
2021-07-06 11:56:24 +01:00
karlchillmaid
d90d0d632e Change 'cancel' to 'reject' 2021-07-05 17:21:57 +01:00
karlchillmaid
18800a9cec Change 'withdraw' to 'discard' 2021-07-05 17:11:26 +01:00
karlchillmaid
60d8734f79 Replace use of 'broadcast' 2021-07-05 16:39:48 +01:00
Chris Hill-Scott
960d2b8bf1 Merge pull request #3954 from alphagov/no-empty-state-choose-areas
Remove empty state step before choosing areas
2021-07-05 16:01:49 +01:00
Chris Hill-Scott
2cfd22b20c Remove empty state step before choosing areas
We had some kind of idea that having this empty page would introduce the
idea of choosing areas and reinforce that you are building up a list of
areas.

But since the journey is now so simple with the button to create an
alert directly on the dashboard page, maybe people don’t need this extra
orientation.
2021-07-05 14:33:02 +01:00
karlchillmaid
a8bd65254e Change previous to past 2021-07-05 13:49:36 +01:00
Leo Hemsted
74b5d8f3cd add test for when trying to sign in as another invited user 2021-07-02 18:11:53 +01:00
Ben Thorner
2355d1e0e6 Explain about text message prefixes when editing
Previously this lead to 2 support tickets because the user didn't
understand why their messages was being split into 2 fragments. We
tried modifying the message about charges, but that made it more
complicated. Adding a hint should hopefully be enough.
2021-07-02 16:25:45 +01:00
Chris Hill-Scott
5a378fe51f Use CustomBroadcastArea to estimate phones in bleed area
Our current assumption is that the bleed area has the same population
density as the broadcast area.

This is particularly naïve when:
- the bleed area overlaps the sea – no-one lives in the sea
- the broadcast area is a village and the bleed area is the surrounding
  countryside
- the broadcast area is adjacent to a densely populated area like a city

We can be smarter about this now that we have a way of determining the
number of phones in an arbitrary area, based on the known areas that we
have population data about.

Calculating the population in an overlap is a slightly more intensive
calculation. So we only doing it for areas which are smaller enough that
it doesn’t slow things down too much. For larger areas we still use the
more naïve algorithm.
2021-07-02 10:36:25 +01:00
Ben Thorner
1f33924ceb Send upload_id to Template Preview for logging
This means we can include the anonymous ID for the file in the log
we have about Type3 fonts [1]. Currently, we have no way of tracing
manually uploaded files with this potential defect.

[1]: https://github.com/alphagov/notifications-template-preview/pull/557
2021-07-01 12:09:47 +01:00
Ben Thorner
43afcd1064 Remove redundant restrictions for WebAuthn feature
Since the register and authentication APIs work in pairs, we can
just put the restrictions on the "begin" API. We weren't testing
the restrictions on the "complete" API anyway.

For authentication, it's also enough to check if the user has
WebAuthn as their auth type, as it's not a big deal if a user
continues to login with a security key indefinitely.
2021-06-30 16:19:12 +01:00
Ben Thorner
7fafc18fb3 Remove unnecessary restriction for 2FA WebAuthn
It should be enough to check the user has it set as their auth type.
Even if a user is no longer eligible to register a security key, it
should still be OK for them to continue using the feature.
2021-06-30 14:54:20 +01:00
Leo Hemsted
7b3751240c ensure user details are always in the session after entering password
We signal that we're mid-way through the sign-in flow by adding a
`user_details` dict to the session.

previously, we'd only put a user's details in the session in `User.sign_in`,
just before sending any 2fa prompt and redirecting to the two factor
pages.

However, we found a bug where a user with no session (eg, using a fresh
browser) tried to log in, but they had never clicked the link to
validate their email address when registering. Their user's state was
still in "pending", so we redirected to `main.resend_email_verification`
as intended - however, they didn't have anything in the session and the
resend page expected to get the email address to resend to out of that.

To be safe, as soon as we've confirmed the user has entered their
password correctly, lets save the session data at that point. That way
any redirects will be fine.
2021-06-29 18:13:25 +01:00
Leo Hemsted
71613dd942 remove old /two-factor endpoint and update test names
we redirect people to `/two-factor-sms` since #26ad20719
2021-06-29 16:19:24 +01:00
Leo Hemsted
c439cafd37 always create platform admin users with webauthn in tests 2021-06-29 16:19:22 +01:00
Leo Hemsted
126f9cf6be fix bug stopping editing of permissions of webauthn platform admins
We hide the radio field in the HTML for platform admins, as we don't
want anyone to be able to change their auth type. However, when the form
is validated, the form has a field called login_authentication that it
expects a value for. It silently fails as it complains that when the
user POSTed they didn't select a value for that radio field, but the
error message is on the radio fields that don't get displayed to the
user so they'd never know.

Fixing this is actually pretty hard.

We use this form in two places, one where we have a user to edit, one
where we are creating an invite from scratch. So sometimes we don't know
about a user's auth type. In addition, radio buttons are mandatory by
design, but now sometimes we don't just want to make it optional but
explicitly ignore the value being passed in? To solve this, remove the
field entirely from the form if the user is a platform admin. This means
that if the code in manage_users.py tries to access the
login_authentication value from the form, it'll error, but I think
that's okay to leave for now given we concede that this isn't a perfect
final solution.

The tests didn't flag this previously as they tried to set from sms_auth
(the default for `platform_admin_user`) TO email_auth or sms_auth. Also,
the diagnosis of this bug was confounded further by the fact that
`mock_get_users_by_service` sets what is returned by the API - the
service model then takes the IDs out of that response and calls
`User.get_user_by_id` for the matching ID (as in, the code only uses
get_users_by_service to ensure the user belongs to that service). This
means that we accidentally set the form editing the current user, as
when we log in we set `get_user_by_id` to return the user of our choice
2021-06-29 15:53:48 +01:00
Leo Hemsted
92b6885224 ensure webauthn page aborts if user isn't allowed 2021-06-29 15:53:48 +01:00
Rebecca Law
5534ecb5a4 Merge pull request #3939 from alphagov/check-daily-limit-for-csv-uploads
Check the daily limit get the daily notification_count from redis.
2021-06-29 14:41:22 +01:00
Rebecca Law
77c2aa9fd6 Stop passing in today_only for the get_service_statistics method.
We now only ever call it with False.
To remove it from the api call will require a change in the API so will do that at another time.
2021-06-29 07:33:40 +01:00
Ben Thorner
1806ff2721 DRY up fixtures to use their equivalent factory
It's unclear if we really need the factory functions, but for now
this avoids the fixture and the factory diverging.
2021-06-28 17:52:11 +01:00
Ben Thorner
91b28879f7 DRY up fixtures for service one users / admins
Note that, while it makes sense for most service one users to also
be in the organisation, this doesn't apply to caseworkers.
2021-06-28 17:45:19 +01:00
Ben Thorner
81cdc31e80 Refactor creating user fixture into one function
This removes *a lot* of duplication, in advance of adding another
fixture for a user with a WebAuthn auth type.
2021-06-28 17:25:36 +01:00
Ben Thorner
e7c1ce1869 Merge pull request #3938 from alphagov/save-original-pdf-uploads
Backup original precompiled uploads to S3
2021-06-24 12:43:40 +01:00
Ben Thorner
b3f48c1a84 Backup original precompiled uploads to S3
This continues the work from Template Preview [1], so that we have
a complete store of original PDFs to use for testing changes to it.

Previously we did store some originals, but these were only invalid
PDFs that had failed sanitisation; for valid PDFs, the "transient"
bucket only contains the sanitised versions, which the API deletes
/ moves when the notification is sent [2].

Since the notification is only created at a later stage [3], there's
no easy way to get the final name of the PDF we send to DVLA. Instead,
we use the "upload_id", which eventually becomes the notification ID
[4]. This should be enough to trace the file for specific debugging.

Note that we only want to store original PDFs if they're valid (and
virus free!), since there's no point testing changes with bad data.

[1]: https://github.com/alphagov/notifications-template-preview/pull/545
[2]: c44ec57c17/app/service/send_notification.py (L212)
[3]: 7930a53a58/app/main/views/uploads.py (L362)
[4]: 7930a53a58/app/main/views/uploads.py (L373)
2021-06-24 12:21:05 +01:00
Katie Smith
1862cd0223 Update data format for platform admin report
The format of dates returned from API for the "Monthly notification
statuses for live services" report has changed, so we no longer need to
format the dates here.

https://github.com/alphagov/notifications-api/pull/3279
2021-06-23 16:14:58 +01:00
Rebecca Law
44f02f2e30 To check the daily limit get the daily notification_count from redis.
The daily limit cache is set by the api when a notification is created. There is one cache key per service per day and it expires after 24 hours.
2021-06-23 15:56:05 +01:00
Pea Tyczynska
7930a53a58 Merge pull request #3935 from alphagov/more-detailed-request-go-live-ticket
Make a label more descriptive in request-to-go-live ticket
2021-06-18 10:01:50 +01:00
Pea Tyczynska
d1dc1aec6c Make a label more descriptive in request-to-go-live ticket
We have a label saying "other live services". This label means
other live services for a user making the request, but it could
also be interpreted as other live services for an organisation.

Hence, we are changing the label to "other live services for
that user" to avoid confusion
2021-06-17 17:53:28 +01:00
Ben Thorner
562245d9cd Merge pull request #3931 from alphagov/refactor-email-verify-webauthn
Refactor email revalidation check
2021-06-16 16:24:41 +01:00
Ben Thorner
9177ffa65a Clarify variable name in pagination tests
We should avoid using abbreviations, as they aren't universally
understood i.e. they're not worth the small saving in typing.
2021-06-16 16:08:38 +01:00
Rebecca Law
38edcae68a Merge pull request #3924 from alphagov/letter-permanent-failure
Permanent failure message for letters
2021-06-15 13:43:26 +01:00
Rebecca Law
d7364eb21a Add permanent-failure to the format_notification_status formatter so the status appears on the activity page. 2021-06-15 13:08:07 +01:00
Ben Thorner
1c4a903b65 Move tests to match the module they are in
Previously some of the tests for code in the "formatters" module
were in tests for the "utils" module. This moves them to where
they should be. While two of these methods are probably more utils
than formatters, I'd like to postpone a refactor of that module
for now, and focus on slimming down test for utils/__init__.py.
2021-06-14 12:52:57 +01:00
Ben Thorner
c17d438de8 DRY-up email revalidation check
Previously this was duplicated between the "two_factor" and the
"webauthn" views, and required more test setup. This DRYs up the
check and tests it once, using mocks to simplify the view tests.

As part of DRYing up the check into a util module, I've also moved
the "is_less_than_days_ago" function it uses.
2021-06-14 12:52:54 +01:00
Ben Thorner
edb0b8214d Move pagination utils into own module
This continues the pattern established in [1], just to chip away a
bit more at the random collection of stuff in utils/__init__.py.

[1]: https://github.com/alphagov/notifications-admin/pull/3923
2021-06-14 11:00:05 +01:00
Ben Thorner
44cf2b16b5 Merge pull request #3923 from alphagov/refactor-email-verify
Split out utils code into separate modules
2021-06-14 10:28:28 +01:00