-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#2816] Split user/password auth from token verification #1449
base: develop
Are you sure you want to change the base?
Conversation
a657993
to
624ce24
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #1449 +/- ##
===========================================
+ Coverage 94.59% 94.61% +0.02%
===========================================
Files 1071 1071
Lines 39704 39794 +90
===========================================
+ Hits 37557 37653 +96
+ Misses 2147 2141 -6 ☔ View full report in Codecov by Sentry. |
a8a696b
to
de8eb28
Compare
13d404b
to
e1899ae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, couple stylistic suggestiions
|
||
cls.user = UserFactory(login_type=LoginTypeChoices.default) | ||
cls.expires_in = getattr(settings, "ACCOUNTS_USER_TOKEN_EXPIRE_TIME", 300) | ||
cls.make_token = lambda: totp(cls.user.seed, period=cls.expires_in) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cls.make_token = lambda: totp(cls.user.seed, period=cls.expires_in) | |
cls.token = lambda: totp(cls.user.seed, period=cls.expires_in) |
The value for this will be the same for all tests, so it's a bit misleading to call it make_token
(which to me suggests that a new token is made every time this is called)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The totp
function does use the current timestamp, and not all tests freeze the time (or in the same way), so I thought it'd still be easier to reason about if it's a callable. But I will add a freeze_time to the whole class, because time-based tests should be deterministic.
afc0998
to
d9a06c0
Compare
This doesn't seem to check config.login_2fa_sms anymore? This is a PR we should discuss on monday, I may be overlooking something on how this works |
That was intentional -- these are authentication backends, their task should be solely to accept some kind of credentials and return a user upon successful validation. Whether or not a token is required is a view-level concern, where the actual session is created if the right conditions are met (in this case, the username/password view doesn't actually create a session, it sends a token if the credentials are a valid, and the token verification view creates the session. I added a test to validate that behavior). The previous code was doing too much in two senses: it was validating both a token and a username/password, and it's behavior changed depending on the config, which is a controller/view level concern. |
d9a06c0
to
33b6f1a
Compare
Previously, the UserModelEmailBackend was overloaded to support both username/password authentication, as well as TOTP validation. It did this, in part, by verifying the 2FA flag on the site configuration. This was both confusing (an authentication backend should do one thing only, multiple logics means multiple backends), as well as mixing concerns (the _view_ should decide which arguments to pass to to authentication backend based on the site configuration, authentication backends should only authenticate). This commit separates both concerns into independent backends, and adds some tests to ensure that they are properly invoked.
0d5dee3
to
c3d84a6
Compare
Discussed and change is okay after tests pass |
c3d84a6
to
9b0e8c1
Compare
Previously, the UserModelEmailBackend was overloaded to support both username/password authentication, as well as TOTP validation. It did this, in part, by verifying the 2FA flag on the site configuration.
This was both confusing (an authentication backend should do one thing only, multiple logics means multiple backends), as well as mixing concerns (the view should decide which arguments to pass to to authentication backend based on the site configuration, authentication backends should only authenticate).
This commit separates both concerns into independent backends, and adds some tests to ensure that they are properly invoked.