|
34 | 34 | from pytest_testconfig import config as py_config |
35 | 35 | from model_registry.types import RegisteredModel |
36 | 36 |
|
37 | | -from tests.model_registry.rbac.utils import wait_for_oauth_openshift_deployment, get_byoidc_user_credentials |
38 | | -from tests.model_registry.utils import generate_namespace_name, get_rest_headers, wait_for_default_resource_cleanedup |
| 37 | +from tests.model_registry.rbac.utils import wait_for_oauth_openshift_deployment |
| 38 | +from tests.model_registry.utils import ( |
| 39 | + generate_namespace_name, |
| 40 | + get_rest_headers, |
| 41 | + wait_for_default_resource_cleanedup, |
| 42 | + get_byoidc_user_credentials, |
| 43 | +) |
39 | 44 | from utilities.general import generate_random_name, wait_for_pods_running |
40 | 45 |
|
41 | 46 | from tests.model_registry.constants import ( |
@@ -486,7 +491,7 @@ def test_idp_user( |
486 | 491 | original_user: str, |
487 | 492 | api_server_url: str, |
488 | 493 | is_byoidc: bool, |
489 | | -) -> Generator[UserTestSession, None, None]: |
| 494 | +) -> Generator[UserTestSession | None, None, None]: |
490 | 495 | """ |
491 | 496 | Session-scoped fixture that creates a test IDP user and cleans it up after all tests. |
492 | 497 | Returns a UserTestSession object that contains all necessary credentials and contexts. |
@@ -545,56 +550,62 @@ def original_user() -> str: |
545 | 550 |
|
546 | 551 | @pytest.fixture(scope="module") |
547 | 552 | def created_htpasswd_secret( |
548 | | - original_user: str, user_credentials_rbac: dict[str, str] |
549 | | -) -> Generator[UserTestSession, None, None]: |
| 553 | + is_byoidc: bool, original_user: str, user_credentials_rbac: dict[str, str] |
| 554 | +) -> Generator[UserTestSession | None, None, None]: |
550 | 555 | """ |
551 | 556 | Session-scoped fixture that creates a test IDP user and cleans it up after all tests. |
552 | 557 | Returns a UserTestSession object that contains all necessary credentials and contexts. |
553 | 558 | """ |
| 559 | + if is_byoidc: |
| 560 | + yield |
554 | 561 |
|
555 | | - temp_path, htpasswd_b64 = create_htpasswd_file( |
556 | | - username=user_credentials_rbac["username"], password=user_credentials_rbac["password"] |
557 | | - ) |
558 | | - try: |
559 | | - LOGGER.info(f"Creating secret {user_credentials_rbac['secret_name']} in openshift-config namespace") |
560 | | - with Secret( |
561 | | - name=user_credentials_rbac["secret_name"], |
562 | | - namespace="openshift-config", |
563 | | - htpasswd=htpasswd_b64, |
564 | | - type="Opaque", |
565 | | - wait_for_resource=True, |
566 | | - ) as secret: |
567 | | - yield secret |
568 | | - finally: |
569 | | - # Clean up the temporary file |
570 | | - temp_path.unlink(missing_ok=True) |
| 562 | + else: |
| 563 | + temp_path, htpasswd_b64 = create_htpasswd_file( |
| 564 | + username=user_credentials_rbac["username"], password=user_credentials_rbac["password"] |
| 565 | + ) |
| 566 | + try: |
| 567 | + LOGGER.info(f"Creating secret {user_credentials_rbac['secret_name']} in openshift-config namespace") |
| 568 | + with Secret( |
| 569 | + name=user_credentials_rbac["secret_name"], |
| 570 | + namespace="openshift-config", |
| 571 | + htpasswd=htpasswd_b64, |
| 572 | + type="Opaque", |
| 573 | + wait_for_resource=True, |
| 574 | + ) as secret: |
| 575 | + yield secret |
| 576 | + finally: |
| 577 | + # Clean up the temporary file |
| 578 | + temp_path.unlink(missing_ok=True) |
571 | 579 |
|
572 | 580 |
|
573 | 581 | @pytest.fixture(scope="module") |
574 | 582 | def updated_oauth_config( |
575 | | - admin_client: DynamicClient, original_user: str, user_credentials_rbac: dict[str, str] |
| 583 | + is_byoidc: bool, admin_client: DynamicClient, original_user: str, user_credentials_rbac: dict[str, str] |
576 | 584 | ) -> Generator[Any, None, None]: |
577 | | - # Get current providers and add the new one |
578 | | - oauth = OAuth(name="cluster") |
579 | | - identity_providers = oauth.instance.spec.identityProviders |
580 | | - |
581 | | - new_idp = { |
582 | | - "name": user_credentials_rbac["idp_name"], |
583 | | - "mappingMethod": "claim", |
584 | | - "type": "HTPasswd", |
585 | | - "htpasswd": {"fileData": {"name": user_credentials_rbac["secret_name"]}}, |
586 | | - } |
587 | | - updated_providers = identity_providers + [new_idp] |
588 | | - |
589 | | - LOGGER.info("Updating OAuth") |
590 | | - identity_providers_patch = ResourceEditor(patches={oauth: {"spec": {"identityProviders": updated_providers}}}) |
591 | | - identity_providers_patch.update(backup_resources=True) |
592 | | - # Wait for OAuth server to be ready |
593 | | - wait_for_oauth_openshift_deployment() |
594 | | - LOGGER.info(f"Added IDP {user_credentials_rbac['idp_name']} to OAuth configuration") |
595 | | - yield |
596 | | - identity_providers_patch.restore() |
597 | | - wait_for_oauth_openshift_deployment() |
| 585 | + if is_byoidc: |
| 586 | + yield |
| 587 | + else: |
| 588 | + # Get current providers and add the new one |
| 589 | + oauth = OAuth(name="cluster") |
| 590 | + identity_providers = oauth.instance.spec.identityProviders |
| 591 | + |
| 592 | + new_idp = { |
| 593 | + "name": user_credentials_rbac["idp_name"], |
| 594 | + "mappingMethod": "claim", |
| 595 | + "type": "HTPasswd", |
| 596 | + "htpasswd": {"fileData": {"name": user_credentials_rbac["secret_name"]}}, |
| 597 | + } |
| 598 | + updated_providers = identity_providers + [new_idp] |
| 599 | + |
| 600 | + LOGGER.info("Updating OAuth") |
| 601 | + identity_providers_patch = ResourceEditor(patches={oauth: {"spec": {"identityProviders": updated_providers}}}) |
| 602 | + identity_providers_patch.update(backup_resources=True) |
| 603 | + # Wait for OAuth server to be ready |
| 604 | + wait_for_oauth_openshift_deployment() |
| 605 | + LOGGER.info(f"Added IDP {user_credentials_rbac['idp_name']} to OAuth configuration") |
| 606 | + yield |
| 607 | + identity_providers_patch.restore() |
| 608 | + wait_for_oauth_openshift_deployment() |
598 | 609 |
|
599 | 610 |
|
600 | 611 | @pytest.fixture(scope="module") |
|
0 commit comments