Better test for Vary header

This commit is contained in:
Simon Willison 2020-06-06 12:26:19 -07:00
commit 070838bfa1
2 changed files with 6 additions and 2 deletions

View file

@ -132,8 +132,6 @@ class TestClient:
if csrftoken_from is True:
csrftoken_from = path
token_response = await self._request(csrftoken_from)
# Check this had a Vary: Cookie header
assert "Cookie" == token_response.headers["vary"]
csrftoken = token_response.cookies["ds_csrftoken"]
cookies["ds_csrftoken"] = csrftoken
post_data["csrftoken"] = csrftoken

View file

@ -100,6 +100,12 @@ def test_custom_params(canned_write_client):
assert '<input type="text" id="qp3" name="extra" value="foo">' in response.text
def test_vary_header(canned_write_client):
# These forms embed a csrftoken so they should be served with Vary: Cookie
assert "vary" not in canned_write_client.get("/data").headers
assert "Cookie" == canned_write_client.get("/data/update_name").headers["vary"]
def test_canned_query_permissions_on_database_page(canned_write_client):
# Without auth only shows three queries
query_names = [