-
Notifications
You must be signed in to change notification settings - Fork 687
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: Proper exception handling of InvalidPasswordLength #5279
fix: Proper exception handling of InvalidPasswordLength #5279
Conversation
Hi @prateekj117 and thanks for this fix! I've added a simple test plan to the PR description, hope that's OK. In general, PRs to this project should include the sections laid out in the template - it helps speed the review process. The change looks good at first glance, but if you have time, could you add a test to cover this behaviour? Take a look at this test for an example. |
@zenmonkeykstop Ya, sure. I will keep that in mind. I will add the test as well. Thanks for the review !!! |
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.
Change looks good, a test covering the behavior change in this case would be great.
@prateekj117 Maybe I can save you some time. This could go in def test_login_password_too_long(journalist_app, test_journo, mocker):
mocked_error_logger = mocker.patch('journalist.app.logger.error')
with journalist_app.test_client() as app:
resp = app.post(url_for('main.login'),
data=dict(username=test_journo['username'],
password='a' * (Journalist.MAX_PASSWORD_LEN + 1),
token=TOTP(test_journo['otp_secret']).now()))
assert resp.status_code == 200
text = resp.data.decode('utf-8')
assert "Login failed" in text
mocked_error_logger.assert_called_once_with(
"Login for '{}' failed: Password too long (len={})".format(
test_journo['username'], Journalist.MAX_PASSWORD_LEN + 1)) |
@rmol Thanks a lot. Though I would have definitely enjoyed writting this logic myself and learning a few more things along the way. |
@prateekj117 Well, drat. I could delete the comment. 😉 That's good to know; I will not deprive you of the pleasure of writing tests for your next PR. 🙂 |
@zenmonkeykstop Error recorded in Docker output is @rmol Thanks for the test. |
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.
CI is passing with the new test, this is good to go!
Status
Ready for review
Description of Changes
When entering passphrase of more than 128 (max_limit) characters, the user lands to the Internal Server Error Page.
Fixes #5145
Changes proposed in this pull request:
Handle the exception properly so that the server returns with the flashed error message.
Testing
make dev
- it completes successfullylocalhost:8081
with a valid username<userName>
and TOTP code, and a password longer than 127 characters:Login failed. Please wait for a new code from your two-factor mobile app or security key before trying again
message.[<timestamp>] ERROR in utils: Login for '<userName>' failed: invalid password
Deployment
Checklist
If you made changes to the server application code:
make lint
) and tests (make test
) pass in the development containerIf you made non-trivial code changes: