Commit Graph

11397 Commits

Author SHA1 Message Date
Ben Thorner
35507683ee Switch to jest.spyOn() for window.location
The previous comment was incorrect, so there's no need to use the
defineObject hack, or to populate the object beforehand.
2021-05-13 10:22:27 +01:00
Ben Thorner
aae01bf8e2 Switch to jest.spyOn for navigator.credentials
This follows the same approach as for window.fetch, using the Jest
before/afterAll() blocks to handle the idiosynchrosies of whether
the object/function is defined in the test environment.
2021-05-13 10:22:26 +01:00
Ben Thorner
9ee01a2567 Check for response.ok in fetch calls
It's possible for a call to fetch to trigger then "then" callback
even thought the response is an error [1]. We should test for both
scenarios, since they are handled differently. To avoid duplicating
the tests, I've used Jest's parameterisation feature [2].

[1]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
[2]: https://jestjs.io/docs/api#testeachtablename-fn-timeout
2021-05-13 10:22:26 +01:00
Ben Thorner
6948f5f003 Switch to window.fetch for AJAX calls
In response to [1]. Using window.fetch means we don't get console
logs on errors, so this simplifies the error handling, although we
need to account for some errors not being a standard error object,
such as the string we get by doing Promise.reject('error').

In making this change, I've also started addressing another comment
in the PR [2], so that we reset mocked objects after the tests.

This also switches the ordering of done(), so that it's the last
statement (in response to [3]).

In the next commit we'll check for 'response.ok', but I wanted to
keep this one simple, as it's quite a large change.

[1]: https://github.com/alphagov/notifications-admin/pull/3878#discussion_r631054187
[2]: https://github.com/alphagov/notifications-admin/pull/3878#discussion_r631060116
[3]: https://github.com/alphagov/notifications-admin/pull/3878#discussion_r631061628
2021-05-13 10:22:25 +01:00
Ben Thorner
957dba4356 Avoid registering the same authenticator twice
This passes existing credentials in the server response, to allow
the browser to prevent re-registering the same key for the same
user. Registering the same key multiple times doesn't seem to be
an issue technically; the user has likely got their keys mixed up.

- Chrome says "you don't need to register it again".
- Safari exits with an InvalidStateError.
- Firefox exits with a DOMException.
2021-05-13 10:22:24 +01:00
Ben Thorner
e2cf3e2c70 Support registering a new authenticator
This adds Yubico's FIDO2 library and two APIs for working with the
"navigator.credentials.create()" function in JavaScript. The GET
API uses the library to generate options for the "create()" function,
and the POST API decodes and verifies the resulting credential. While
the options and response are dict-like, CBOR is necessary to encode
some of the byte-level values, which can't be represented in JSON.

Much of the code here is based on the Yubico library example [1][2].

Implementation notes:

- There are definitely better ways to alert the user about failure, but
window.alert() will do for the time being. Using location.reload() is
also a bit jarring if the page scrolls, but not a major issue.

- Ideally we would use window.fetch() to do AJAX calls, but we don't
have a polyfill for this, and we use $.ajax() elsewhere [3]. We need
to do a few weird tricks [6] to stop jQuery trashing the data.

- The FIDO2 server doesn't serve web requests; it's just a "server" in
the sense of WebAuthn terminology. It lives in its own module, since it
needs to be initialised with the app / config.

- $.ajax returns a promise-like object. Although we've used ".fail()"
elsewhere [3], I couldn't find a stub object that supports it, so I've
gone for ".catch()", and used a Promise stub object in tests.

- WebAuthn only works over HTTPS, but there's an exception for "localhost"
[4].  However, the library is a bit too strict [5], so we have to disable
origin verification to avoid needing HTTPS for dev work.

[1]: c42d9628a4/examples/server/server.py
[2]: c42d9628a4/examples/server/static/register.html
[3]: 91453d3639/app/assets/javascripts/updateContent.js (L33)
[4]: https://stackoverflow.com/questions/55971593/navigator-credentials-is-null-on-local-server
[5]: c42d9628a4/fido2/rpid.py (L69)
[6]: https://stackoverflow.com/questions/12394622/does-jquery-ajax-or-load-allow-for-responsetype-arraybuffer
2021-05-13 10:22:23 +01:00
Ben Thorner
ebb82b2e80 Add page for security keys with stubbed data
This adds a new platform admin settings row, leading a page which
shows any existing keys and allows a new one to be registered. Until
the APIs for this are implemented, the user API client just returns
some stubbed data for manual testing.

