Skip to content
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

Make APIClient.force_authenticate() work with user=None #8212

Merged
merged 4 commits into from
Sep 15, 2022

Conversation

willbeaufoy
Copy link
Contributor

@willbeaufoy willbeaufoy commented Oct 17, 2021

Description

See the issue: #8211 for why this is needed.

Previously force_authenticate() called logout() if no user is provided. However as described in the issue, there is
a case where we want to authenticate with a token but not a user, so we don't want to logout in this case.

@willbeaufoy willbeaufoy marked this pull request as ready for review October 17, 2021 14:40
@kevin-brown
Copy link
Member

We should have an added test for the case that was broken before to ensure it doesn't crop up again in the future.

@willbeaufoy
Copy link
Contributor Author

willbeaufoy commented Oct 18, 2021

We should have an added test for the case that was broken before to ensure it doesn't crop up again in the future.

Done, added test which fails without my new code.

assert 'token' not in response.data

# Token only
token = Token.objects.create(key='xyz', user=user)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be better, in my opinion at least, to have these as 3 individual tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to rerequest review from you, but the request failed for some reason. Anyway it's ready for review again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marksweb any chance of getting this merged?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@willbeaufoy I'm afraid I don't have the ability to do that. I was just reviewing to assist the maintainers.

Perhaps @tomchristie could take a look over this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomchristie any chance of merging this?

@stale
Copy link

stale bot commented Apr 18, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@willbeaufoy
Copy link
Contributor Author

Closing this PR as it's being ignored - however it works well and is ready to merge.

@tomchristie
Copy link
Member

Hi @willbeaufoy.

I do think we want this, yes.
No reason we shouldn't get this in and merged for the next release.

Thanks for the prompt.

@tomchristie tomchristie reopened this Sep 14, 2022
@willbeaufoy
Copy link
Contributor Author

Hi @willbeaufoy.

I do think we want this, yes. No reason we shouldn't get this in and merged for the next release.

Thanks for the prompt.

Ah great. I noticed it failed linting so I've just fixed this and pushed the update.

@tomchristie tomchristie merged commit 354ae73 into encode:master Sep 15, 2022
@tomchristie
Copy link
Member

Thanks @willbeaufoy 😀

sigvef pushed a commit to sigvef/django-rest-framework that referenced this pull request Dec 3, 2022
)

* Fix testing with token

* Add unit test

* Split unit test into 3

* Fix linting error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants