-
Notifications
You must be signed in to change notification settings - Fork 354
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
fix: cli gives misleading error message when logging in with a bad password [MD-277] #8990
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8990 +/- ##
=======================================
Coverage 46.22% 46.22%
=======================================
Files 1175 1175
Lines 145341 145357 +16
Branches 2414 2414
=======================================
+ Hits 67180 67197 +17
+ Misses 77952 77951 -1
Partials 209 209
Flags with carried forward coverage won't be shown. Click here to find out more.
|
✅ Deploy Preview for determined-ui ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
bf900a8
to
48e4505
Compare
d4a34c3
to
d767c32
Compare
806349d
to
dc136dd
Compare
harness/tests/cli/test_user.py
Outdated
mock_die: mock.MagicMock, mock_getpass: mock.MagicMock | ||
) -> None: | ||
mock_getpass.side_effect = lambda *_: "newpass" | ||
with responses.RequestsMock( |
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 context manager version of this works, but since you're not doing anything complicated, the easier way to do this is to use the responses.activate
decorator. It uses the default registry, which should be a little less brittle than the OrderedRegistry
, anyway.
@mock.patch...
@responses.activate
def test_log...
...
util.expect_get_info() # take a look at the code here for another example of the pattern with `responses.activate`
responses.post(...)
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.
I agree OrderedRegistry
is not necessary for this test.
harness/tests/cli/test_user.py
Outdated
@@ -47,3 +48,29 @@ def test_user_edit_no_fields(mock_die: mock.MagicMock) -> None: | |||
mock_die.assert_has_calls( | |||
[mock.call("No field provided. Use 'det user edit -h' for usage.", exit_code=1)] | |||
) | |||
|
|||
|
|||
@mock.patch("getpass.getpass") |
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.
It shouldn't be too dangerous, but this code can touch the actual filesystem via the TokenStore. For this reason, I recommend patching determined.common.api.authentication.TokenStore
, too. I'm fine letting using the default mock class as its target (as is done when you don't pass a target to its decorator)
@mock.patch("determined.common.api.authentication.TokenStore")
But since we have a fake TokenStore
, you can also do
@mock.patch("determined.common.api.authentication.TokenStore", util.MockTokenStore)
if you like. I'm not sure which I'd choose, myself. More complex or more brittle, seems like a toss-up. Including the option to help you get up to speed with Python unittest.mock
.
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.
That's a great point. It better to avoid touching the filesystem in this test (mock external dependency).
0dca7d7
to
0cd4a6e
Compare
harness/tests/cli/test_user.py
Outdated
@mock.patch("determined.common.api.authentication.TokenStore", util.MockTokenStore(strict=False)) | ||
@mock.patch("getpass.getpass", lambda *_: "newpass") | ||
@mock.patch("determined.cli.cli.die") | ||
def test_login_returns_invalid_credentials_error_message(mock_die: mock.MagicMock) -> None: |
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.
One comment I have left is that the naming on this method is a little wonky since login
isn't isn't really "returning". "dies with" is the first thing that comes to my own mind, but I'm sure there are other good options, too. Whatever you think is best, no need to check back 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.
Small patch, but I really like how this turned out. I'm still pleased with the InvalidCredentialsException
subclass.
6f4419b
to
0c24f33
Compare
Description
When a user attempts to log in with an incorrect username and/or password, CLI display a misleading error message:
Test Plan
Login with incorrect password and/or username
Expect "Failed to log in user: Invalid username/password combination. Please try again." as the output.
Commentary (optional)
Checklist
docs/release-notes/
.See Release Note for details.
Ticket
MD-277