Login returns 500 when usernames differ only in case and none matches exactly
🙂 Looking for an issue? Welcome! This issue is open for contribution. If this is the first time you’re requesting an issue, please:
- Read Contributing guidelines carefully. Pay extra attention to Using generative AI. Pull requests and comments that don’t follow the guidelines won’t be answered.
- Confirm that you’ve read the guidelines in your comment.
Observed behavior
If a facility has two users whose usernames only differ in case, like Shared_Username and shared_username, and someone tries to log in as SHARED_USERNAME with the wrong password, the server returns a 500 instead of the usual "incorrect username or password" error.
Errors and logs
AttributeError: 'NoneType' object has no attribute 'password'
kolibri/core/auth/viewsets/session.py, in _throw_validation_error
Expected behavior
A 401 invalid credentials error for a wrong password, or a 400 missing password error if no password is sent.
User-facing consequences
The learner gets a generic server error and doesn't know what went wrong.
Steps to reproduce
- Create
Shared_Usernameandshared_usernamein the same facility - Try to sign in as
SHARED_USERNAMEwith any wrong password - The POST to
/api/auth/session/returns 500
Context
Found this on develop. When the case-insensitive lookup returns more than one user, the code falls back to an exact-case match (added in #11082). If nothing matches exactly, that returns None, and the next line reads .password on it.
I've opened #15540 with a fix and regression tests.