Fix the response status code when authenticating with wrong credentials #9655
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I read through https://www.django-rest-framework.org/community/contributing/, but it looks like the GitHub discussion page is gone. Also the issues page is not available. This is why I decided to open this PR without contacting anyone in advance.
Description
This PR started, when I wanted to authenticate via token auth in a test.
I sent the username and password and I received 400 bad request.
Then, I double checked in my development setup and everything worked.
Thing was, I forgot to create the user account in the test.
Anyway, I got the 400 instead of the 401, which would have been way more clear to me.
This is why I decided to open this PR.
The changed behavior conforms to RFC9110, see https://www.rfc-editor.org/rfc/rfc9110#section-15.5.2-2 where it says to return 401 on failed attempts.
Also, I fixed the failing tests where I think DRF should return 401 instead of 403.