99from app .core .jwt import get_jwt_service
1010
1111
12+ def _assert_no_store_headers (headers : dict [str , str ]) -> None :
13+ """Assert auth-state responses are marked as non-cacheable."""
14+ assert headers .get ("cache-control" ) == "no-store"
15+ assert headers .get ("pragma" ) == "no-cache"
16+
17+
1218@pytest .mark .asyncio
1319async def test_auth_login_refresh_logout_happy_path (
1420 app_factory ,
@@ -27,6 +33,7 @@ async def test_auth_login_refresh_logout_happy_path(
2733 json = {"email" : "alice@example.com" , "password" : "Password123!" },
2834 )
2935 assert login_response .status_code == 200
36+ _assert_no_store_headers (dict (login_response .headers ))
3037 login_payload = login_response .json ()
3138 assert login_payload ["access_token" ]
3239 assert login_payload ["refresh_token" ]
@@ -46,6 +53,7 @@ async def test_auth_login_refresh_logout_happy_path(
4653 json = {"refresh_token" : login_payload ["refresh_token" ]},
4754 )
4855 assert refresh_response .status_code == 200
56+ _assert_no_store_headers (dict (refresh_response .headers ))
4957 refresh_payload = refresh_response .json ()
5058 assert refresh_payload ["refresh_token" ] != login_payload ["refresh_token" ]
5159 refresh_access_claims = jwt_service .verify_token (
@@ -64,12 +72,14 @@ async def test_auth_login_refresh_logout_happy_path(
6472 headers = {"authorization" : f"Bearer { refresh_payload ['access_token' ]} " },
6573 )
6674 assert logout_response .status_code == 204
75+ _assert_no_store_headers (dict (logout_response .headers ))
6776
6877 refresh_after_logout = await client .post (
6978 "/auth/token" ,
7079 json = {"refresh_token" : refresh_payload ["refresh_token" ]},
7180 )
7281 assert refresh_after_logout .status_code == 401
82+ _assert_no_store_headers (dict (refresh_after_logout .headers ))
7383 assert refresh_after_logout .json ()["code" ] == "session_expired"
7484
7585
@@ -88,6 +98,7 @@ async def test_auth_cookie_login_refresh_logout_happy_path(
8898 ) as client :
8999 csrf_response = await client .get ("/auth/csrf" )
90100 assert csrf_response .status_code == 200
101+ _assert_no_store_headers (dict (csrf_response .headers ))
91102 csrf_token = csrf_response .json ()["csrf_token" ]
92103
93104 login_response = await client .post (
@@ -99,6 +110,7 @@ async def test_auth_cookie_login_refresh_logout_happy_path(
99110 },
100111 )
101112 assert login_response .status_code == 200
113+ _assert_no_store_headers (dict (login_response .headers ))
102114 assert login_response .json () == {
103115 "authenticated" : True ,
104116 "session_transport" : "cookie" ,
@@ -122,6 +134,7 @@ async def test_auth_cookie_login_refresh_logout_happy_path(
122134 },
123135 )
124136 assert refresh_response .status_code == 200
137+ _assert_no_store_headers (dict (refresh_response .headers ))
125138 assert refresh_response .json () == {
126139 "authenticated" : True ,
127140 "session_transport" : "cookie" ,
@@ -146,6 +159,7 @@ async def test_auth_cookie_login_refresh_logout_happy_path(
146159 },
147160 )
148161 assert logout_response .status_code == 204
162+ _assert_no_store_headers (dict (logout_response .headers ))
149163
150164 replacement_csrf = await client .get ("/auth/csrf" )
151165 assert replacement_csrf .status_code == 200
0 commit comments