Commit Graph

92 Commits

Author SHA1 Message Date
Kenneth Kehl
ed3a356ad1 merge from main and fix some tests 2024-01-19 08:58:24 -08:00
Kenneth Kehl
567dd390b4 fix personalisation 2024-01-18 10:03:35 -08:00
Kenneth Kehl
f9f1013f5b notify-api-742 don't write phone numbers to db 2024-01-16 11:21:24 -08:00
Kenneth Kehl
ca199c4491 flake8 2024-01-10 11:49:20 -08:00
Kenneth Kehl
97baa4c184 flake8 2024-01-10 11:38:23 -08:00
Kenneth Kehl
6f04915ee8 flake8 2024-01-10 11:20:33 -08:00
Kenneth Kehl
f6ba9b4d74 mock redis 2024-01-10 11:14:04 -08:00
Kenneth Kehl
e15122d6f5 mock redis 2024-01-10 11:00:50 -08:00
Kenneth Kehl
1ecb747c6d reformat 2023-08-29 14:54:30 -07:00
Kenneth Kehl
5a350560d7 notify-api-433b remove research mode 2023-08-25 12:09:00 -07:00
Kenneth Kehl
0f470af7b6 fix more skips 2023-05-22 11:35:00 -07:00
Kenneth Kehl
47b5303726 fix more skips 2023-05-18 14:18:02 -07:00
Ryan Ahearn
82df01653f Update tests to focus on US numbers 2023-01-05 11:06:12 -05:00
Christa Hartsock
af6495cd4c Get tests passing locally
When we cloned the repository and started making modifications, we
didn't initially keep tests in step. This commit tries to get us to a
clean test run by skipping tests that are failing and removing some
that we no longer expect to use (MMG, Firetext), with the intention that
we will come back in future and update or remove them as appropriate.

To find all tests skipped, search for `@pytest.mark.skip(reason="Needs
updating for TTS:`. There will be a brief description of the work that
needs to be done to get them passing, if known. Delete that line to make
them run in a standard test run (`make test`).
2022-07-07 15:41:15 -07:00
Chris Hill-Scott
c2b6a9df80 Allow admin app to specify domain for registration email
This follows the pattern for invite emails where the admin app tells the
API which domain to use when generating the link.

This will starting working once the admin change is merged:
- [ ] TBC

It won’t break anything if it’s merged before the admin change.
2022-03-07 15:03:46 +00:00
Chris Hill-Scott
544bfbf569 Add separate config item for failed login count
It’s confusing that changing `MAX_VERIFY_CODE_COUNT` also limits the
number of failed login attempts that a user of text messages 2FA can
make.

This makes the parameters independent, and adds a test to make sure any
future changes which affect the limit of failed login attempts are
covered.
2021-10-04 10:45:07 +01:00
Chris Hill-Scott
786893d920 Reduce max concurrent 2 factor codes
I was doing some analysis and saw that in the last 24 hours the most
codes that anyone had was in a 15 minute window was 3.

So I think we can safely reduce this to 5 to get a bit more security
with enough headroom to not have any negative impact to the user.
2021-10-04 10:45:06 +01:00
Ben Thorner
0312e2a528 Split generating authorization headers by type
In response to [1].

[1]: https://github.com/alphagov/notifications-api/pull/3300#discussion_r681653248
2021-08-04 15:13:52 +01:00
Pea Tyczynska
251107029a Add webauthn to tests that include other auth types 2021-05-13 12:44:36 +01:00
Ben Thorner
a91fde2fda Run auto-correct on app/ and tests/ 2021-03-12 11:45:45 +00:00
Rebecca Law
77b76ea0a4 Rename variable, it's a better name now. 2021-02-17 13:15:29 +00:00
Rebecca Law
e77534fb17 Send text message that are to an international number from a number rather than "Notify"
Update `send_user_2fa_code` to send from number when recipient is international
Update `update_user_attribute` to send from number when recipient is international
2021-02-17 12:14:47 +00:00
Chris Hill-Scott
3b0b96834d Do extra code style checks with flake8-bugbear
Flake8 Bugbear checks for some extra things that aren’t code style
errors, but are likely to introduce bugs or unexpected behaviour. A
good example is having mutable default function arguments, which get
shared between every call to the function and therefore mutating a value
in one place can unexpectedly cause it to change in another.

This commit enables all the extra warnings provided by Flake8 Bugbear,
except for:
- the line length one (because we already lint for that separately)
- B903 Data class should either be immutable or use `__slots__` because
  this seems to false-positive on some of our custom exceptions
- B902 Invalid first argument 'cls' used for instance method because
  some SQLAlchemy decorators (eg `declared_attr`) make things that
  aren’t formally class methods take a class not an instance as their
  first argument

It disables:
- _B306: BaseException.message is removed in Python 3_ because I think
  our exceptions have a custom structure that means the `.message`
  attribute is still present

Matches the work done in other repos:
- https://github.com/alphagov/notifications-admin/pull/3172/files
2020-12-22 16:26:45 +00:00
Leo Hemsted
2b7e05d4e4 restore email sign in code expiry functionality
reverts 789112a31f

however, keeps the changes to the tests as they were an improvement
2020-05-05 12:00:36 +01:00
Leo Hemsted
789112a31f don't expire email sign in codes on use
we're seeing issues with email clients sniffing links, and causing them
to expire before the user gets a chance to click on them. Temporarily
disable the expiry while we work on a more permanent solution.

