From 4b50745100ff62f86758796acd3b5c2b683d2dcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?McCoy=20Pati=C3=B1o?= <39780829+mccoyp@users.noreply.github.com> Date: Tue, 30 Jul 2024 11:30:32 -0700 Subject: [PATCH] [Key Vault] Update tests to work with missing SP credentials (#36679) --- .../azure-keyvault-administration/tests/_async_test_case.py | 6 +++--- .../azure-keyvault-administration/tests/_test_case.py | 6 +++--- .../azure-keyvault-certificates/tests/_async_test_case.py | 4 ++-- .../azure-keyvault-certificates/tests/_test_case.py | 4 ++-- .../tests/test_examples_certificates.py | 1 + .../tests/test_examples_certificates_async.py | 1 + sdk/keyvault/azure-keyvault-keys/tests/_async_test_case.py | 6 +++--- sdk/keyvault/azure-keyvault-keys/tests/_test_case.py | 6 +++--- sdk/keyvault/azure-keyvault-keys/tests/test_samples_keys.py | 1 + .../azure-keyvault-keys/tests/test_samples_keys_async.py | 1 + .../azure-keyvault-secrets/tests/_async_test_case.py | 4 ++-- sdk/keyvault/azure-keyvault-secrets/tests/_test_case.py | 4 ++-- .../azure-keyvault-secrets/tests/test_samples_secrets.py | 1 + .../tests/test_samples_secrets_async.py | 1 + 14 files changed, 26 insertions(+), 20 deletions(-) diff --git a/sdk/keyvault/azure-keyvault-administration/tests/_async_test_case.py b/sdk/keyvault/azure-keyvault-administration/tests/_async_test_case.py index 3fa73ec293cd..cece3f542563 100644 --- a/sdk/keyvault/azure-keyvault-administration/tests/_async_test_case.py +++ b/sdk/keyvault/azure-keyvault-administration/tests/_async_test_case.py @@ -48,9 +48,9 @@ def _skip_if_not_configured(self, api_version, **kwargs): def _set_mgmt_settings_real_values(self): if self.is_live: - os.environ["AZURE_TENANT_ID"] = os.environ["KEYVAULT_TENANT_ID"] - os.environ["AZURE_CLIENT_ID"] = os.environ["KEYVAULT_CLIENT_ID"] - os.environ["AZURE_CLIENT_SECRET"] = os.environ["KEYVAULT_CLIENT_SECRET"] + os.environ["AZURE_TENANT_ID"] = os.getenv("KEYVAULT_TENANT_ID", "") # empty in pipelines + os.environ["AZURE_CLIENT_ID"] = os.getenv("KEYVAULT_CLIENT_ID", "") # empty in pipelines + os.environ["AZURE_CLIENT_SECRET"] = os.getenv("KEYVAULT_CLIENT_SECRET", "") # empty for user-based auth class KeyVaultBackupClientPreparer(BaseClientPreparer): diff --git a/sdk/keyvault/azure-keyvault-administration/tests/_test_case.py b/sdk/keyvault/azure-keyvault-administration/tests/_test_case.py index 20c1cc9e069a..67a5c7f450ab 100644 --- a/sdk/keyvault/azure-keyvault-administration/tests/_test_case.py +++ b/sdk/keyvault/azure-keyvault-administration/tests/_test_case.py @@ -49,9 +49,9 @@ def _skip_if_not_configured(self, api_version, **kwargs): def _set_mgmt_settings_real_values(self): if self.is_live: - os.environ["AZURE_TENANT_ID"] = os.environ["KEYVAULT_TENANT_ID"] - os.environ["AZURE_CLIENT_ID"] = os.environ["KEYVAULT_CLIENT_ID"] - os.environ["AZURE_CLIENT_SECRET"] = os.environ["KEYVAULT_CLIENT_SECRET"] + os.environ["AZURE_TENANT_ID"] = os.getenv("KEYVAULT_TENANT_ID", "") # empty in pipelines + os.environ["AZURE_CLIENT_ID"] = os.getenv("KEYVAULT_CLIENT_ID", "") # empty in pipelines + os.environ["AZURE_CLIENT_SECRET"] = os.getenv("KEYVAULT_CLIENT_SECRET", "") # empty for user-based auth class KeyVaultBackupClientPreparer(BaseClientPreparer): diff --git a/sdk/keyvault/azure-keyvault-certificates/tests/_async_test_case.py b/sdk/keyvault/azure-keyvault-certificates/tests/_async_test_case.py index c4528a74f443..959061de2552 100644 --- a/sdk/keyvault/azure-keyvault-certificates/tests/_async_test_case.py +++ b/sdk/keyvault/azure-keyvault-certificates/tests/_async_test_case.py @@ -28,8 +28,8 @@ def __init__(self, **kwargs) -> None: self.is_logging_enabled = kwargs.pop("logging_enable", True) if is_live(): - os.environ["AZURE_TENANT_ID"] = os.environ["KEYVAULT_TENANT_ID"] - os.environ["AZURE_CLIENT_ID"] = os.environ["KEYVAULT_CLIENT_ID"] + os.environ["AZURE_TENANT_ID"] = os.getenv("KEYVAULT_TENANT_ID", "") # empty in pipelines + os.environ["AZURE_CLIENT_ID"] = os.getenv("KEYVAULT_CLIENT_ID", "") # empty in pipelines os.environ["AZURE_CLIENT_SECRET"] = os.getenv("KEYVAULT_CLIENT_SECRET", "") # empty for user-based auth def __call__(self, fn): diff --git a/sdk/keyvault/azure-keyvault-certificates/tests/_test_case.py b/sdk/keyvault/azure-keyvault-certificates/tests/_test_case.py index f7220cb87f8a..a36ebc805f23 100644 --- a/sdk/keyvault/azure-keyvault-certificates/tests/_test_case.py +++ b/sdk/keyvault/azure-keyvault-certificates/tests/_test_case.py @@ -26,8 +26,8 @@ def __init__(self, **kwargs) -> None: if is_live(): self.azure_keyvault_url = os.environ["AZURE_KEYVAULT_URL"] - os.environ["AZURE_TENANT_ID"] = os.environ["KEYVAULT_TENANT_ID"] - os.environ["AZURE_CLIENT_ID"] = os.environ["KEYVAULT_CLIENT_ID"] + os.environ["AZURE_TENANT_ID"] = os.getenv("KEYVAULT_TENANT_ID", "") # empty in pipelines + os.environ["AZURE_CLIENT_ID"] = os.getenv("KEYVAULT_CLIENT_ID", "") # empty in pipelines os.environ["AZURE_CLIENT_SECRET"] = os.getenv("KEYVAULT_CLIENT_SECRET", "") # empty for user-based auth def __call__(self, fn): diff --git a/sdk/keyvault/azure-keyvault-certificates/tests/test_examples_certificates.py b/sdk/keyvault/azure-keyvault-certificates/tests/test_examples_certificates.py index 43867cc52679..fa44f47351e9 100644 --- a/sdk/keyvault/azure-keyvault-certificates/tests/test_examples_certificates.py +++ b/sdk/keyvault/azure-keyvault-certificates/tests/test_examples_certificates.py @@ -21,6 +21,7 @@ def print(*args): assert all(arg is not None for arg in args) +@pytest.mark.playback_test_only("Can't run in live pipelines, and there's no reason to.") def test_create_certificate_client(): vault_url = "vault_url" # pylint:disable=unused-variable diff --git a/sdk/keyvault/azure-keyvault-certificates/tests/test_examples_certificates_async.py b/sdk/keyvault/azure-keyvault-certificates/tests/test_examples_certificates_async.py index 7be52807b0c2..04e42c9ac805 100644 --- a/sdk/keyvault/azure-keyvault-certificates/tests/test_examples_certificates_async.py +++ b/sdk/keyvault/azure-keyvault-certificates/tests/test_examples_certificates_async.py @@ -21,6 +21,7 @@ def print(*args): @pytest.mark.asyncio +@pytest.mark.playback_test_only("Can't run in live pipelines, and there's no reason to.") async def test_create_certificate(): vault_url = "vault_url" # pylint:disable=unused-variable diff --git a/sdk/keyvault/azure-keyvault-keys/tests/_async_test_case.py b/sdk/keyvault/azure-keyvault-keys/tests/_async_test_case.py index e57df68d21a6..1bd3c07ac22b 100644 --- a/sdk/keyvault/azure-keyvault-keys/tests/_async_test_case.py +++ b/sdk/keyvault/azure-keyvault-keys/tests/_async_test_case.py @@ -95,9 +95,9 @@ def create_key_client(self, vault_uri, **kwargs): def _set_mgmt_settings_real_values(self): if self.is_live: - os.environ["AZURE_TENANT_ID"] = os.environ["KEYVAULT_TENANT_ID"] - os.environ["AZURE_CLIENT_ID"] = os.environ["KEYVAULT_CLIENT_ID"] - os.environ["AZURE_CLIENT_SECRET"] = os.environ.get("KEYVAULT_CLIENT_SECRET", "") # Empty for user auth + os.environ["AZURE_TENANT_ID"] = os.getenv("KEYVAULT_TENANT_ID", "") # empty in pipelines + os.environ["AZURE_CLIENT_ID"] = os.getenv("KEYVAULT_CLIENT_ID", "") # empty in pipelines + os.environ["AZURE_CLIENT_SECRET"] = os.getenv("KEYVAULT_CLIENT_SECRET", "") # empty for user-based auth def _skip_if_not_configured(self, is_hsm): if self.is_live and is_hsm and self.managed_hsm_url is None: diff --git a/sdk/keyvault/azure-keyvault-keys/tests/_test_case.py b/sdk/keyvault/azure-keyvault-keys/tests/_test_case.py index fca6129379f6..dac13b948287 100644 --- a/sdk/keyvault/azure-keyvault-keys/tests/_test_case.py +++ b/sdk/keyvault/azure-keyvault-keys/tests/_test_case.py @@ -100,9 +100,9 @@ def create_key_client(self, vault_uri, **kwargs): def _set_mgmt_settings_real_values(self): if self.is_live: - os.environ["AZURE_TENANT_ID"] = os.environ["KEYVAULT_TENANT_ID"] - os.environ["AZURE_CLIENT_ID"] = os.environ["KEYVAULT_CLIENT_ID"] - os.environ["AZURE_CLIENT_SECRET"] = os.environ.get("KEYVAULT_CLIENT_SECRET", "") # Empty for user auth + os.environ["AZURE_TENANT_ID"] = os.getenv("KEYVAULT_TENANT_ID", "") # empty in pipelines + os.environ["AZURE_CLIENT_ID"] = os.getenv("KEYVAULT_CLIENT_ID", "") # empty in pipelines + os.environ["AZURE_CLIENT_SECRET"] = os.getenv("KEYVAULT_CLIENT_SECRET", "") # empty for user-based auth def _skip_if_not_configured(self, is_hsm): if self.is_live and is_hsm and self.managed_hsm_url is None: diff --git a/sdk/keyvault/azure-keyvault-keys/tests/test_samples_keys.py b/sdk/keyvault/azure-keyvault-keys/tests/test_samples_keys.py index 1401d89c335d..0d453e91ba44 100644 --- a/sdk/keyvault/azure-keyvault-keys/tests/test_samples_keys.py +++ b/sdk/keyvault/azure-keyvault-keys/tests/test_samples_keys.py @@ -23,6 +23,7 @@ def print(*args): assert all(arg is not None for arg in args) +@pytest.mark.playback_test_only("Can't run in live pipelines, and there's no reason to.") def test_create_key_client(): vault_url = "vault_url" # pylint:disable=unused-variable diff --git a/sdk/keyvault/azure-keyvault-keys/tests/test_samples_keys_async.py b/sdk/keyvault/azure-keyvault-keys/tests/test_samples_keys_async.py index c8a4835d9dd7..0357017a4b44 100644 --- a/sdk/keyvault/azure-keyvault-keys/tests/test_samples_keys_async.py +++ b/sdk/keyvault/azure-keyvault-keys/tests/test_samples_keys_async.py @@ -21,6 +21,7 @@ def print(*args): @pytest.mark.asyncio +@pytest.mark.playback_test_only("Can't run in live pipelines, and there's no reason to.") async def test_create_key_client(): vault_url = "vault_url" # pylint:disable=unused-variable diff --git a/sdk/keyvault/azure-keyvault-secrets/tests/_async_test_case.py b/sdk/keyvault/azure-keyvault-secrets/tests/_async_test_case.py index dd2d355814fa..ef32f9076e8d 100644 --- a/sdk/keyvault/azure-keyvault-secrets/tests/_async_test_case.py +++ b/sdk/keyvault/azure-keyvault-secrets/tests/_async_test_case.py @@ -18,8 +18,8 @@ def __init__(self, **kwargs) -> None: self.is_logging_enabled = kwargs.pop("logging_enable", True) if is_live(): - os.environ["AZURE_TENANT_ID"] = os.environ["KEYVAULT_TENANT_ID"] - os.environ["AZURE_CLIENT_ID"] = os.environ["KEYVAULT_CLIENT_ID"] + os.environ["AZURE_TENANT_ID"] = os.getenv("KEYVAULT_TENANT_ID", "") # empty in pipelines + os.environ["AZURE_CLIENT_ID"] = os.getenv("KEYVAULT_CLIENT_ID", "") # empty in pipelines os.environ["AZURE_CLIENT_SECRET"] = os.getenv("KEYVAULT_CLIENT_SECRET", "") # empty for user-based auth def __call__(self, fn): diff --git a/sdk/keyvault/azure-keyvault-secrets/tests/_test_case.py b/sdk/keyvault/azure-keyvault-secrets/tests/_test_case.py index 25ffd0fcef47..311a3b5742a8 100644 --- a/sdk/keyvault/azure-keyvault-secrets/tests/_test_case.py +++ b/sdk/keyvault/azure-keyvault-secrets/tests/_test_case.py @@ -24,8 +24,8 @@ def __init__(self, **kwargs) -> None: self.is_logging_enabled = kwargs.pop("logging_enable", True) if is_live(): - os.environ["AZURE_TENANT_ID"] = os.environ["KEYVAULT_TENANT_ID"] - os.environ["AZURE_CLIENT_ID"] = os.environ["KEYVAULT_CLIENT_ID"] + os.environ["AZURE_TENANT_ID"] = os.getenv("KEYVAULT_TENANT_ID", "") # empty in pipelines + os.environ["AZURE_CLIENT_ID"] = os.getenv("KEYVAULT_CLIENT_ID", "") # empty in pipelines os.environ["AZURE_CLIENT_SECRET"] = os.getenv("KEYVAULT_CLIENT_SECRET", "") # empty for user-based auth def __call__(self, fn): diff --git a/sdk/keyvault/azure-keyvault-secrets/tests/test_samples_secrets.py b/sdk/keyvault/azure-keyvault-secrets/tests/test_samples_secrets.py index 9c29da8cdc19..e0694f4cb690 100644 --- a/sdk/keyvault/azure-keyvault-secrets/tests/test_samples_secrets.py +++ b/sdk/keyvault/azure-keyvault-secrets/tests/test_samples_secrets.py @@ -19,6 +19,7 @@ def print(*args): assert all(arg is not None for arg in args) +@pytest.mark.playback_test_only("Can't run in live pipelines, and there's no reason to.") def test_create_secret_client(): vault_url = "vault_url" # pylint:disable=unused-variable diff --git a/sdk/keyvault/azure-keyvault-secrets/tests/test_samples_secrets_async.py b/sdk/keyvault/azure-keyvault-secrets/tests/test_samples_secrets_async.py index a8f566e3be2e..034ccd514ec7 100644 --- a/sdk/keyvault/azure-keyvault-secrets/tests/test_samples_secrets_async.py +++ b/sdk/keyvault/azure-keyvault-secrets/tests/test_samples_secrets_async.py @@ -22,6 +22,7 @@ def print(*args): @pytest.mark.asyncio +@pytest.mark.playback_test_only("Can't run in live pipelines, and there's no reason to.") async def test_create_secret_client(): vault_url = "vault_url" # pylint:disable=unused-variable