|
35 | 35 | from model_registry.types import RegisteredModel |
36 | 36 |
|
37 | 37 | from tests.model_registry.rbac.utils import wait_for_oauth_openshift_deployment |
38 | | -from tests.model_registry.utils import generate_namespace_name, get_rest_headers, wait_for_default_resource_cleanedup |
| 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,13 +491,14 @@ 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. |
493 | 498 | """ |
494 | 499 | if is_byoidc: |
495 | | - pytest.skip("Working on OIDC support for tests that use test_idp_user") |
| 500 | + # For BYOIDC, we would be using a preconfigured group and username for actual api calls. |
| 501 | + yield |
496 | 502 | else: |
497 | 503 | user_credentials_rbac = request.getfixturevalue(argname="user_credentials_rbac") |
498 | 504 | _ = request.getfixturevalue(argname="created_htpasswd_secret") |
@@ -544,67 +550,84 @@ def original_user() -> str: |
544 | 550 |
|
545 | 551 | @pytest.fixture(scope="module") |
546 | 552 | def created_htpasswd_secret( |
547 | | - original_user: str, user_credentials_rbac: dict[str, str] |
548 | | -) -> Generator[UserTestSession, None, None]: |
| 553 | + is_byoidc: bool, original_user: str, user_credentials_rbac: dict[str, str] |
| 554 | +) -> Generator[UserTestSession | None, None, None]: |
549 | 555 | """ |
550 | 556 | Session-scoped fixture that creates a test IDP user and cleans it up after all tests. |
551 | 557 | Returns a UserTestSession object that contains all necessary credentials and contexts. |
552 | 558 | """ |
| 559 | + if is_byoidc: |
| 560 | + yield |
553 | 561 |
|
554 | | - temp_path, htpasswd_b64 = create_htpasswd_file( |
555 | | - username=user_credentials_rbac["username"], password=user_credentials_rbac["password"] |
556 | | - ) |
557 | | - try: |
558 | | - LOGGER.info(f"Creating secret {user_credentials_rbac['secret_name']} in openshift-config namespace") |
559 | | - with Secret( |
560 | | - name=user_credentials_rbac["secret_name"], |
561 | | - namespace="openshift-config", |
562 | | - htpasswd=htpasswd_b64, |
563 | | - type="Opaque", |
564 | | - wait_for_resource=True, |
565 | | - ) as secret: |
566 | | - yield secret |
567 | | - finally: |
568 | | - # Clean up the temporary file |
569 | | - 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) |
570 | 579 |
|
571 | 580 |
|
572 | 581 | @pytest.fixture(scope="module") |
573 | 582 | def updated_oauth_config( |
574 | | - 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] |
575 | 584 | ) -> Generator[Any, None, None]: |
576 | | - # Get current providers and add the new one |
577 | | - oauth = OAuth(name="cluster") |
578 | | - identity_providers = oauth.instance.spec.identityProviders |
579 | | - |
580 | | - new_idp = { |
581 | | - "name": user_credentials_rbac["idp_name"], |
582 | | - "mappingMethod": "claim", |
583 | | - "type": "HTPasswd", |
584 | | - "htpasswd": {"fileData": {"name": user_credentials_rbac["secret_name"]}}, |
585 | | - } |
586 | | - updated_providers = identity_providers + [new_idp] |
| 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] |
587 | 599 |
|
588 | | - LOGGER.info("Updating OAuth") |
589 | | - identity_providers_patch = ResourceEditor(patches={oauth: {"spec": {"identityProviders": updated_providers}}}) |
590 | | - identity_providers_patch.update(backup_resources=True) |
591 | | - # Wait for OAuth server to be ready |
592 | | - wait_for_oauth_openshift_deployment() |
593 | | - LOGGER.info(f"Added IDP {user_credentials_rbac['idp_name']} to OAuth configuration") |
594 | | - yield |
595 | | - identity_providers_patch.restore() |
596 | | - wait_for_oauth_openshift_deployment() |
| 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() |
597 | 609 |
|
598 | 610 |
|
599 | 611 | @pytest.fixture(scope="module") |
600 | | -def user_credentials_rbac() -> dict[str, str]: |
601 | | - random_str = generate_random_name() |
602 | | - return { |
603 | | - "username": f"test-user-{random_str}", |
604 | | - "password": f"test-password-{random_str}", |
605 | | - "idp_name": f"test-htpasswd-idp-{random_str}", |
606 | | - "secret_name": f"test-htpasswd-secret-{random_str}", |
607 | | - } |
| 612 | +def user_credentials_rbac( |
| 613 | + is_byoidc: bool, |
| 614 | +) -> dict[str, str]: |
| 615 | + if is_byoidc: |
| 616 | + byoidc_creds = get_byoidc_user_credentials(username="mr-non-admin") |
| 617 | + return { |
| 618 | + "username": byoidc_creds["username"], |
| 619 | + "password": byoidc_creds["password"], |
| 620 | + "idp_name": "byoidc", |
| 621 | + "secret_name": None, |
| 622 | + } |
| 623 | + else: |
| 624 | + random_str = generate_random_name() |
| 625 | + return { |
| 626 | + "username": f"test-user-{random_str}", |
| 627 | + "password": f"test-password-{random_str}", |
| 628 | + "idp_name": f"test-htpasswd-idp-{random_str}", |
| 629 | + "secret_name": f"test-htpasswd-secret-{random_str}", |
| 630 | + } |
608 | 631 |
|
609 | 632 |
|
610 | 633 | @pytest.fixture(scope="class") |
|
0 commit comments