-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Description
First check
- I added a very descriptive title to this issue. (I think?)
- I used the GitHub search to find a similar issue and didn't find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google "How to X in FastAPI" and didn't find any information.
- I already read and followed all the tutorial in the docs and didn't find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
- After submitting this, I commit to one of:
- Implement a Pull Request for a confirmed bug.
What?
When testing a FastAPI application with normal cookies, everything works as intended. When setting secure=True, it breaks tests. The TestClient request context seems to lose information about cookies given to it via response, which breaks tests that depend on the cookie being resubmitted to the application.
Example
I've produced a small repository with this reproducible issue: https://github.com/kevr/fastapi-secure-cookie-bug
Route that causes the issue: https://github.com/kevr/fastapi-secure-cookie-bug/blob/secure_cookie_bug/secure_app/app.py#L13
Test that tests and fails: https://github.com/kevr/fastapi-secure-cookie-bug/blob/secure_cookie_bug/test/test_app.py#L8
$ pytest test
# test_secure_cookie fails.
# Load up uvicorn on another shell.
$ uvicorn --reload secure_app.app:app
# Use our app server over http localhost.
$ curl -v 'http://localhost:8000' # Gives `set-cookie`.
$ curl -b test_cookie=TEST -v 'http://localhost:8000' # Provides a `test_cookie` to the app.
Additional Comments
Am I approaching this the wrong way? I'm not sure if this is actually a bug or a "bug due to lack of understanding."