TestClient does not clear cookies based on response except if domain is set to testserver.local #3373
Unanswered
mlbiche
asked this question in
Potential Issue
Replies: 1 comment
|
As the issue seems strongly related to |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Testing a response that delete a cookie with
TestClientdoes not work except if domain is set totestserver.local.This due to how
cookiejardeletes cookies. If no domain is provided when deleting the cookie, the domain used to delete the cookie is set to request domain, beingtestserver.local(see cookiejar.py#L1532 + cookiejar.py#L645). Iftestserverdomain is provided, the domain used to delete the cookie is set totestserver.localbecause it is required to be dotted. However, setting the cookie without domain or withtestserverdomain (beingTestClient.base_url.hostreturned value), the cookie is stored in the cookie jar with the provided domain and nottestserver.local.I have written test cases to illustrate this situation : mlbiche@4adcaf0
I would expect all 3 test cases to succeed while only
testserver.localdoes.Also, note that this issue is even less expected with following code:
As no domain is provided neither when initializing TestClient, neither when deleting the cookie, this would be expected to work. This fails because the cookie is set the cookie jar with empty domain while deleting always try to delete with
testserver.local.I have to admit that
cookiejarbehaviour is confusing for me : why would it always define a dotted domain when extracting cookies while theCookieconstructor let you define cookies without dotted domain (see cookiejar.py#L786.However, as it does work this way, I
starlette.TestClientorhttpx2.Clientshould be updated and always set the domain :Client.base_url.host + ".local"if no domain is provided inCookies.set_models.py#L1104domain + ".local"if the domain isn't dotted inCookies.setAll reactions