The link will still expire after half an hour, and sms codes aren't
affected by this change
2020-05-04 12:01:57 +01: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 Tyczynska
0eed4c99a7 Add email_access_valdiated_at field to user table, populate it
and update it when users have to use their email to interact with
Notify service.

Initial population:
If user has email_auth, set last_validated_at to logged_in_at.
If user has sms_auth,  set it to created_at.

Then:
Update email_access_valdiated_at date when:
- user with email_auth logs in
- new user is created
- user resets password when logged out, meaning we send them an
email with a link they have to click to reset their password.
2020-01-30 14:51:54 +00:00
Chris Hill-Scott
8af5cbab86 Bump utils to 30.5.4 2018-10-09 15:08:54 +01:00
Chris Hill-Scott
c0e2a478f6 Allow admin to specify domain for email auth links
Similar to https://github.com/alphagov/notifications-api/pull/1515

This lets the admin app pass in a domain to use for email auth links,
so that when it’s running on a different URL users who try to sign in
will get an email auth link for the domain they sign in on, not the
default admin domain for the environment in which the API is running.
2018-02-09 14:19:17 +00:00
Leo Hemsted
b1cccdcc6b First batch of flake8 changes.
Many unused variables, and replacing some old fixtures with
admin_request before I realised just how many there where 😩
2017-11-28 17:00:01 +00:00
Rebecca Law
ab5b7c20a7 Use sms sender or reply to email address of the Notify service in create_2fa_code depending on message type. 2017-11-27 16:52:52 +00:00
venusbb
3945007d24 add reply-to-text to user/rest persist notifications 2017-11-27 14:36:54 +00:00
Leo Hemsted
0146e2d935 attempt to reduce code duplication 2017-11-07 16:47:40 +00:00
Leo Hemsted
67ae1fdb7b PR changes - some comment clarification and code simplifying 2017-11-07 16:47:40 +00:00
Leo Hemsted
a8ebb10c8e add tests for code used 2017-11-07 16:47:40 +00:00
Leo Hemsted
a231918317 put secret code in email url token 2017-11-07 16:47:26 +00:00
Leo Hemsted
6af616eb83 add name to personalisation and urlencode next param
also add tests
2017-11-07 16:47:26 +00:00
Leo Hemsted
dd326ec1d3 add new template to config
and rename existing new user email verification template for clarity
2017-11-07 16:47:26 +00:00
Leo Hemsted
b2756ac99d add email code verification
by hitting POST /<user_id>/email-code, we create an email two factor
code to send to the user. That email contains a link with a token that
will sign the user in when opened.

Also some other things:

"email verification" (aka when you first create an account) doesn't
hit the API anymore

refactor 2fa code verification and sending to use jsonschema, and share code between sms and email

Die marshmallow die!
2017-11-07 16:45:49 +00:00
Martyn Inglis
2591d3a1df This massive set of changes uses the new queue names object throughout the app and tests.
Lots of changes, all changing the line of code that puts things into queues, and the code that tests that.
2017-05-25 10:51:49 +01:00
Imdad Ahad
3de93cbcd0 Assume that we will only receive a UK number:
* We currently don't validate the number so this test
* will fail assuming an invalid number was passed.
* Since we do validation on the front end, for now
* we'll assume a valid number. This does need to be
* looked at in future.
2017-04-27 13:24:48 +01:00
Rebecca Law
fd0bfbe2f6 If user account is locked return 404 even if the code is correct.
Update user.failed_login_count = 0 if code is correct.
New endpoint to reset the failed_login_count
2017-02-28 14:28:33 +00:00
Rebecca Law
fb61b4528b Remove resetting the failed_login_count to zero in the api. The admin app will deal with doing that. 2017-02-28 11:21:47 +00:00
Leo Hemsted
8bad5926ab dont set session_id or logged_in_at if user provides email code 2017-02-24 15:14:47 +00:00
Leo Hemsted
a47672f7e3 Add current_session_id to the user model, update on login
when we change the last logged in time, set the current session id to
a random uuid

this way, we can compare it to the cookie a user has, and if they
differ then we can log them out

also update user.logged_in_at at 2FA rather than password check, since
that feels more accurate
2017-02-22 17:30:55 +00:00
Leo Hemsted
0515c51475 replace notify_api with client fixture in user/test_rest.py 2017-02-17 11:02:28 +00:00
Leo Hemsted
ac9739f8a2 ensure we reset failed_login_count when appropriate
in verify_user_password, if succesful we reset the failed_login_count.
now we use failed_login_count for 2FA attempts, we need to make sure we
reset it in other places too, so that people don't get blocked,
especially in the reset-password user journey.

* verify_user_code - if it's succesful, reset the failed_login_count
* update_password - reset failed_login_count because either
  * you're logged in and so it's 0 anyway
  * you're resetting your password via pword reset link, and the old
    count isn't relevant anymore
2017-02-16 16:00:40 +00:00
Rebecca Law
ed4b9d34a6 Changes as per code review comments.
Fix my backward date math :P
2017-02-15 17:41:07 +00:00
Rebecca Law
52342afe3f Add a limit to the number of active 2fa codes that we create. At the moment that is set to 10. 2017-02-15 16:18:05 +00:00
Rebecca Law
9de88c50ba Remove test for resetting the failed_login_count, the admin app will request that. 2017-02-15 15:24:42 +00:00