-
Notifications
You must be signed in to change notification settings - Fork 64
tests(maas): add multiple auth policy and cascade deletion tests #1220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dbasunag
merged 6 commits into
opendatahub-io:main
from
SB159:feature/test-multiple-auth-policies-per-model
Mar 17, 2026
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
151d6e1
tests(maas): add multiple auth policy and cascade deletion tests
SB159 f5eb149
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] cd56cc2
tests(maas): fix address coderabit review comments
SB159 1eaae51
address review comments
SB159 3606ea7
address review comments
SB159 dcc5f91
Merge branch 'main' into feature/test-multiple-auth-policies-per-model
dbasunag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
tests/model_serving/maas_billing/maas_subscription/test_cascade_deletion.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
| import requests | ||
| from kubernetes.dynamic import DynamicClient | ||
| from simple_logger.logger import get_logger | ||
|
|
||
| from tests.model_serving.maas_billing.maas_subscription.utils import ( | ||
| chat_payload_for_url, | ||
| poll_expected_status, | ||
| ) | ||
| from utilities.resources.maa_s_subscription import MaaSSubscription | ||
|
|
||
| LOGGER = get_logger(name=__name__) | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures( | ||
| "maas_unprivileged_model_namespace", | ||
| "maas_subscription_controller_enabled_latest", | ||
| "maas_gateway_api", | ||
| "maas_api_gateway_reachable", | ||
| "maas_inference_service_tinyllama_free", | ||
| "maas_model_tinyllama_free", | ||
| "maas_auth_policy_tinyllama_free", | ||
| "maas_subscription_tinyllama_free", | ||
| ) | ||
| class TestCascadeDeletion: | ||
| """ | ||
| Tests that deleting MaaSSubscription CRs triggers proper cleanup/rebuild behavior. | ||
| """ | ||
|
|
||
| @pytest.mark.tier1 | ||
| @pytest.mark.parametrize("ocp_token_for_actor", [{"type": "free"}], indirect=True) | ||
| def test_delete_subscription_rebuilds_trlp( | ||
| self, | ||
| request_session_http: requests.Session, | ||
| model_url_tinyllama_free: str, | ||
| maas_headers_for_actor_api_key: dict[str, str], | ||
| temporary_system_authenticated_subscription: MaaSSubscription, | ||
| ) -> None: | ||
| """ | ||
| Add a second subscription for the same model, then delete it. | ||
| Verify the original subscription still allows access (HTTP 200). | ||
| """ | ||
|
|
||
| LOGGER.info(f"Deleting temporary subscription {temporary_system_authenticated_subscription.name}") | ||
|
|
||
| temporary_system_authenticated_subscription.clean_up(wait=True) | ||
|
|
||
| payload = chat_payload_for_url(model_url=model_url_tinyllama_free) | ||
|
|
||
| response = poll_expected_status( | ||
| request_session_http=request_session_http, | ||
| model_url=model_url_tinyllama_free, | ||
| headers=maas_headers_for_actor_api_key, | ||
| payload=payload, | ||
| expected_statuses={200}, | ||
| wait_timeout=240, | ||
| sleep=5, | ||
| request_timeout=60, | ||
| ) | ||
|
|
||
| assert response.status_code == 200, ( | ||
| f"Expected HTTP 200 after deleting temporary subscription and rebuilding policies, " | ||
| f"but received {response.status_code}: {(response.text or '')[:200]}" | ||
| ) | ||
|
|
||
| @pytest.mark.tier1 | ||
| @pytest.mark.parametrize("ocp_token_for_actor", [{"type": "free"}], indirect=True) | ||
| def test_delete_last_subscription_denies_access( | ||
| self, | ||
| request_session_http: requests.Session, | ||
| admin_client: DynamicClient, | ||
| maas_free_group: str, | ||
| maas_model_tinyllama_free, | ||
| model_url_tinyllama_free: str, | ||
| maas_headers_for_actor_api_key: dict[str, str], | ||
| maas_subscription_tinyllama_free: MaaSSubscription, | ||
| ) -> None: | ||
| """ | ||
| Delete the only/original subscription for the model. | ||
| Verify access is denied with 403 or 429. | ||
|
|
||
| Expected behavior: | ||
| - 403 if auth policy denies because no valid subscription exists | ||
| - 429 if default deny token rate limit policy applies first | ||
|
|
||
| Both mean: no subscription => no access. | ||
| """ | ||
|
|
||
| original_name = maas_subscription_tinyllama_free.name | ||
| original_priority = getattr(maas_subscription_tinyllama_free, "priority", 0) | ||
|
|
||
| LOGGER.info("Deleting original subscription %s", original_name) | ||
| maas_subscription_tinyllama_free.clean_up(wait=True) | ||
|
SB159 marked this conversation as resolved.
|
||
|
|
||
| payload = chat_payload_for_url(model_url=model_url_tinyllama_free) | ||
|
|
||
| try: | ||
| response = poll_expected_status( | ||
| request_session_http=request_session_http, | ||
| model_url=model_url_tinyllama_free, | ||
| headers=maas_headers_for_actor_api_key, | ||
| payload=payload, | ||
| expected_statuses={403, 429}, | ||
| wait_timeout=120, | ||
| sleep=5, | ||
| request_timeout=60, | ||
| ) | ||
|
|
||
| LOGGER.info( | ||
| "No subscription present for model %s -> received %s as expected", | ||
| maas_model_tinyllama_free.name, | ||
| response.status_code, | ||
| ) | ||
|
|
||
| assert response.status_code in {403, 429}, ( | ||
| "Expected 403 or 429 after deleting the last subscription, " | ||
| f"got {response.status_code}: {(response.text or '')[:200]}" | ||
| ) | ||
| finally: | ||
| with MaaSSubscription( | ||
|
dbasunag marked this conversation as resolved.
Outdated
|
||
| client=admin_client, | ||
| name=original_name, | ||
| namespace=maas_subscription_tinyllama_free.namespace, | ||
| owner={ | ||
| "groups": [{"name": maas_free_group}], | ||
| }, | ||
| model_refs=[ | ||
| { | ||
| "name": maas_model_tinyllama_free.name, | ||
| "namespace": maas_model_tinyllama_free.namespace, | ||
| "tokenRateLimits": [{"limit": 100, "window": "1m"}], | ||
| } | ||
| ], | ||
| priority=original_priority, | ||
| teardown=False, | ||
| wait_for_resource=True, | ||
| ) as restored_subscription: | ||
| restored_subscription.wait_for_condition( | ||
| condition="Ready", | ||
| status="True", | ||
| timeout=300, | ||
| ) | ||
| LOGGER.info("Restored original subscription %s", restored_subscription.name) | ||
131 changes: 131 additions & 0 deletions
131
tests/model_serving/maas_billing/maas_subscription/test_multiple_auth_policies_per_model.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
| import requests | ||
| from simple_logger.logger import get_logger | ||
|
|
||
| from tests.model_serving.maas_billing.maas_subscription.utils import ( | ||
| chat_payload_for_url, | ||
| poll_expected_status, | ||
| ) | ||
|
|
||
| LOGGER = get_logger(name=__name__) | ||
|
|
||
| MAAS_SUBSCRIPTION_HEADER = "x-maas-subscription" | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures( | ||
| "maas_unprivileged_model_namespace", | ||
| "maas_subscription_controller_enabled_latest", | ||
| "maas_gateway_api", | ||
| "maas_api_gateway_reachable", | ||
| "maas_inference_service_tinyllama_premium", | ||
| "maas_model_tinyllama_premium", | ||
| "maas_auth_policy_tinyllama_premium", | ||
| "maas_subscription_tinyllama_premium", | ||
| ) | ||
| class TestMultipleAuthPoliciesPerModel: | ||
| @pytest.mark.smoke | ||
| @pytest.mark.parametrize("ocp_token_for_actor", [{"type": "free"}], indirect=True) | ||
| def test_premium_model_denies_free_actor_by_default( | ||
| self, | ||
| request_session_http: requests.Session, | ||
| model_url_tinyllama_premium: str, | ||
| maas_subscription_tinyllama_premium, | ||
| maas_headers_for_actor_api_key: dict[str, str], | ||
| ) -> None: | ||
| """ | ||
| Verify FREE actor is denied by default on the premium model. | ||
| """ | ||
|
|
||
| baseline_headers = dict(maas_headers_for_actor_api_key) | ||
| baseline_headers[MAAS_SUBSCRIPTION_HEADER] = maas_subscription_tinyllama_premium.name | ||
| baseline_payload = chat_payload_for_url(model_url=model_url_tinyllama_premium) | ||
|
|
||
| baseline_response = poll_expected_status( | ||
| request_session_http=request_session_http, | ||
| model_url=model_url_tinyllama_premium, | ||
| headers=baseline_headers, | ||
| payload=baseline_payload, | ||
| expected_statuses={403}, | ||
| ) | ||
|
|
||
| assert baseline_response.status_code == 403, ( | ||
| f"Expected baseline 403 for FREE actor on premium model, got " | ||
| f"{baseline_response.status_code}: {(baseline_response.text or '')[:200]}" | ||
| ) | ||
|
|
||
| @pytest.mark.smoke | ||
| @pytest.mark.parametrize("ocp_token_for_actor", [{"type": "free"}], indirect=True) | ||
| def test_two_auth_policies_or_logic_allows_access( | ||
| self, | ||
| request_session_http: requests.Session, | ||
| model_url_tinyllama_premium: str, | ||
| maas_headers_for_actor_api_key: dict[str, str], | ||
| premium_system_authenticated_access, | ||
| ) -> None: | ||
| """ | ||
| Verify FREE actor can access the premium model when an extra AuthPolicy | ||
| and matching subscription for system:authenticated exist. | ||
| """ | ||
|
|
||
| payload = chat_payload_for_url(model_url=model_url_tinyllama_premium) | ||
| explicit_headers = dict(maas_headers_for_actor_api_key) | ||
| explicit_headers[MAAS_SUBSCRIPTION_HEADER] = premium_system_authenticated_access["subscription"].name | ||
|
|
||
| LOGGER.info( | ||
| f"Polling for 200 on premium model with OR auth policy: " | ||
| f"auth_policy={premium_system_authenticated_access['auth_policy'].name}, " | ||
| f"subscription={premium_system_authenticated_access['subscription'].name}" | ||
| ) | ||
|
|
||
| response = poll_expected_status( | ||
| request_session_http=request_session_http, | ||
| model_url=model_url_tinyllama_premium, | ||
| headers=explicit_headers, | ||
| payload=payload, | ||
| expected_statuses={200}, | ||
| ) | ||
|
|
||
| assert response.status_code == 200, ( | ||
| f"Expected 200 with second AuthPolicy (OR logic), got {response.status_code}: {(response.text or '')[:200]}" | ||
| ) | ||
|
|
||
| @pytest.mark.tier1 | ||
| @pytest.mark.parametrize("ocp_token_for_actor", [{"type": "free"}], indirect=True) | ||
| def test_delete_extra_auth_policy_denies_access_on_premium_model( | ||
| self, | ||
| request_session_http: requests.Session, | ||
| model_url_tinyllama_premium: str, | ||
| maas_headers_for_actor_api_key: dict[str, str], | ||
| premium_system_authenticated_access, | ||
| ) -> None: | ||
| """ | ||
| Verify FREE actor loses access again after the extra AuthPolicy is deleted. | ||
| """ | ||
|
|
||
| payload = chat_payload_for_url(model_url=model_url_tinyllama_premium) | ||
| explicit_headers = dict(maas_headers_for_actor_api_key) | ||
| explicit_headers[MAAS_SUBSCRIPTION_HEADER] = premium_system_authenticated_access["subscription"].name | ||
|
|
||
| poll_expected_status( | ||
| request_session_http=request_session_http, | ||
| model_url=model_url_tinyllama_premium, | ||
| headers=explicit_headers, | ||
| payload=payload, | ||
| expected_statuses={200}, | ||
| ) | ||
|
|
||
| premium_system_authenticated_access["auth_policy"].delete(wait=True) | ||
|
|
||
| response = poll_expected_status( | ||
| request_session_http=request_session_http, | ||
| model_url=model_url_tinyllama_premium, | ||
| headers=explicit_headers, | ||
| payload=payload, | ||
| expected_statuses={403}, | ||
| ) | ||
|
|
||
| assert response.status_code == 403, ( | ||
| f"Expected 403 after deleting extra AuthPolicy, got {response.status_code}: {(response.text or '')[:200]}" | ||
| ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.