forked from Azure/azure-sdk-for-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KeyVault] Enable Test Proxy for KeyVault Secrets (Azure#22807)
* switch to assert from self.assert* * Adding in conftest * Make sleep patches into fixtures * Change class name for pytest * move from aztestcase to azrectestcase * fix import * change class name for pytest * decorate sync tests with proxy * decorate async tests * missing imports * changes to get the tests collectd by pytest * add in sanitizers & test proxy changes * secrets client async preparer * changes for preparer * update with further sanitizers * update to test and recordings * changes to async test case * update test_parse to record output * minor cleanups * move to async prepaper * updates * minor changes to get tests working * more recordings from test proxy * switch to assert from self.assert* * Adding in conftest * updates * updates * further merges * merges * merges * changes * more recordings for async tests * Changes for async tests and work around for test proxy * Changes to to get tests working * change for EnvironmentVariablesLoader & recordings * clean up for client creation * fix patches for sleep * add in http cache clean * mods for win-http * recordings using test proxy * set default vault url * changes for auth headers * changes for auth update * new recordings * delete vcrpy recordings * remove unused imports & code cleanup * minor changes around patching sleep * new recordings for 7.3 * new recordings * clean up recordings of 7.3 preview * remove 7.3 preview tests * removing customer default handler for auth * new recording for test * code clean up and formatting * remove temp fix for async recordings * code clean up for imports, better error messages * add cache challenge in to a teardown * new recordings with cache challenge change * change kv url error * fix wrong masking name * Fix SecretsClientPreparer typo * remove code block for async tests * remove unused imports
- Loading branch information
1 parent
1eec48b
commit e769b81
Showing
279 changed files
with
216,280 additions
and
190,627 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
sdk/keyvault/azure-keyvault-secrets/tests/_async_test_case.py
This file contains 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,43 @@ | ||
# ------------------------------------ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
# ------------------------------------ | ||
import os | ||
|
||
import pytest | ||
from azure.keyvault.secrets._shared.client_base import DEFAULT_VERSION | ||
from devtools_testutils import AzureRecordedTestCase, is_live | ||
|
||
|
||
class AsyncSecretsClientPreparer(AzureRecordedTestCase): | ||
def __init__(self, **kwargs) -> None: | ||
self.azure_keyvault_url = "https://vaultname.vault.azure.net" | ||
|
||
if is_live(): | ||
self.azure_keyvault_url = os.environ["AZURE_KEYVAULT_URL"] | ||
|
||
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_CLIENT_SECRET"] = os.environ["KEYVAULT_CLIENT_SECRET"] | ||
|
||
def __call__(self, fn): | ||
async def _preparer(test_class, api_version, **kwargs): | ||
self._skip_if_not_configured(api_version) | ||
if not self.is_logging_enabled: | ||
kwargs.update({"logging_enable": False}) | ||
client = self.create_client(self.azure_keyvault_url, api_version=api_version, **kwargs) | ||
await fn(test_class, client) | ||
|
||
return _preparer | ||
|
||
def create_client(self, vault_uri, **kwargs): | ||
from azure.keyvault.secrets.aio import SecretClient | ||
|
||
credential = self.get_credential(SecretClient, is_async=True) | ||
return self.create_client_from_credential(SecretClient, credential=credential, vault_url=vault_uri, **kwargs) | ||
|
||
def _skip_if_not_configured(self, api_version, **kwargs): | ||
if is_live() and api_version != DEFAULT_VERSION: | ||
pytest.skip("This test only uses the default API version for live tests") |
This file contains 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
This file contains 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
This file contains 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
This file contains 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,68 @@ | ||
# -------------------------------------------------------------------------- | ||
# | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# | ||
# The MIT License (MIT) | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the ""Software""), to | ||
# deal in the Software without restriction, including without limitation the | ||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
# sell copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
# IN THE SOFTWARE. | ||
# | ||
# -------------------------------------------------------------------------- | ||
import os | ||
import pytest | ||
from unittest import mock | ||
from devtools_testutils import is_live, test_proxy, add_oauth_response_sanitizer, add_general_regex_sanitizer | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def add_sanitizers(test_proxy): | ||
azure_keyvault_url = os.getenv("azure_keyvault_url", "https://vaultname.vault.azure.net") | ||
azure_keyvault_url = azure_keyvault_url.rstrip("/") | ||
keyvault_tenant_id = os.getenv("keyvault_tenant_id", "keyvault_tenant_id") | ||
keyvault_subscription_id = os.getenv("keyvault_subscription_id", "keyvault_subscription_id") | ||
|
||
add_general_regex_sanitizer(regex=azure_keyvault_url, value="https://vaultname.vault.azure.net") | ||
add_general_regex_sanitizer(regex=keyvault_tenant_id, value="00000000-0000-0000-0000-000000000000") | ||
add_general_regex_sanitizer(regex=keyvault_subscription_id, value="00000000-0000-0000-0000-000000000000") | ||
add_oauth_response_sanitizer() | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def patch_async_sleep(): | ||
async def immediate_return(_): | ||
return | ||
|
||
if not is_live(): | ||
with mock.patch("asyncio.sleep", immediate_return): | ||
yield | ||
|
||
else: | ||
yield | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def patch_sleep(): | ||
def immediate_return(_): | ||
return | ||
|
||
if not is_live(): | ||
with mock.patch("time.sleep", immediate_return): | ||
yield | ||
|
||
else: | ||
yield |
This file contains 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 |
---|---|---|
|
@@ -10,7 +10,6 @@ | |
|
||
|
||
class GetSecretTest(PerfStressTest): | ||
|
||
def __init__(self, arguments): | ||
super().__init__(arguments) | ||
|
||
|
This file contains 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
Oops, something went wrong.