<?xml version="1.0" encoding="utf-8"?><testsuites name="pytest tests"><testsuite name="pytest" errors="0" failures="5" skipped="11" tests="150" time="659.183" timestamp="2026-10-30T13:02:46.390115+00:00" hostname="ai-gateway-controller-group033dfc0eecfd6abc097ae03f6d08db38-pod"><testcase classname="tests.test_api_keys.TestAPIKeyAuthorization" name="test_admin_manage_other_users_keys" time="94.571" /><testcase classname="tests.test_api_keys.TestAPIKeyBulkOperations" name="test_bulk_revoke_dry_run" time="0.528" /><testcase classname="tests.test_api_keys.TestAPIKeyExpiration" name="test_expiration_policy_boundaries[within-limit]" time="0.081" /><testcase classname="tests.test_api_keys.TestAPIKeyExpiration" name="test_expiration_policy_boundaries[at-limit]" time="0.087" /><testcase classname="tests.test_api_keys.TestAPIKeyExpiration" name="test_expiration_policy_boundaries[exceeds-limit]" time="0.089" /><testcase classname="tests.test_api_keys.TestAPIKeyExpiration" name="test_expiration_policy_boundaries[without-expiration]" time="0.093" /><testcase classname="tests.test_api_keys.TestAPIKeyExpiration" name="test_expiration_policy_boundaries[short-expiration]" time="0.084" /><testcase classname="tests.test_api_keys.TestAPIKeyModelInference" name="test_api_key_model_access_success" time="0.193" /><testcase classname="tests.test_api_keys.TestAPIKeyModelInference" name="test_invalid_api_key_rejected" time="0.049" /><testcase classname="tests.test_api_keys.TestAPIKeyModelInference" name="test_no_auth_header_rejected" time="0.036" /><testcase classname="tests.test_api_keys.TestAPIKeyModelInference" name="test_revoked_api_key_rejected" time="2.337" /><testcase classname="tests.test_api_keys.TestAPIKeyModelInference" name="test_api_key_chat_completions" time="0.074" /><testcase classname="tests.test_api_keys.TestAPIKeyRevocationE2E" name="test_double_revoke_returns_404" time="0.252" /><testcase classname="tests.test_api_keys.TestAPIKeyRevocationE2E" name="test_revoke_nonexistent_key_returns_404" time="0.099" /><testcase classname="tests.test_api_keys.TestAPIKeyRevocationE2E" name="test_revoke_then_create_new_key_works" time="0.371" /><testcase classname="tests.test_api_keys.TestAPIKeyRevocationE2E" name="test_individual_revoke_multiple_keys" time="0.531" /><testcase classname="tests.test_api_keys.TestAPIKeyRevocationE2E" name="test_revoke_keys_rejected_at_gateway" time="0.725" /><testcase classname="tests.test_api_keys.TestEphemeralKeyCleanup" name="test_cronjob_exists_and_configured" time="0.153" /><testcase classname="tests.test_api_keys.TestEphemeralKeyCleanup" name="test_cleanup_networkpolicy_exists" time="0.141" /><testcase classname="tests.test_api_keys.TestEphemeralKeyCleanup" name="test_create_ephemeral_key" time="0.268" /><testcase classname="tests.test_api_keys.TestEphemeralKeyCleanup" name="test_trigger_cleanup_preserves_active_keys" time="0.239"><skipped type="pytest.skip" message="Cannot find maas-api pod in odh-ai-gateway-infra: error: error executing jsonpath &quot;{.items[0].metadata.name}&quot;: Error executing template: array index out of bounds: index 0, length 0. Printing more information for debugging the template:&#10;&#09;template was:&#10;&#09;&#09;{.items[0].metadata.name}&#10;&#09;object given to jsonpath engine was:&#10;&#09;&#09;map[string]interface {}{&quot;apiVersion&quot;:&quot;v1&quot;, &quot;items&quot;:[]interface {}{}, &quot;kind&quot;:&quot;List&quot;, &quot;metadata&quot;:map[string]interface {}{&quot;resourceVersion&quot;:&quot;&quot;}}">/workspace/source/test/maas-e2e/test/e2e/tests/test_api_keys.py:1429: Cannot find maas-api pod in odh-ai-gateway-infra: error: error executing jsonpath "{.items[0].metadata.name}": Error executing template: array index out of bounds: index 0, length 0. Printing more information for debugging the template:
	template was:
		{.items[0].metadata.name}
	object given to jsonpath engine was:
		map[string]interface {}{"apiVersion":"v1", "items":[]interface {}{}, "kind":"List", "metadata":map[string]interface {}{"resourceVersion":""}}</skipped></testcase><testcase classname="tests.test_api_keys.TestAPIKeySubscriptionPhases" name="test_create_key_for_active_subscription" time="12.386" /><testcase classname="tests.test_api_keys.TestAPIKeyCRUD" name="test_revoke_api_key" time="106.052" /><testcase classname="tests.test_api_keys.TestAPIKeyBulkOperations" name="test_bulk_revoke_by_subscription_forbidden_for_non_admin" time="0.097" /><testcase classname="tests.test_api_keys.TestAPIKeySubscriptionPhases" name="test_create_key_for_failed_subscription" time="12.411" /><testcase classname="tests.test_api_keys.TestAPIKeySubscriptionPhases" name="test_create_key_for_degraded_subscription" time="15.003" /><testcase classname="tests.test_api_keys.TestAPIKeyBulkOperations" name="test_bulk_revoke_other_user_forbidden" time="118.319" /><testcase classname="tests.test_api_keys.TestAPIKeyBulkOperations" name="test_bulk_revoke_missing_scope_returns_400" time="0.087" /><testcase classname="tests.test_api_keys.TestAPIKeyLabels" name="test_create_api_key_with_labels" time="0.184" /><testcase classname="tests.test_api_keys.TestAPIKeySubscriptionFilter" name="test_search_filters_by_subscription" time="30.780" /><testcase classname="tests.test_api_keys.TestAPIKeyLabels" name="test_search_api_keys_by_labels" time="0.454" /><testcase classname="tests.test_api_keys.TestAPIKeyLabels" name="test_backward_compatibility_no_labels" time="0.171" /><testcase classname="tests.test_namespace_scoping.TestMaaSAPIWatchNamespace" name="test_subscription_in_subscription_namespace_visible_to_api" time="0.000"><skipped type="pytest.skip" message="test_namespace_scoping validates single-tenant dormant mode; skipped when ENABLE_TENANT_NAMESPACE_DISCOVERY=true">/workspace/source/test/maas-e2e/test/e2e/tests/test_namespace_scoping.py:214: test_namespace_scoping validates single-tenant dormant mode; skipped when ENABLE_TENANT_NAMESPACE_DISCOVERY=true</skipped></testcase><testcase classname="tests.test_namespace_scoping.TestMaaSAPIWatchNamespace" name="test_subscription_in_another_namespace_not_visible_to_api" time="0.000"><skipped type="pytest.skip" message="test_namespace_scoping validates single-tenant dormant mode; skipped when ENABLE_TENANT_NAMESPACE_DISCOVERY=true">/workspace/source/test/maas-e2e/test/e2e/tests/test_namespace_scoping.py:247: test_namespace_scoping validates single-tenant dormant mode; skipped when ENABLE_TENANT_NAMESPACE_DISCOVERY=true</skipped></testcase><testcase classname="tests.test_namespace_scoping.TestMaaSControllerWatchNamespace" name="test_authpolicy_and_subscription_in_maas_subscription_namespace" time="0.000"><skipped type="pytest.skip" message="test_namespace_scoping validates single-tenant dormant mode; skipped when ENABLE_TENANT_NAMESPACE_DISCOVERY=true">/workspace/source/test/maas-e2e/test/e2e/tests/test_namespace_scoping.py:287: test_namespace_scoping validates single-tenant dormant mode; skipped when ENABLE_TENANT_NAMESPACE_DISCOVERY=true</skipped></testcase><testcase classname="tests.test_namespace_scoping.TestMaaSControllerWatchNamespace" name="test_authpolicy_and_subscription_in_another_namespace" time="0.000"><skipped type="pytest.skip" message="test_namespace_scoping validates single-tenant dormant mode; skipped when ENABLE_TENANT_NAMESPACE_DISCOVERY=true">/workspace/source/test/maas-e2e/test/e2e/tests/test_namespace_scoping.py:324: test_namespace_scoping validates single-tenant dormant mode; skipped when ENABLE_TENANT_NAMESPACE_DISCOVERY=true</skipped></testcase><testcase classname="tests.test_namespace_scoping.TestModelRef" name="test_auth_policy_model_ref" time="0.000"><skipped type="pytest.skip" message="test_namespace_scoping validates single-tenant dormant mode; skipped when ENABLE_TENANT_NAMESPACE_DISCOVERY=true">/workspace/source/test/maas-e2e/test/e2e/tests/test_namespace_scoping.py:382: test_namespace_scoping validates single-tenant dormant mode; skipped when ENABLE_TENANT_NAMESPACE_DISCOVERY=true</skipped></testcase><testcase classname="tests.test_namespace_scoping.TestModelRef" name="test_subscription_model_ref" time="0.000"><skipped type="pytest.skip" message="test_namespace_scoping validates single-tenant dormant mode; skipped when ENABLE_TENANT_NAMESPACE_DISCOVERY=true">/workspace/source/test/maas-e2e/test/e2e/tests/test_namespace_scoping.py:456: test_namespace_scoping validates single-tenant dormant mode; skipped when ENABLE_TENANT_NAMESPACE_DISCOVERY=true</skipped></testcase><testcase classname="tests.test_negative_security.TestAPIKeyManagementIsolation" name="test_api_key_cannot_mint_another_api_key" time="0.440" /><testcase classname="tests.test_negative_security.TestHeaderSpoofing" name="test_forged_identity_headers_rejected_on_key_mint[username-only]" time="0.640" /><testcase classname="tests.test_negative_security.TestHeaderSpoofing" name="test_forged_identity_headers_rejected_on_key_mint[group-only]" time="0.624" /><testcase classname="tests.test_negative_security.TestHeaderSpoofing" name="test_forged_identity_headers_rejected_on_key_mint[keyname-only]" time="0.595" /><testcase classname="tests.test_negative_security.TestHeaderSpoofing" name="test_forged_identity_headers_rejected_on_key_mint[identity-envelope]" time="0.656" /><testcase classname="tests.test_negative_security.TestHeaderSpoofing" name="test_forged_identity_headers_rejected_on_key_mint[admin-scope]" time="0.674" /><testcase classname="tests.test_negative_security.TestHeaderSpoofing" name="test_injected_identity_headers_rejected_on_inference" time="0.316" /><testcase classname="tests.test_negative_security.TestHeaderSpoofing" name="test_duplicate_subscription_headers_ignored" time="8.483" /><testcase classname="tests.test_api_keys.TestAPIKeyBulkOperations" name="test_bulk_revoke_own_keys" time="129.888" /><testcase classname="tests.test_api_keys.TestAPIKeySubscriptionFilter" name="test_search_without_subscription_returns_all" time="1.575" /><testcase classname="tests.test_api_keys.TestAPIKeyCRUD" name="test_create_api_key" time="129.553" /><testcase classname="tests.test_api_keys.TestAPIKeyAuthorization" name="test_non_admin_cannot_access_other_users_keys" time="130.200" /><testcase classname="tests.test_negative_security.TestCrossModelAccess" name="test_key_cannot_access_model_outside_subscription" time="0.391" /><testcase classname="tests.test_api_keys.TestAPIKeyBulkOperations" name="test_bulk_revoke_admin_can_revoke_any_user" time="1.349" /><testcase classname="tests.test_api_keys.TestAPIKeyBulkOperations" name="test_bulk_revoke_dry_run_by_subscription" time="15.119" /><testcase classname="tests.test_negative_security.TestHeaderAbuse" name="test_special_characters_in_subscription_header" time="0.952" /><testcase classname="tests.test_api_keys.TestAPIKeyBulkOperations" name="test_bulk_revoke_combined_user_and_subscription" time="16.408" /><testcase classname="tests.test_negative_security.TestMissingModelRef" name="test_subscription_with_nonexistent_model_ref" time="13.827" /><testcase classname="tests.test_negative_security.TestInternalEndpointIsolation" name="test_internal_endpoint_not_routable[api-keys-cleanup]" time="0.190" /><testcase classname="tests.test_negative_security.TestInternalEndpointIsolation" name="test_health_endpoint_accessible" time="0.040" /><testcase classname="tests.test_negative_security.TestInternalEndpointIsolation" name="test_v1_models_via_maas_api_prefix" time="0.254" /><testcase classname="tests.test_negative_security.TestExpiredKeyRejection" name="test_expired_key_rejected_at_gateway" time="5.147" /><testcase classname="tests.test_subscription.TestAuthEnforcement" name="test_authorized_user_gets_200" time="0.162" /><testcase classname="tests.test_subscription.TestAuthEnforcement" name="test_invalid_token_gets_403" time="0.089" /><testcase classname="tests.test_subscription.TestAuthEnforcement" name="test_wrong_group_gets_403" time="0.060" /><testcase classname="tests.test_subscription.TestAPIKeySubscriptionBinding" name="test_create_api_key_uses_highest_priority_subscription" time="2.694" /><testcase classname="tests.test_subscription.TestAPIKeySubscriptionBinding" name="test_create_api_key_with_explicit_simulator_subscription" time="0.176" /><testcase classname="tests.test_subscription.TestAPIKeySubscriptionBinding" name="test_create_api_key_nonexistent_subscription_errors" time="10.494" /><testcase classname="tests.test_subscription.TestAuthEnforcement" name="test_no_auth_gets_401" time="0.043" /><testcase classname="tests.test_subscription.TestOrderingEdgeCases" name="test_subscription_before_auth_policy" time="17.357" /><testcase classname="tests.test_api_keys.TestAPIKeyCRUD" name="test_list_api_keys" time="143.190" /><testcase classname="tests.test_api_keys.TestAPIKeyBulkOperations" name="test_bulk_revoke_by_subscription" time="15.941" /><testcase classname="tests.test_negative_security.TestInternalEndpointIsolation" name="test_internal_endpoint_not_routable[api-keys-validate]" time="0.210" /><testcase classname="tests.test_negative_security.TestInternalEndpointIsolation" name="test_internal_endpoint_not_routable[subscriptions-select]" time="0.199" /><testcase classname="tests.test_subscription.TestE2ESubscriptionFlow" name="test_e2e_with_both_access_and_subscription_gets_200" time="195.244"><failure message="TimeoutError: TokenRateLimitPolicy maas-trlp-premium-w0-42ee9d was not created and enforced in e2e-models-e2e-worker-w0-42ee9d within 180s: generation=2, observedGeneration=2, Enforced={'lastTransitionTime': '2026-10-30T13:04:53Z', 'message': 'TokenRateLimitPolicy waiting for the following components to sync: [Limitador]', 'reason': 'Unknown', 'status': 'False', 'type': 'Enforced'}, includes_subscription=True">self = &lt;test_subscription.TestE2ESubscriptionFlow object at 0x7f5d639657d0&gt;

    def test_e2e_with_both_access_and_subscription_gets_200(self):
        """
        API key with both access and subscription should get 200 OK.
    
        Uses an existing model reference that aligns with gateway path-based model identity.
        """
        ns = _ns()
        auth_policy_name = "e2e-test-auth-success"
        subscription_name = "e2e-test-subscription-success"
        sa_name = "e2e-sa-success"
    
        try:
            # Create service account and get OC token for maas-api
            oc_token = _create_sa_token(sa_name, namespace=ns)
            sa_user = _sa_to_user(sa_name, namespace=ns)
    
            # Use pre-existing premium model to keep model identity consistent with gateway path.
            _create_test_auth_policy(auth_policy_name, PREMIUM_MODEL_REF, users=[sa_user])
            _create_test_subscription(subscription_name, PREMIUM_MODEL_REF, users=[sa_user])
            _wait_for_maas_auth_policy_phase(auth_policy_name, namespace=ns, timeout=120, require_auth_policies=False)
