@@ -27,22 +27,31 @@ def workflow_default(c: Composition) -> None:
2727 c .up ("materialized" )
2828 base = f"http://localhost:{ c .port ('materialized' , 6876 )} "
2929
30- # Regression test for database-issues#11340. With `allowed_roles:
31- # Normal`, header-based Basic auth correctly rejects `mz_system`, but
32- # `/api/login` previously did not run the same role check — letting an
33- # internal role obtain a session cookie and bypass the policy on
34- # subsequent requests. Make sure `/api/login` enforces the listener's
35- # role policy directly and never mints a session for a disallowed role .
36- with c .test_case ("session_login_rejects_disallowed_role " ):
30+ # Regression test for database-issues#11340. `/api/login` does not run
31+ # the listener's role check itself, so a disallowed role (here
32+ # `mz_system` on an `allowed_roles: Normal` listener) can authenticate
33+ # and mint a session cookie. Authorization runs per request in the
34+ # `http_authz` middleware instead, so that cookie is rejected on every
35+ # protected route and the policy still can't be bypassed .
36+ with c .test_case ("session_cookie_for_disallowed_role_is_rejected " ):
3737 s = requests .Session ()
3838 r = s .post (
3939 f"{ base } /api/login" ,
4040 json = {"username" : "mz_system" , "password" : "password" },
4141 )
42- assert r .status_code == 401 , f"expected 401, got { r .status_code } : { r .text } "
4342 assert (
44- "mz_session" not in s .cookies
45- ), f"login rejection must not set a session cookie: { s .cookies } "
43+ r .status_code == 200
44+ ), f"expected login to succeed, got { r .status_code } : { r .text } "
45+ assert (
46+ "mz_session" in s .cookies
47+ ), f"login should mint a session cookie: { s .cookies } "
48+
49+ # Reusing that session cookie on a protected route is rejected by
50+ # the authorization middleware.
51+ r = s .post (f"{ base } /api/sql" , json = {"query" : "SELECT 1" })
52+ assert (
53+ r .status_code == 401
54+ ), f"expected 401 reusing disallowed-role session, got { r .status_code } : { r .text } "
4655
4756 with c .override (
4857 Materialized (
0 commit comments