@@ -53,28 +53,11 @@ def owasp_anon_api(playwright: Playwright) -> Generator[APIRequestContext, None,
5353 ctx .dispose ()
5454
5555
56- @pytest .fixture (scope = "module" )
57- def owasp_admin_api (playwright : Playwright ) -> Generator [APIRequestContext , None , None ]:
58- """Admin-authenticated API context for OWASP A01 tests (admin bypass via teams=null).
59-
60- Prefers the ``MCP_AUTH`` env var (set by the Makefile from a token signed with
61- the running gateway's secret) so signatures match the deployed instance. Falls
62- back to a locally-signed JWT only when ``MCP_AUTH`` is unset.
63- """
64- token = os .getenv ("MCP_AUTH" , "" ) or _make_jwt ("admin@example.com" , is_admin = True )
65- ctx = playwright .request .new_context (
66- base_url = BASE_URL ,
67- extra_http_headers = {"Authorization" : f"Bearer { token } " , "Accept" : "application/json" },
68- )
69- yield ctx
70- ctx .dispose ()
71-
72-
7356@pytest .fixture
74- def owasp_user_a_api (owasp_admin_api : APIRequestContext , playwright : Playwright ):
57+ def owasp_user_a_api (admin_api : APIRequestContext , playwright : Playwright ):
7558 """Non-admin API context for User A, registered in the system. Cleans up after test."""
7659 email = f"owasp-a-{ uuid .uuid4 ().hex [:8 ]} @example.com"
77- create_resp = owasp_admin_api .post (
60+ create_resp = admin_api .post (
7861 "/auth/email/admin/users" ,
7962 data = {"email" : email , "password" : TEST_PASSWORD , "full_name" : "OWASP User A" },
8063 )
@@ -85,14 +68,14 @@ def owasp_user_a_api(owasp_admin_api: APIRequestContext, playwright: Playwright)
8568 yield {"ctx" : ctx , "email" : email }
8669 ctx .dispose ()
8770 with suppress (Exception ):
88- owasp_admin_api .delete (f"/auth/email/admin/users/{ email } " )
71+ admin_api .delete (f"/auth/email/admin/users/{ email } " )
8972
9073
9174@pytest .fixture
92- def owasp_user_b_api (owasp_admin_api : APIRequestContext , playwright : Playwright ):
75+ def owasp_user_b_api (admin_api : APIRequestContext , playwright : Playwright ):
9376 """Non-admin API context for User B, registered in the system. Cleans up after test."""
9477 email = f"owasp-b-{ uuid .uuid4 ().hex [:8 ]} @example.com"
95- create_resp = owasp_admin_api .post (
78+ create_resp = admin_api .post (
9679 "/auth/email/admin/users" ,
9780 data = {"email" : email , "password" : TEST_PASSWORD , "full_name" : "OWASP User B" },
9881 )
@@ -103,11 +86,11 @@ def owasp_user_b_api(owasp_admin_api: APIRequestContext, playwright: Playwright)
10386 yield {"ctx" : ctx , "email" : email }
10487 ctx .dispose ()
10588 with suppress (Exception ):
106- owasp_admin_api .delete (f"/auth/email/admin/users/{ email } " )
89+ admin_api .delete (f"/auth/email/admin/users/{ email } " )
10790
10891
10992@pytest .fixture
110- def two_teams_setup (owasp_admin_api : APIRequestContext , playwright : Playwright ):
93+ def two_teams_setup (admin_api : APIRequestContext , playwright : Playwright ):
11194 """Create two distinct teams with separate scoped tokens. Cleans up after test."""
11295 suffix = uuid .uuid4 ().hex [:8 ]
11396 team_a_id : str | None = None
@@ -118,25 +101,25 @@ def two_teams_setup(owasp_admin_api: APIRequestContext, playwright: Playwright):
118101 ctx_b = None
119102 try :
120103 # Team A
121- resp_a = owasp_admin_api .post ("/teams/" , data = {"name" : f"owasp-team-a-{ suffix } " , "description" : "OWASP Team A" , "visibility" : "private" })
104+ resp_a = admin_api .post ("/teams/" , data = {"name" : f"owasp-team-a-{ suffix } " , "description" : "OWASP Team A" , "visibility" : "private" })
122105 assert resp_a .status in (200 , 201 ), f"Failed creating Team A: { resp_a .status } { resp_a .text ()} "
123106 team_a_id = resp_a .json ()["id" ]
124107
125108 # Team B
126- resp_b = owasp_admin_api .post ("/teams/" , data = {"name" : f"owasp-team-b-{ suffix } " , "description" : "OWASP Team B" , "visibility" : "private" })
109+ resp_b = admin_api .post ("/teams/" , data = {"name" : f"owasp-team-b-{ suffix } " , "description" : "OWASP Team B" , "visibility" : "private" })
127110 assert resp_b .status in (200 , 201 ), f"Failed creating Team B: { resp_b .status } { resp_b .text ()} "
128111 team_b_id = resp_b .json ()["id" ]
129112
130113 # Server owned by Team A
131- srv_a = owasp_admin_api .post (
114+ srv_a = admin_api .post (
132115 "/servers" ,
133116 data = {"server" : {"name" : f"owasp-srv-a-{ suffix } " , "description" : "Team A server" }, "team_id" : team_a_id , "visibility" : "team" },
134117 )
135118 assert srv_a .status in (200 , 201 ), f"Failed creating Team A server: { srv_a .status } { srv_a .text ()} "
136119 server_a_id = srv_a .json ()["id" ]
137120
138121 # Server owned by Team B
139- srv_b = owasp_admin_api .post (
122+ srv_b = admin_api .post (
140123 "/servers" ,
141124 data = {"server" : {"name" : f"owasp-srv-b-{ suffix } " , "description" : "Team B server" }, "team_id" : team_b_id , "visibility" : "team" },
142125 )
@@ -163,24 +146,24 @@ def two_teams_setup(owasp_admin_api: APIRequestContext, playwright: Playwright):
163146 ctx_b .dispose ()
164147 if server_a_id :
165148 with suppress (Exception ):
166- owasp_admin_api .delete (f"/servers/{ server_a_id } " )
149+ admin_api .delete (f"/servers/{ server_a_id } " )
167150 if server_b_id :
168151 with suppress (Exception ):
169- owasp_admin_api .delete (f"/servers/{ server_b_id } " )
152+ admin_api .delete (f"/servers/{ server_b_id } " )
170153 if team_a_id :
171154 with suppress (Exception ):
172- owasp_admin_api .delete (f"/teams/{ team_a_id } " )
155+ admin_api .delete (f"/teams/{ team_a_id } " )
173156 if team_b_id :
174157 with suppress (Exception ):
175- owasp_admin_api .delete (f"/teams/{ team_b_id } " )
158+ admin_api .delete (f"/teams/{ team_b_id } " )
176159
177160
178161@pytest .fixture
179- def private_server_owned_by_user_a (owasp_admin_api : APIRequestContext , owasp_user_a_api : dict ):
162+ def private_server_owned_by_user_a (admin_api : APIRequestContext , owasp_user_a_api : dict ):
180163 """Create a private server via admin on behalf of User A and return its ID. Cleans up after test."""
181164 server_id : str | None = None
182165 try :
183- resp = owasp_admin_api .post (
166+ resp = admin_api .post (
184167 "/servers" ,
185168 data = {
186169 "server" : {"name" : f"owasp-priv-{ uuid .uuid4 ().hex [:8 ]} " , "description" : "User A private server" },
@@ -195,4 +178,4 @@ def private_server_owned_by_user_a(owasp_admin_api: APIRequestContext, owasp_use
195178 finally :
196179 if server_id :
197180 with suppress (Exception ):
198- owasp_admin_api .delete (f"/servers/{ server_id } " )
181+ admin_api .delete (f"/servers/{ server_id } " )
0 commit comments