&gt;           _wait_for_subscription_inference_ready(
                subscription_name,
                PREMIUM_MODEL_REF,
                namespace=ns,
                model_namespace=MODEL_NAMESPACE,
                timeout=180,
            )

test/maas-e2e/test/e2e/tests/test_subscription.py:1887: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
test/maas-e2e/test/e2e/tests/test_helper.py:1781: in _wait_for_subscription_inference_ready
    _wait_for_token_rate_limit_policy(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

model_ref = 'premium-w0-42ee9d'
model_namespace = 'e2e-models-e2e-worker-w0-42ee9d', timeout = 180
subscription_name = 'e2e-test-subscription-success'
subscription_namespace = 'ai-tenant-e2e-worker-w0-42ee9d'

    def _wait_for_token_rate_limit_policy(
        model_ref, model_namespace=MODEL_NAMESPACE, timeout=60, *, subscription_name=None, subscription_namespace=None
    ):
        """Wait for the current TokenRateLimitPolicy generation to be enforced.
    
        If a subscription is supplied, wait until the policy includes it. This
        prevents accepting the old policy before the controller updates its spec.
    
        Args:
            model_ref: Name of the model (e.g., "e2e-distinct-simulated")
            model_namespace: Namespace where the TRLP should be created (default: MODEL_NAMESPACE)
            timeout: Maximum wait time in seconds (default: 60)
            subscription_name: Subscription that the policy must include, if supplied
            subscription_namespace: Subscription namespace (defaults to _ns())
    
        Raises:
            TimeoutError: If TRLP isn't created and enforced within timeout
        """
        trlp_name = f"maas-trlp-{model_ref}"
        expected_subscription = (
            f"{subscription_namespace or _ns()}/{subscription_name}" if subscription_name else None
        )
        last_snapshot = "not found"
        deadline = time.time() + timeout
        log.info(f"Waiting for TokenRateLimitPolicy {trlp_name} in {model_namespace} (timeout: {timeout}s)...")
    
        while time.time() &lt; deadline:
            result = subprocess.run(
                ["oc", "get", "tokenratelimitpolicy", trlp_name, "-n", model_namespace, "-o", "json"],
                capture_output=True,
                text=True,
                timeout=30,
            )
            if result.returncode == 0:
                try:
                    trlp = json.loads(result.stdout)
                    metadata = trlp.get("metadata", {})
                    status = trlp.get("status", {})
                    generation = metadata.get("generation")
                    observed = status.get("observedGeneration")
                    conditions = status.get("conditions", [])
                    enforced = next((c for c in conditions if c.get("type") == "Enforced"), None)
                    subscriptions = {
                        name.strip()
                        for name in metadata.get("annotations", {}).get(
                            "maas.opendatahub.io/subscriptions", ""
                        ).split(",")
                    }
                    includes_subscription = expected_subscription is None or expected_subscription in subscriptions
                    last_snapshot = (
                        f"generation={generation}, observedGeneration={observed}, "
                        f"Enforced={enforced}, includes_subscription={includes_subscription}"
                    )
                    if (
                        enforced and enforced.get("status") == "True"
                        and generation is not None and observed == generation
                        and includes_subscription
                    ):
                        log.info(f"TokenRateLimitPolicy {trlp_name} generation {generation} is enforced")
                        return
                    log.debug(f"TokenRateLimitPolicy {trlp_name} is not ready: {last_snapshot}")
                except (json.JSONDecodeError, KeyError) as e:
                    log.debug(f"Failed to parse TRLP status: {e}")
            elif _is_not_found_error(result.stderr):
                log.debug(f"TokenRateLimitPolicy {trlp_name} not found yet...")
            elif _is_transient_kubectl_error(result.stderr):
                log.debug(
                    f"Transient error while reading TokenRateLimitPolicy {trlp_name}: {result.stderr.strip()}"
                )
            else:
                raise RuntimeError(
                    f"Failed to get TokenRateLimitPolicy {trlp_name} in namespace '{model_namespace}': "
                    f"{result.stderr.strip()}"
                )
            time.sleep(3)
    
&gt;       raise TimeoutError(
            f"TokenRateLimitPolicy {trlp_name} was not created and enforced in {model_namespace} within {timeout}s: {last_snapshot}"
        )
E       TimeoutError: TokenRateLimitPolicy maas-trlp-premium-w0-42ee9d was not created and enforced in e2e-models-e2e-worker-w0-42ee9d within 180s: generation=2, observedGeneration=2, Enforced={'lastTransitionTime': '2026-10-30T13:04:53Z', 'message': 'TokenRateLimitPolicy waiting for the following components to sync: [Limitador]', 'reason': 'Unknown', 'status': 'False', 'type': 'Enforced'}, includes_subscription=True

test/maas-e2e/test/e2e/tests/test_helper.py:1538: TimeoutError</failure></testcase><testcase classname="tests.test_subscription.TestSubscriptionEnforcement" name="test_subscribed_user_gets_200" time="0.252" /><testcase classname="tests.test_subscription.TestE2ESubscriptionFlow" name="test_e2e_multiple_subscriptions_separate_keys_gets_200" time="205.665"><failure message="TimeoutError: TokenRateLimitPolicy maas-trlp-simulator-w4-54994c was not created and enforced in e2e-models-e2e-worker-w4-54994c within 180s: generation=5, observedGeneration=5, Enforced={'lastTransitionTime': '2026-10-30T13:04:53Z', 'message': 'TokenRateLimitPolicy waiting for the following components to sync: [Limitador]', 'reason': 'Unknown', 'status': 'False', 'type': 'Enforced'}, includes_subscription=True">self = &lt;test_subscription.TestE2ESubscriptionFlow object at 0x7fa86deeae10&gt;

    def test_e2e_multiple_subscriptions_separate_keys_gets_200(self):
        """
        User with two subscriptions for the same model: mint one API key per subscription;
        each key succeeds on inference without x-maas-subscription.
        """
        ns = _ns()
        auth_policy_name = "e2e-test-auth-multi-sub-valid"
        subscription_1 = "e2e-test-subscription-free"
        subscription_2 = "e2e-test-subscription-premium"
        sa_name = "e2e-sa-multi-sub-valid"
    
        try:
            # Create service account and get OC token for maas-api
            oc_token = _create_sa_token(sa_name, namespace=ns)
            sa_user = _sa_to_user(sa_name, namespace=ns)
    
            # Create test resources with 2 subscriptions for the same user
            _create_test_auth_policy(auth_policy_name, MODEL_REF, users=[sa_user])
            _create_test_subscription(subscription_1, MODEL_REF, users=[sa_user], token_limit=100)
            _create_test_subscription(subscription_2, MODEL_REF, users=[sa_user], token_limit=1000)
    
            _wait_for_maas_auth_policy_phase(auth_policy_name, require_enforced=False)
&gt;           _wait_for_subscription_inference_ready(
                subscription_1,
                MODEL_REF,
                model_namespace=MODEL_NAMESPACE,
                timeout=180,
            )

test/maas-e2e/test/e2e/tests/test_subscription.py:2089: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
test/maas-e2e/test/e2e/tests/test_helper.py:1781: in _wait_for_subscription_inference_ready
    _wait_for_token_rate_limit_policy(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

model_ref = 'simulator-w4-54994c'
model_namespace = 'e2e-models-e2e-worker-w4-54994c', timeout = 180
subscription_name = 'e2e-test-subscription-free'
subscription_namespace = 'ai-tenant-e2e-worker-w4-54994c'

    def _wait_for_token_rate_limit_policy(
        model_ref, model_namespace=MODEL_NAMESPACE, timeout=60, *, subscription_name=None, subscription_namespace=None
    ):
        """Wait for the current TokenRateLimitPolicy generation to be enforced.
    
        If a subscription is supplied, wait until the policy includes it. This
        prevents accepting the old policy before the controller updates its spec.
    
        Args:
            model_ref: Name of the model (e.g., "e2e-distinct-simulated")
            model_namespace: Namespace where the TRLP should be created (default: MODEL_NAMESPACE)
            timeout: Maximum wait time in seconds (default: 60)
            subscription_name: Subscription that the policy must include, if supplied
            subscription_namespace: Subscription namespace (defaults to _ns())
    
        Raises:
            TimeoutError: If TRLP isn't created and enforced within timeout
        """
        trlp_name = f"maas-trlp-{model_ref}"
        expected_subscription = (
            f"{subscription_namespace or _ns()}/{subscription_name}" if subscription_name else None
        )
        last_snapshot = "not found"
        deadline = time.time() + timeout
        log.info(f"Waiting for TokenRateLimitPolicy {trlp_name} in {model_namespace} (timeout: {timeout}s)...")
    
        while time.time() &lt; deadline:
            result = subprocess.run(
                ["oc", "get", "tokenratelimitpolicy", trlp_name, "-n", model_namespace, "-o", "json"],
                capture_output=True,
                text=True,
                timeout=30,
            )
            if result.returncode == 0:
                try:
                    trlp = json.loads(result.stdout)
                    metadata = trlp.get("metadata", {})
                    status = trlp.get("status", {})
                    generation = metadata.get("generation")
                    observed = status.get("observedGeneration")
                    conditions = status.get("conditions", [])
                    enforced = next((c for c in conditions if c.get("type") == "Enforced"), None)
                    subscriptions = {
                        name.strip()
                        for name in metadata.get("annotations", {}).get(
                            "maas.opendatahub.io/subscriptions", ""
                        ).split(",")
                    }
                    includes_subscription = expected_subscription is None or expected_subscription in subscriptions
                    last_snapshot = (
                        f"generation={generation}, observedGeneration={observed}, "
                        f"Enforced={enforced}, includes_subscription={includes_subscription}"
                    )
                    if (
                        enforced and enforced.get("status") == "True"
                        and generation is not None and observed == generation
                        and includes_subscription
                    ):
                        log.info(f"TokenRateLimitPolicy {trlp_name} generation {generation} is enforced")
                        return
                    log.debug(f"TokenRateLimitPolicy {trlp_name} is not ready: {last_snapshot}")
                except (json.JSONDecodeError, KeyError) as e:
                    log.debug(f"Failed to parse TRLP status: {e}")
            elif _is_not_found_error(result.stderr):
                log.debug(f"TokenRateLimitPolicy {trlp_name} not found yet...")
            elif _is_transient_kubectl_error(result.stderr):
                log.debug(
                    f"Transient error while reading TokenRateLimitPolicy {trlp_name}: {result.stderr.strip()}"
                )
            else:
                raise RuntimeError(
                    f"Failed to get TokenRateLimitPolicy {trlp_name} in namespace '{model_namespace}': "
                    f"{result.stderr.strip()}"
                )
            time.sleep(3)
    
&gt;       raise TimeoutError(
            f"TokenRateLimitPolicy {trlp_name} was not created and enforced in {model_namespace} within {timeout}s: {last_snapshot}"
        )
E       TimeoutError: TokenRateLimitPolicy maas-trlp-simulator-w4-54994c was not created and enforced in e2e-models-e2e-worker-w4-54994c within 180s: generation=5, observedGeneration=5, Enforced={'lastTransitionTime': '2026-10-30T13:04:53Z', 'message': 'TokenRateLimitPolicy waiting for the following components to sync: [Limitador]', 'reason': 'Unknown', 'status': 'False', 'type': 'Enforced'}, includes_subscription=True

test/maas-e2e/test/e2e/tests/test_helper.py:1538: TimeoutError</failure></testcase><testcase classname="tests.test_subscription.TestE2ESubscriptionFlow" name="test_e2e_group_based_access_gets_200" time="197.449"><failure message="TimeoutError: TokenRateLimitPolicy maas-trlp-simulator-w3-3048f9 was not created and enforced in e2e-models-e2e-worker-w3-3048f9 within 180s: generation=8, observedGeneration=8, Enforced={'lastTransitionTime': '2026-10-30T13:04:19Z', 'message': 'TokenRateLimitPolicy waiting for the following components to sync: [Limitador]', 'reason': 'Unknown', 'status': 'False', 'type': 'Enforced'}, includes_subscription=True">self = &lt;test_subscription.TestE2ESubscriptionFlow object at 0x7efdb887d210&gt;

    def test_e2e_group_based_access_gets_200(self):
        """
        E2E test: Group-based auth and subscription (success case).
    
        Validates that users can access models via group membership in both
        MaaSAuthPolicy and MaaSSubscription, not just explicit user lists.
        """
        ns = _ns()
        auth_policy_name = "e2e-test-group-auth"
        subscription_name = "e2e-test-group-subscription"
        sa_name = "e2e-sa-group"
    
        # Use namespace-specific group that SA will be in
        test_group = f"system:serviceaccounts:{ns}"
    
        try:
            # Create service account and get OC token for maas-api
            oc_token = _create_sa_token(sa_name, namespace=ns)
    
            # Create auth policy using GROUP (not user)
            _create_test_auth_policy(auth_policy_name, MODEL_REF, groups=[test_group])
    
            # Create subscription using GROUP (not user)
            _create_test_subscription(subscription_name, MODEL_REF, groups=[test_group])
    
            _wait_for_maas_auth_policy_phase(auth_policy_name, require_enforced=False)
&gt;           _wait_for_subscription_inference_ready(
                subscription_name,
                MODEL_REF,
                model_namespace=MODEL_NAMESPACE,
                timeout=180,
            )

test/maas-e2e/test/e2e/tests/test_subscription.py:2216: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
test/maas-e2e/test/e2e/tests/test_helper.py:1781: in _wait_for_subscription_inference_ready
    _wait_for_token_rate_limit_policy(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

model_ref = 'simulator-w3-3048f9'
model_namespace = 'e2e-models-e2e-worker-w3-3048f9', timeout = 180
subscription_name = 'e2e-test-group-subscription'
subscription_namespace = 'ai-tenant-e2e-worker-w3-3048f9'

    def _wait_for_token_rate_limit_policy(
        model_ref, model_namespace=MODEL_NAMESPACE, timeout=60, *, subscription_name=None, subscription_namespace=None
    ):
        """Wait for the current TokenRateLimitPolicy generation to be enforced.
    
        If a subscription is supplied, wait until the policy includes it. This
        prevents accepting the old policy before the controller updates its spec.
    
        Args:
            model_ref: Name of the model (e.g., "e2e-distinct-simulated")
            model_namespace: Namespace where the TRLP should be created (default: MODEL_NAMESPACE)
            timeout: Maximum wait time in seconds (default: 60)
            subscription_name: Subscription that the policy must include, if supplied
            subscription_namespace: Subscription namespace (defaults to _ns())
    
        Raises:
            TimeoutError: If TRLP isn't created and enforced within timeout
        """
        trlp_name = f"maas-trlp-{model_ref}"
        expected_subscription = (
            f"{subscription_namespace or _ns()}/{subscription_name}" if subscription_name else None
        )
        last_snapshot = "not found"
        deadline = time.time() + timeout
        log.info(f"Waiting for TokenRateLimitPolicy {trlp_name} in {model_namespace} (timeout: {timeout}s)...")
    
        while time.time() &lt; deadline:
            result = subprocess.run(
                ["oc", "get", "tokenratelimitpolicy", trlp_name, "-n", model_namespace, "-o", "json"],
                capture_output=True,
                text=True,
                timeout=30,
            )
            if result.returncode == 0:
                try:
                    trlp = json.loads(result.stdout)
                    metadata = trlp.get("metadata", {})
                    status = trlp.get("status", {})
                    generation = metadata.get("generation")
                    observed = status.get("observedGeneration")
                    conditions = status.get("conditions", [])
                    enforced = next((c for c in conditions if c.get("type") == "Enforced"), None)
                    subscriptions = {
                        name.strip()
                        for name in metadata.get("annotations", {}).get(
                            "maas.opendatahub.io/subscriptions", ""
                        ).split(",")
                    }
                    includes_subscription = expected_subscription is None or expected_subscription in subscriptions
                    last_snapshot = (
                        f"generation={generation}, observedGeneration={observed}, "
                        f"Enforced={enforced}, includes_subscription={includes_subscription}"
                    )
                    if (
                        enforced and enforced.get("status") == "True"
                        and generation is not None and observed == generation
                        and includes_subscription
                    ):
                        log.info(f"TokenRateLimitPolicy {trlp_name} generation {generation} is enforced")
                        return
                    log.debug(f"TokenRateLimitPolicy {trlp_name} is not ready: {last_snapshot}")
                except (json.JSONDecodeError, KeyError) as e:
                    log.debug(f"Failed to parse TRLP status: {e}")
            elif _is_not_found_error(result.stderr):
                log.debug(f"TokenRateLimitPolicy {trlp_name} not found yet...")
            elif _is_transient_kubectl_error(result.stderr):
                log.debug(
                    f"Transient error while reading TokenRateLimitPolicy {trlp_name}: {result.stderr.strip()}"
                )
            else:
                raise RuntimeError(
                    f"Failed to get TokenRateLimitPolicy {trlp_name} in namespace '{model_namespace}': "
                    f"{result.stderr.strip()}"
                )
            time.sleep(3)
    
&gt;       raise TimeoutError(
            f"TokenRateLimitPolicy {trlp_name} was not created and enforced in {model_namespace} within {timeout}s: {last_snapshot}"
        )
E       TimeoutError: TokenRateLimitPolicy maas-trlp-simulator-w3-3048f9 was not created and enforced in e2e-models-e2e-worker-w3-3048f9 within 180s: generation=8, observedGeneration=8, Enforced={'lastTransitionTime': '2026-10-30T13:04:19Z', 'message': 'TokenRateLimitPolicy waiting for the following components to sync: [Limitador]', 'reason': 'Unknown', 'status': 'False', 'type': 'Enforced'}, includes_subscription=True

test/maas-e2e/test/e2e/tests/test_helper.py:1538: TimeoutError</failure></testcase><testcase classname="tests.test_negative_security.TestMissingModelRef" name="test_authpolicy_with_nonexistent_model_ref" time="3.213" /><testcase classname="tests.test_api_keys.TestAPIKeyLabels" name="test_labels_validation_errors" time="0.293" /><testcase classname="tests.test_subscription.TestManagedAnnotation" name="test_authpolicy_managed_false_prevents_update" time="0.321"><skipped type="pytest.skip" message="gateway-only mode: per-model AuthPolicy is not created">/workspace/source/test/maas-e2e/test/e2e/tests/test_subscription.py:1580: gateway-only mode: per-model AuthPolicy is not created</skipped></testcase><testcase classname="tests.test_subscription.TestManagedAnnotation" name="test_trlp_managed_false_prevents_update" time="308.918"><failure message="TimeoutError: TokenRateLimitPolicy maas-trlp-simulator-w1-ac0c58 was not created and enforced in e2e-models-e2e-worker-w1-ac0c58 within 300s: generation=3, observedGeneration=3, Enforced={'lastTransitionTime': '2026-10-30T13:05:08Z', 'message': 'TokenRateLimitPolicy waiting for the following components to sync: [Limitador]', 'reason': 'Unknown', 'status': 'False', 'type': 'Enforced'}, includes_subscription=True">self = &lt;test_subscription.TestManagedAnnotation object at 0x7efd87baf350&gt;

    def test_trlp_managed_false_prevents_update(self):
        """TokenRateLimitPolicy annotated with opendatahub.io/managed=false must not
        have its spec updated when the parent MaaSSubscription is modified."""
        ns = _ns()
        trlp_ns = MODEL_NAMESPACE
        parent_snapshot = None
        try:
            # 1. Verify the TRLP exists
            trlp = _get_cr("tokenratelimitpolicy", TRLP_NAME, trlp_ns)
            assert trlp, f"TokenRateLimitPolicy {TRLP_NAME} not found in {trlp_ns}"
    
            # 2. Snapshot the parent MaaSSubscription for cleanup
            parent_snapshot = _snapshot_cr(
                "maassubscription", SIMULATOR_SUBSCRIPTION, ns
            )
            assert parent_snapshot, (
                f"MaaSSubscription {SIMULATOR_SUBSCRIPTION} not found in {ns}"
            )
    
            # 3. Annotate the TRLP with managed=false
            _annotate(
                "tokenratelimitpolicy",
                TRLP_NAME,
                f"{MANAGED_ANNOTATION}=false",
                trlp_ns,
            )
            log.info(
                "Annotated TokenRateLimitPolicy %s with %s=false",
                TRLP_NAME,
                MANAGED_ANNOTATION,
            )
    
            # 4. Re-read the TRLP to capture baseline spec (post-annotation)
            trlp_baseline = _get_cr("tokenratelimitpolicy", TRLP_NAME, trlp_ns)
            assert trlp_baseline, (
                f"TokenRateLimitPolicy {TRLP_NAME} disappeared after annotation"
            )
            baseline_spec = trlp_baseline["spec"]
    
            # 5. Modify the parent MaaSSubscription (change the token rate limit value)
            modified_parent = copy.deepcopy(parent_snapshot)
            model_refs = modified_parent["spec"].get("modelRefs", [])
            assert model_refs, (
                f"MaaSSubscription {SIMULATOR_SUBSCRIPTION} has no modelRefs"
            )
            for ref in model_refs:
                if ref.get("name") == MODEL_REF:
                    limits = ref.get("tokenRateLimits", [])
                    assert limits, f"modelRef {MODEL_REF} has no tokenRateLimits"
                    limits[0]["limit"] = limits[0]["limit"] + 99999
                    break
            else:
                pytest.fail(
                    f"modelRef {MODEL_REF} not found in MaaSSubscription {SIMULATOR_SUBSCRIPTION}"
                )
            _apply_cr(modified_parent)
            log.info(
                "Modified parent MaaSSubscription %s (changed token rate limit)",
                SIMULATOR_SUBSCRIPTION,
            )
    
            # 6. Wait for the controller to reconcile the edited spec
            modified = _get_cr("maassubscription", SIMULATOR_SUBSCRIPTION, ns)
            assert modified, (
                f"MaaSSubscription {SIMULATOR_SUBSCRIPTION} disappeared after update"
            )
            reconciled = _wait_for_subscription_generation_observed(
                SIMULATOR_SUBSCRIPTION,
                modified["metadata"]["generation"],
                namespace=ns,
            )
            # An unchanged TRLP only proves managed=false if the reconcile got
            # to the TRLP step: the model was valid and the step did not fail.
            # Degraded is expected while Kuadrant has not enforced the policy.
            status = reconciled.get("status", {})
            model_ready = any(
                s.get("name") == MODEL_REF and s.get("ready") is True
                for s in status.get("modelRefStatuses", [])
            )
            assert model_ready and status.get("phase") in ("Active", "Degraded"), (
                f"MaaSSubscription {SIMULATOR_SUBSCRIPTION} reconciled without "
                f"reaching the TRLP step: {status}"
            )
    
            # 7. Re-read the TRLP and compare spec
            trlp_after = _get_cr("tokenratelimitpolicy", TRLP_NAME, trlp_ns)
            assert trlp_after, (
                f"TokenRateLimitPolicy {TRLP_NAME} disappeared after parent update"
            )
            after_spec = trlp_after["spec"]
    
            assert baseline_spec == after_spec, (
                f"TokenRateLimitPolicy spec changed despite {MANAGED_ANNOTATION}=false.\n"
                f"Before: {json.dumps(baseline_spec, indent=2)}\n"
                f"After:  {json.dumps(after_spec, indent=2)}"
            )
            log.info(
                "TokenRateLimitPolicy spec unchanged after parent modification — managed=false respected"
            )
    
        finally:
            # Remove the annotation (best-effort so parent restore still runs)
            try:
                _annotate(
                    "tokenratelimitpolicy", TRLP_NAME, f"{MANAGED_ANNOTATION}-", trlp_ns
                )
                log.info(
                    "Removed %s annotation from TokenRateLimitPolicy %s",
                    MANAGED_ANNOTATION,
                    TRLP_NAME,
                )
            except subprocess.CalledProcessError:
                log.warning(
                    "Failed to remove %s annotation from TokenRateLimitPolicy %s (may not exist)",
                    MANAGED_ANNOTATION,
                    TRLP_NAME,
                )
    
            # Restore the parent MaaSSubscription
            if parent_snapshot:
                _apply_cr(parent_snapshot)
                log.info(
                    "Restored parent MaaSSubscription %s from snapshot",
                    SIMULATOR_SUBSCRIPTION,
                )
&gt;               _wait_for_subscription_inference_ready(
                    SIMULATOR_SUBSCRIPTION,
                    MODEL_REF,
                    model_namespace=MODEL_NAMESPACE,
                )

test/maas-e2e/test/e2e/tests/test_subscription.py:1789: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
test/maas-e2e/test/e2e/tests/test_helper.py:1781: in _wait_for_subscription_inference_ready
    _wait_for_token_rate_limit_policy(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

model_ref = 'simulator-w1-ac0c58'
model_namespace = 'e2e-models-e2e-worker-w1-ac0c58', timeout = 300
subscription_name = 'simulator-subscription'
subscription_namespace = 'ai-tenant-e2e-worker-w1-ac0c58'

    def _wait_for_token_rate_limit_policy(
        model_ref, model_namespace=MODEL_NAMESPACE, timeout=60, *, subscription_name=None, subscription_namespace=None
    ):
        """Wait for the current TokenRateLimitPolicy generation to be enforced.
    
        If a subscription is supplied, wait until the policy includes it. This
        prevents accepting the old policy before the controller updates its spec.
    
        Args:
            model_ref: Name of the model (e.g., "e2e-distinct-simulated")
            model_namespace: Namespace where the TRLP should be created (default: MODEL_NAMESPACE)
            timeout: Maximum wait time in seconds (default: 60)
            subscription_name: Subscription that the policy must include, if supplied
            subscription_namespace: Subscription namespace (defaults to _ns())
    
        Raises:
            TimeoutError: If TRLP isn't created and enforced within timeout
        """
        trlp_name = f"maas-trlp-{model_ref}"
        expected_subscription = (
            f"{subscription_namespace or _ns()}/{subscription_name}" if subscription_name else None
        )
        last_snapshot = "not found"
        deadline = time.time() + timeout
        log.info(f"Waiting for TokenRateLimitPolicy {trlp_name} in {model_namespace} (timeout: {timeout}s)...")
    
        while time.time() &lt; deadline:
            result = subprocess.run(
                ["oc", "get", "tokenratelimitpolicy", trlp_name, "-n", model_namespace, "-o", "json"],
                capture_output=True,
                text=True,
                timeout=30,
            )
            if result.returncode == 0:
                try:
                    trlp = json.loads(result.stdout)
                    metadata = trlp.get("metadata", {})
                    status = trlp.get("status", {})
                    generation = metadata.get("generation")
                    observed = status.get("observedGeneration")
                    conditions = status.get("conditions", [])
                    enforced = next((c for c in conditions if c.get("type") == "Enforced"), None)
                    subscriptions = {
                        name.strip()
                        for name in metadata.get("annotations", {}).get(
                            "maas.opendatahub.io/subscriptions", ""
                        ).split(",")
                    }
                    includes_subscription = expected_subscription is None or expected_subscription in subscriptions
                    last_snapshot = (
                        f"generation={generation}, observedGeneration={observed}, "
                        f"Enforced={enforced}, includes_subscription={includes_subscription}"
                    )
                    if (
                        enforced and enforced.get("status") == "True"
                        and generation is not None and observed == generation
                        and includes_subscription
                    ):
                        log.info(f"TokenRateLimitPolicy {trlp_name} generation {generation} is enforced")
                        return
                    log.debug(f"TokenRateLimitPolicy {trlp_name} is not ready: {last_snapshot}")
                except (json.JSONDecodeError, KeyError) as e:
                    log.debug(f"Failed to parse TRLP status: {e}")
            elif _is_not_found_error(result.stderr):
                log.debug(f"TokenRateLimitPolicy {trlp_name} not found yet...")
            elif _is_transient_kubectl_error(result.stderr):
                log.debug(
                    f"Transient error while reading TokenRateLimitPolicy {trlp_name}: {result.stderr.strip()}"
                )
            else:
                raise RuntimeError(
                    f"Failed to get TokenRateLimitPolicy {trlp_name} in namespace '{model_namespace}': "
                    f"{result.stderr.strip()}"
                )
            time.sleep(3)
    
&gt;       raise TimeoutError(
            f"TokenRateLimitPolicy {trlp_name} was not created and enforced in {model_namespace} within {timeout}s: {last_snapshot}"
        )
E       TimeoutError: TokenRateLimitPolicy maas-trlp-simulator-w1-ac0c58 was not created and enforced in e2e-models-e2e-worker-w1-ac0c58 within 300s: generation=3, observedGeneration=3, Enforced={'lastTransitionTime': '2026-10-30T13:05:08Z', 'message': 'TokenRateLimitPolicy waiting for the following components to sync: [Limitador]', 'reason': 'Unknown', 'status': 'False', 'type': 'Enforced'}, includes_subscription=True

test/maas-e2e/test/e2e/tests/test_helper.py:1538: TimeoutError</failure></testcase><testcase classname="tests.test_subscription.TestStatusReporting" name="test_subscription_active_status_with_valid_model" time="70.848" /><testcase classname="tests.test_subscription.TestStatusReporting" name="test_authpolicy_active_status_with_valid_model" time="3.607" /><testcase classname="tests.test_subscription.TestDegradedSubscriptionFiltering" name="test_degraded_healthy_model_allows_inference" time="14.284" /><testcase classname="tests.test_subscription.TestStatusReporting" name="test_subscription_degraded_status_with_partial_models" time="88.254" /><testcase classname="tests.test_subscription.TestDegradedSubscriptionFiltering" name="test_models_endpoint_with_degraded_subscription_api_key" time="14.452" /><testcase classname="tests.test_subscription.TestStatusReporting" name="test_authpolicy_degraded_status_with_partial_models" time="3.430" /><testcase classname="tests.test_subscription.TestStatusReporting" name="test_subscription_failed_status_with_missing_model" time="106.177" /><testcase classname="tests.test_subscription_list_endpoints.TestListSubscriptions" name="test_returns_accessible_subscriptions" time="6.824" /><testcase classname="tests.test_subscription.TestDegradedSubscriptionFiltering" name="test_models_endpoint_with_degraded_subscription_kube_token" time="14.148" /><testcase classname="tests.test_subscription_list_endpoints.TestListSubscriptions" name="test_unauthenticated_returns_401[all-subscriptions]" time="0.066" /><testcase classname="tests.test_subscription_list_endpoints.TestListSubscriptions" name="test_subscription_includes_model_refs" time="14.036" /><testcase classname="tests.test_subscription.TestStatusReporting" name="test_authpolicy_failed_status_with_missing_model" time="22.721" /><testcase classname="tests.test_subscription_list_endpoints.TestListSubscriptions" name="test_model_ref_display_name_and_description_enriched" time="13.711" /><testcase classname="tests.test_subscription_list_endpoints.TestListSubscriptions" name="test_unauthenticated_returns_401[subscriptions-for-model]" time="4.270" /><testcase classname="tests.test_subscription_list_endpoints.TestListSubscriptionsForModel" name="test_unknown_model_returns_empty" time="0.625" /><testcase classname="tests.test_subscription_list_endpoints.TestSubscriptionModelAccessFiltering" name="test_omits_subscription_with_no_authorized_models" time="10.952" /><testcase classname="tests.test_subscription_list_endpoints.TestSubscriptionModelAccessFiltering" name="test_filters_unauthorized_models" time="14.465" /><testcase classname="tests.test_subscription_list_endpoints.TestListSubscriptionsForModel" name="test_returns_subscriptions_for_model" time="36.548" /><testcase classname="tests.test_models_endpoint.TestModelsEndpoint" name="test_empty_subscription_header_value" time="10.543" /><testcase classname="tests.test_models_endpoint.TestModelsEndpoint" name="test_user_token_returns_all_models" time="25.752" /><testcase classname="tests.test_models_endpoint.TestModelsEndpoint" name="test_multiple_distinct_models_in_subscription" time="19.619" /><testcase classname="tests.test_models_endpoint.TestModelsEndpoint" name="test_response_schema_and_metadata" time="0.600" /><testcase classname="tests.test_models_endpoint.TestModelsEndpoint" name="test_api_key_scoped_to_subscription" time="17.955" /><testcase classname="tests.test_models_endpoint.TestModelsEndpoint" name="test_user_token_with_subscription_header_filters" time="15.744" /><testcase classname="tests.test_models_endpoint.TestModelsEndpoint" name="test_deduplication_same_model_multiple_refs" time="22.717" /><testcase classname="tests.test_models_endpoint.TestModelsEndpoint" name="test_api_key_with_inaccessible_subscription_403" time="14.914" /><testcase classname="tests.test_models_endpoint.TestModelsEndpoint" name="test_invalid_subscription_header_403" time="14.583" /><testcase classname="tests.test_models_endpoint.TestModelsEndpoint" name="test_api_key_with_deleted_subscription_403" time="45.140" /><testcase classname="tests.test_subscription.TestE2ESubscriptionFlow" name="test_e2e_with_subscription_but_no_access_gets_403" time="12.904" /><testcase classname="tests.test_subscription.TestE2ESubscriptionFlow" name="test_e2e_group_based_subscription_but_no_auth_gets_403" time="13.073" /><testcase classname="tests.test_models_endpoint.TestModelsEndpoint" name="test_access_denied_to_subscription_403" time="24.285" /><testcase classname="tests.test_models_endpoint.TestModelsEndpoint" name="test_api_key_ignores_subscription_header" time="24.091" /><testcase classname="tests.test_subscription.TestE2ESubscriptionFlow" name="test_e2e_mint_api_key_denied_for_inaccessible_subscription" time="28.774"><failure message="AssertionError: Expected 400, got 500: Internal Server Error.&#10;  &#10;assert 500 == 400&#10; +  where 500 = &lt;Response [500]&gt;.status_code">self = &lt;test_subscription.TestE2ESubscriptionFlow object at 0x7fa86deeaf50&gt;

    def test_e2e_mint_api_key_denied_for_inaccessible_subscription(self):
        """POST /v1/api-keys with another user's subscription returns generic invalid_subscription."""
        ns = _ns()
        auth_policy_name = "e2e-test-auth-access-denied"
        user_subscription = "e2e-test-user-subscription"
        other_subscription = "e2e-test-other-subscription"
        sa_user = "e2e-sa-user"
        sa_other = "e2e-sa-other"
    
        try:
            # Create two service accounts
            oc_token_user = _create_sa_token(sa_user, namespace=ns)
            _ = _create_sa_token(sa_other, namespace=ns)  # SA creation only - token unused
    
            user_principal = _sa_to_user(sa_user, namespace=ns)
            other_principal = _sa_to_user(sa_other, namespace=ns)
    
            # Create test resources
            # Both users have access to the model
            _create_test_auth_policy(auth_policy_name, MODEL_REF, users=[user_principal, other_principal])
            # Each user has their own subscription
            _create_test_subscription(user_subscription, MODEL_REF, users=[user_principal])
            _create_test_subscription(other_subscription, MODEL_REF, users=[other_principal])
    
            _wait_for_maas_auth_policy_phase(auth_policy_name, require_enforced=False)
            _wait_for_subscription_discovery_ready(user_subscription)
            _wait_for_subscription_discovery_ready(other_subscription)
    
            # Retry on empty 403 from gateway propagation delay (Envoy may not
            # have loaded the AuthPolicy yet).
            url = f"{_maas_api_url()}/v1/api-keys"
            retries, delay = 6, 5
            for attempt in range(1, retries + 1):
                r = requests.post(
                    url,
                    headers={
                        "Authorization": f"Bearer {oc_token_user}",
                        "Content-Type": "application/json",
                    },
                    json={"name": f"{sa_user}-bad-sub-key", "subscription": other_subscription},
                    timeout=TIMEOUT,
                    verify=TLS_VERIFY,
                )
                if r.status_code == 403 and not r.text.strip():
                    if attempt &lt; retries:
                        log.info("Gateway returned empty 403 (attempt %d/%d), retrying in %ds...",
                                 attempt, retries, delay)
                        time.sleep(delay)
                        continue
                break
&gt;           assert r.status_code == 400, f"Expected 400, got {r.status_code}: {r.text[:500]}"
E           AssertionError: Expected 400, got 500: Internal Server Error.
E             
E           assert 500 == 400
E            +  where 500 = &lt;Response [500]&gt;.status_code

test/maas-e2e/test/e2e/tests/test_subscription.py:2178: AssertionError</failure></testcase><testcase classname="tests.test_models_endpoint.TestModelsEndpoint" name="test_unauthenticated_request_401" time="0.055" /><testcase classname="tests.test_smoke" name="test_chat_completions_streaming_sse" time="0.362" /><testcase classname="tests.test_smoke" name="test_legacy_completions_optionally" time="0.085" /><testcase classname="tests.test_smoke" name="test_healthz_or_404" time="0.036" /><testcase classname="tests.test_tenant.TestTenantLifecycle" name="test_tenant_ready_and_phase_healthy" time="0.453" /><testcase classname="tests.test_tenant.TestTenantContract" name="test_status_has_phase_and_conditions" time="0.150" /><testcase classname="tests.test_tenant.TestTenantContract" name="test_spec_is_well_formed" time="0.450" /><testcase classname="tests.test_tenant.TestTenantNoFalseOwnership" name="test_maas_user_crs_not_owned_by_tenant" time="0.467" /><testcase classname="tests.test_tenant.TestTenantContract" name="test_conditions_use_kubernetes_metav1_shape" time="0.149" /><testcase classname="tests.test_config_tenant.TestConfigAnchorPresence" name="test_cluster_config_not_terminating" time="0.568" /><testcase classname="tests.test_config_tenant.TestConfigTenantOwnership" name="test_default_aitenant_lists_config_owner_reference" time="0.143" /><testcase classname="tests.test_config_tenant.TestConfigAnchorPresence" name="test_cluster_config_default_exists" time="0.544" /><testcase classname="tests.test_config_tenant.TestConfigTenantOwnership" name="test_maas_controller_deployment_does_not_list_config_owner_reference" time="0.157" /><testcase classname="tests.test_config_tenant.TestConfigTenantOwnership" name="test_tenant_config_lists_config_owner_reference" time="0.147" /><testcase classname="tests.test_tenant_discovery" name="test_tenant_discovery_requires_auth" time="23.412" /><testcase classname="tests.test_tenant_discovery" name="test_tenant_discovery_with_invalid_token" time="6.765" /><testcase classname="tests.test_smoke" name="test_tokens_endpoint_replaced_by_api_keys" time="1.523" /><testcase classname="tests.test_tenant_discovery" name="test_tenant_discovery_not_exposed_through_gateway" time="0.156" /><testcase classname="tests.test_tenant_discovery" name="test_tenant_discovery_gateway_matches_deployment" time="0.001"><skipped type="pytest.skip" message="Skipping when Gateway uses ClusterIP + OpenShift Route (unsupported configuration). This mixes incompatible routing paradigms. Gateway has no external hostname in spec.listeners, so /v1/tenants returns an error. Supported configuration: LoadBalancer service with hostname in spec.listeners.">/workspace/source/test/maas-e2e/test/e2e/tests/test_tenant_discovery.py:155: Skipping when Gateway uses ClusterIP + OpenShift Route (unsupported configuration). This mixes incompatible routing paradigms. Gateway has no external hostname in spec.listeners, so /v1/tenants returns an error. Supported configuration: LoadBalancer service with hostname in spec.listeners.</skipped></testcase><testcase classname="tests.test_aitenant_lifecycle.TestAITenantLifecycle" name="test_default_aitenant_bootstraps_maas_tenant_config_without_gateway_mutation" time="2.475" /><testcase classname="tests.test_aitenant_lifecycle.TestAITenantLifecycle" name="test_aitenant_create_bootstrap_resources" time="80.366" /><testcase classname="tests.test_models_endpoint.TestModelsEndpoint" name="test_multiple_api_keys_different_subscriptions" time="28.776" /><testcase classname="tests.test_aitenant_lifecycle.TestAITenantLifecycle" name="test_aitenant_rejected_outside_ai_tenants_namespace" time="9.422" /><testcase classname="tests.test_aitenant_lifecycle.TestAITenantLifecycle" name="test_aitenant_derives_non_default_tenant_namespace" time="82.563" /><testcase classname="tests.test_tenant_discovery" name="test_tenant_discovery_authenticated" time="0.001"><skipped type="pytest.skip" message="Skipping when Gateway uses ClusterIP + OpenShift Route (unsupported configuration). This mixes incompatible routing paradigms. Gateway has no external hostname in spec.listeners, so /v1/tenants returns an error. Supported configuration: LoadBalancer service with hostname in spec.listeners.">/workspace/source/test/maas-e2e/test/e2e/tests/test_tenant_discovery.py:79: Skipping when Gateway uses ClusterIP + OpenShift Route (unsupported configuration). This mixes incompatible routing paradigms. Gateway has no external hostname in spec.listeners, so /v1/tenants returns an error. Supported configuration: LoadBalancer service with hostname in spec.listeners.</skipped></testcase><testcase classname="tests.test_tenant_namespace_discovery.TestTenantNamespaceDiscovery" name="test_label_removal_stops_reconciliation" time="117.897" /><testcase classname="tests.test_aitenant_lifecycle.TestAITenantLifecycle" name="test_aitenant_delete_cleans_maas_resources_and_preserves_user_objects" time="77.968" /><testcase classname="tests.test_models_endpoint.TestModelsEndpoint" name="test_service_account_token_multiple_subs_no_header" time="118.403" /><testcase classname="tests.test_models_endpoint.TestModelsEndpoint" name="test_service_account_token_multiple_subs_with_header" time="137.602" /><testcase classname="tests.test_aitenant_lifecycle.TestAITenantLifecycle" name="test_aitenant_migrates_and_removes_legacy_tenant" time="76.214" /><testcase classname="tests.test_smoke" name="test_models_catalog" time="58.230" /><testcase classname="tests.test_tenant_namespace_discovery.TestTenantNamespaceDiscovery" name="test_labeled_tenant_namespace_is_discovered" time="139.094" /><testcase classname="tests.test_tenant_namespace_discovery.TestTenantNamespaceDiscovery" name="test_dynamic_discovery_after_label_added" time="139.379" /><testcase classname="tests.test_smoke" name="test_chat_completions_gateway_alive" time="49.403" /><testcase classname="tests.test_tenant_namespace_discovery.TestTenantNamespaceDiscovery" name="test_unlabeled_namespace_ignored" time="141.533" /><testcase classname="tests.test_subscription.TestStatusReporting" name="test_subscription_status_transitions_on_model_deletion" time="139.618" /><testcase classname="tests.test_tenant_namespace_discovery.TestTenantNamespaceDiscovery" name="test_per_tenant_oidc_configuration" time="36.212"><skipped type="pytest.skip" message="OIDC_ISSUER_URL not set; per-tenant OIDC E2E requires external OIDC deploy">/workspace/source/test/maas-e2e/test/e2e/tests/test_tenant_namespace_discovery.py:190: OIDC_ISSUER_URL not set; per-tenant OIDC E2E requires external OIDC deploy</skipped></testcase></testsuite></testsuites>