Skip to content

Commit

Permalink
Add test to ensure that the vary header does not contain origin if re…
Browse files Browse the repository at this point in the history
…quest is non-credentialed
  • Loading branch information
Josh Wilson committed Dec 17, 2020
1 parent ba3fe37 commit 1673983
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/middleware/test_cors.py
Expand Up @@ -245,6 +245,24 @@ def homepage(request):
assert response.headers["vary"] == "Origin"


def test_cors_vary_header_is_not_set_for_non_credentialed_request():
app = Starlette()

app.add_middleware(CORSMiddleware, allow_origins=["*"])

@app.route("/")
def homepage(request):
return PlainTextResponse(
"Homepage", status_code=200, headers={"Vary": "Accept-Encoding"}
)

client = TestClient(app)

response = client.get("/", headers={"Origin": "https://someplace.org"})
assert response.status_code == 200
assert response.headers["vary"] == "Accept-Encoding"


def test_cors_vary_header_is_properly_set_for_credentialed_request():
app = Starlette()

Expand Down

0 comments on commit 1673983

Please sign in to comment.