@@ -203,6 +203,133 @@ def maas_headers_for_actor_api_key(maas_api_key_for_actor: str) -> dict[str, str
203203 return build_maas_headers (token = maas_api_key_for_actor )
204204
205205
206+ @pytest .fixture (scope = "function" )
207+ def extra_subscription_with_api_key (
208+ request_session_http : requests .Session ,
209+ base_url : str ,
210+ ocp_token_for_actor : str ,
211+ admin_client : DynamicClient ,
212+ maas_free_group : str ,
213+ maas_model_tinyllama_free : MaaSModelRef ,
214+ maas_subscription_namespace : Namespace ,
215+ maas_subscription_tinyllama_free : MaaSSubscription ,
216+ maas_subscription_controller_enabled_latest : None ,
217+ maas_gateway_api : None ,
218+ maas_api_gateway_reachable : None ,
219+ ) -> Generator [str , Any , Any ]:
220+ """
221+ Creates an extra subscription (for nonexistent-group, priority=1) and an API key
222+ bound to the original free subscription. Verifies the user's key still works even
223+ with a second subscription present (OR-logic fix). Revokes key on teardown.
224+ """
225+ with create_maas_subscription (
226+ admin_client = admin_client ,
227+ subscription_namespace = maas_subscription_namespace .name ,
228+ subscription_name = "extra-subscription" ,
229+ owner_group_name = "nonexistent-group-xyz" ,
230+ model_name = maas_model_tinyllama_free .name ,
231+ model_namespace = maas_model_tinyllama_free .namespace ,
232+ tokens_per_minute = 999 ,
233+ window = "1m" ,
234+ priority = 1 ,
235+ teardown = True ,
236+ wait_for_resource = True ,
237+ ) as extra_subscription :
238+ extra_subscription .wait_for_condition (condition = "Ready" , status = "True" , timeout = 300 )
239+ _ , body = create_api_key (
240+ base_url = base_url ,
241+ ocp_user_token = ocp_token_for_actor ,
242+ request_session_http = request_session_http ,
243+ api_key_name = f"e2e-one-of-two-{ generate_random_name ()} " ,
244+ subscription = maas_subscription_tinyllama_free .name ,
245+ )
246+ yield body ["key" ]
247+ revoke_api_key (
248+ request_session_http = request_session_http ,
249+ base_url = base_url ,
250+ key_id = body ["id" ],
251+ ocp_user_token = ocp_token_for_actor ,
252+ )
253+
254+
255+ @pytest .fixture (scope = "function" )
256+ def high_tier_subscription_with_api_key (
257+ request_session_http : requests .Session ,
258+ base_url : str ,
259+ ocp_token_for_actor : str ,
260+ admin_client : DynamicClient ,
261+ maas_free_group : str ,
262+ maas_model_tinyllama_free : MaaSModelRef ,
263+ maas_subscription_namespace : Namespace ,
264+ maas_subscription_tinyllama_free : MaaSSubscription ,
265+ maas_subscription_controller_enabled_latest : None ,
266+ maas_gateway_api : None ,
267+ maas_api_gateway_reachable : None ,
268+ ) -> Generator [str , Any , Any ]:
269+ """
270+ Creates a high-priority subscription (priority=10) for the free group and an API key
271+ bound to it. Returns the API key. Revokes key and cleans up subscription on teardown.
272+ """
273+ with create_maas_subscription (
274+ admin_client = admin_client ,
275+ subscription_namespace = maas_subscription_namespace .name ,
276+ subscription_name = "high-tier-subscription" ,
277+ owner_group_name = maas_free_group ,
278+ model_name = maas_model_tinyllama_free .name ,
279+ model_namespace = maas_model_tinyllama_free .namespace ,
280+ tokens_per_minute = 9999 ,
281+ window = "1m" ,
282+ priority = 10 ,
283+ teardown = True ,
284+ wait_for_resource = True ,
285+ ) as high_tier_subscription :
286+ high_tier_subscription .wait_for_condition (condition = "Ready" , status = "True" , timeout = 300 )
287+ _ , body = create_api_key (
288+ base_url = base_url ,
289+ ocp_user_token = ocp_token_for_actor ,
290+ request_session_http = request_session_http ,
291+ api_key_name = f"e2e-high-tier-{ generate_random_name ()} " ,
292+ subscription = high_tier_subscription .name ,
293+ )
294+ yield body ["key" ]
295+ revoke_api_key (
296+ request_session_http = request_session_http ,
297+ base_url = base_url ,
298+ key_id = body ["id" ],
299+ ocp_user_token = ocp_token_for_actor ,
300+ )
301+
302+
303+ @pytest .fixture (scope = "function" )
304+ def api_key_bound_to_system_auth_subscription (
305+ request_session_http : requests .Session ,
306+ base_url : str ,
307+ ocp_token_for_actor : str ,
308+ premium_system_authenticated_access : dict ,
309+ maas_subscription_controller_enabled_latest : None ,
310+ maas_gateway_api : None ,
311+ maas_api_gateway_reachable : None ,
312+ ) -> Generator [str , Any , Any ]:
313+ """
314+ API key bound to the system:authenticated subscription on the premium model.
315+ Used for tests that verify OR-logic auth policy access. Revoked on teardown.
316+ """
317+ _ , body = create_api_key (
318+ base_url = base_url ,
319+ ocp_user_token = ocp_token_for_actor ,
320+ request_session_http = request_session_http ,
321+ api_key_name = f"e2e-system-auth-{ generate_random_name ()} " ,
322+ subscription = premium_system_authenticated_access ["subscription" ].name ,
323+ )
324+ yield body ["key" ]
325+ revoke_api_key (
326+ request_session_http = request_session_http ,
327+ base_url = base_url ,
328+ key_id = body ["id" ],
329+ ocp_user_token = ocp_token_for_actor ,
330+ )
331+
332+
206333@pytest .fixture (scope = "class" )
207334def api_key_bound_to_free_subscription (
208335 request_session_http : requests .Session ,
@@ -369,7 +496,7 @@ def premium_system_authenticated_access(
369496 model_namespace = maas_model_tinyllama_premium .namespace ,
370497 tokens_per_minute = 100 ,
371498 window = "1m" ,
372- priority = 0 ,
499+ priority = 1 ,
373500 teardown = True ,
374501 wait_for_resource = True ,
375502 ) as system_authenticated_subscription ,
0 commit comments