This also includes a basic JavaScript module to do the main work of
registering a new authenticator, to be implemented in the next commits.

Some more minor notes:

- Setting the headings in the mapping_table is necessary to get the
horizontal rule along the top (to match the design).

- Setting caption to False in the mapping_table is necessary to stop
an extra margin appearing at the top.
2021-05-12 13:41:53 +01:00
Rebecca Law
e7d6eebdfe Merge pull request #3871 from alphagov/remove-training-mode-test-channels
Remove some of the option we have for broadcast services.
2021-05-06 15:05:29 +01:00
Rebecca Law
cf160c3ae1 Update labels
Use more suscinct labels for the service settings page
2021-05-06 07:29:21 +01:00
Rebecca Law
5495de0b3b Remove some of the option we have for broadcast services.
This is the first step in making the UI easier for setting the
options for a broadcast service. Here we remove the options for
"Training mode" test channels. When we create a broadcast message for a trail mode service it is marked as stubbed and does not create a broadcast event that is sent to a provider.

The label for the form and setting page have been updated to reflect the
change.
2021-05-05 14:04:51 +01:00
Ben Thorner
bfc55b45ca Merge pull request #3863 from alphagov/show-suspended
Show service suspension in breadcrumb
2021-04-28 14:59:56 +01:00
Ben Thorner
b43eb3a591 Show service suspension in breadcrumb
Previously there was no indication that a service was suspended.
While this could also be shown for archived/deleted services, the
meaning is similar enough that it makes sense there too - the name
of the archived service should distinguish it as being archived.
2021-04-27 11:15:13 +01:00
karlchillmaid
c7840496d3 Merge pull request #3866 from alphagov/fix-typo
Fix apostrophe
2021-04-26 14:00:12 +01:00
karlchillmaid
487452b390 Fix apostrophe 2021-04-26 13:38:11 +01:00
Rebecca Law
7563cd79b8 Merge pull request #3865 from alphagov/update-allowances
Update pricing information on the features page
2021-04-22 13:36:17 +01:00
karlchillmaid
e78c10fc40 Remove details of allowance and pricing 2021-04-22 13:27:22 +01:00
karlchillmaid
029a6ec3b5 Update text message cost and rates
Update text message cost and rates on the features page
2021-04-22 13:25:40 +01:00
Pea Tyczynska
c55cc4574e Merge pull request #3854 from alphagov/admin-cancel-broadcast
Allow platform admins to cancel broadcasts.
2021-04-21 12:52:14 +01:00
karlchillmaid
bda66245a8 Merge pull request #3864 from alphagov/update-email-status-content
Update email status description
2021-04-20 17:40:04 +01:00
karlchillmaid
652f3f8065 Update {{ text_field(charge | safe) }} 2021-04-20 17:31:08 +01:00
karlchillmaid
94d71ca330 Update app/templates/views/message-status.html
Co-authored-by: Katie Smith <klssmith@users.noreply.github.com>
2021-04-20 17:30:03 +01:00
Pea Tyczynska
d77ec8a5ca Test that user without permission cannot reject broadcast 2021-04-20 17:27:56 +01:00
Pea Tyczynska
28378fdd3d Test that user without permission cannot accept broadcast
Also fix incorrect docstring.
2021-04-20 17:27:56 +01:00
Pea Tyczynska
6999d3bceb Refactor platform admin user fixtures
To make the code more DRY
2021-04-20 17:27:56 +01:00
Pea Tyczynska
0c0d9dd72f Admins won't see buttons for broadcast actions they can't do
These actions are creating, accepting and rejecting broadcasts.
2021-04-20 17:27:56 +01:00
Pea Tyczynska
002dd7485d Allow platform admins to cancel broadcasts.
Do not allow platform admins to:
- create broadcasts
- approve broadcasts
- reject broadcasts

that is, unless they have a send_messages permission
for a given service.

This is so platform admins have the minimum permissions necessary
to cancel a broadcast that might have been sent out accidentally.
2021-04-20 17:27:55 +01:00
karlchillmaid
6782f6770b Fix error 2021-04-20 16:41:51 +01:00
karlchillmaid
0fe60c3bd8 Update content 2021-04-20 15:51:12 +01:00
karlchillmaid
77f17db9dc Update email status description
Update email status description for ‘Inbox not accepting messages right now’
2021-04-20 15:46:16 +01:00
Rebecca Law
007fa5fa19 Merge pull request #3855 from alphagov/set-annual_billing-in-the-api
Let the API handle setting the default free allowance.
2021-04-20 07:17:57 +01:00
Rebecca Law
0ffcdf692c Merge pull request #3861 from alphagov/dont-add-sender-id-for-letter-jobs
If the job is for letters do not add the sender_id.
2021-04-20 07:17:41 +01:00
Rebecca Law
ac0b8ed95c If the job is for letters do not add the sender_id.
How this happens: a user starts to send a letter job, then in another tab starts a SMS
or email job, the sender_id is set in the session. Then the user goes
back to the letter job tab and creates the job. The sender_id is set in
the metadata of the csv file, and causes an exception when trying to persist
the letter notification.

This PR adds a check to ensure the sender_id is not set for letter jobs.

This will catch a small use case where the user has multiple tabs open
and has started sending an SMS or email job, then tries to send a letter
job.
2021-04-15 13:51:48 +01:00
David McDonald
2871d4cb04 Merge pull request #3858 from alphagov/pyup-scheduled-update-2021-04-12
Scheduled weekly dependency update for week 15
2021-04-14 17:41:09 +01:00
David McDonald
8a930c0ab6 make freeze requirements 2021-04-14 17:28:24 +01:00
Chris Hill-Scott
46d0e73e99 Freeze requirements 2021-04-14 17:24:31 +01:00
pyup-bot
ce2b83cab2 Update xlrd from 1.2.0 to 2.0.1 2021-04-14 17:24:30 +01:00
pyup-bot
5c31d3bbf4 Update prometheus-client from 0.9.0 to 0.10.1 2021-04-14 17:24:29 +01:00
pyup-bot
e3ad749131 Update phonenumbers from 8.12.20 to 8.12.21 2021-04-14 17:24:29 +01:00
pyup-bot
b1fe29f8e8 Update idna from 2.10 to 3.1 2021-04-14 17:24:28 +01:00
pyup-bot
902667021f Update docutils from 0.15.2 to 0.17 2021-04-14 17:24:27 +01:00
pyup-bot
277f80a811 Update dnspython from 1.16.0 to 2.1.0 2021-04-14 17:24:26 +01:00
pyup-bot
3354cd4aa4 Update colorama from 0.4.3 to 0.4.4 2021-04-14 17:24:25 +01:00
pyup-bot
0864d560e5 Update botocore from 1.20.44 to 1.20.49 2021-04-14 17:24:24 +01:00
pyup-bot
f22ea11e11 Update boto3 from 1.17.44 to 1.17.49 2021-04-14 17:24:23 +01:00
pyup-bot
60ac229983 Update awscli from 1.19.44 to 1.19.49 2021-04-14 17:24:22 +01:00
pyup-bot
64d103dfa8 Update humanize from 3.3.0 to 3.4.0 2021-04-14 17:24:21 +01:00
pyup-bot
dea6a4dbe9 Update humanize from 3.3.0 to 3.4.0 2021-04-14 17:24:20 +01:00
Chris Hill-Scott
00f9df7606 Merge pull request #3860 from alphagov/search-templates-by-id
Allow users of the API to search templates by ID
2021-04-14 10:44:17 +01:00
Chris Hill-Scott
e32fc7c606 Use template-list-item selector
For consistency with other assertions
2021-04-14 10:30:00 +01:00
Chris Hill-Scott
e32726f692 Merge pull request #3859 from alphagov/use-rtreelib
Use pure Python Rtree library
2021-04-13 16:05:39 +01:00