-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[KeyVault] KV Certificates to test proxy #24256
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
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
855f99d
sync test mods
kashifkhan 0b03056
add in a conftest for certs
kashifkhan 4846ccd
sync recordings
kashifkhan 42e73ba
minor update to remove method
kashifkhan 2279eeb
clean up imports
kashifkhan 0dd9d99
async recordings
kashifkhan 64bb881
async test to test proxy
kashifkhan 3102991
clean up imports
kashifkhan 5e4f175
PR comments
kashifkhan 897a97e
uncomment out skip
kashifkhan 1ad6336
record failing tests
kashifkhan 227eb0f
delete old recordings
kashifkhan b2499fd
minor clean up
kashifkhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
sdk/keyvault/azure-keyvault-certificates/tests/_async_test_case.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,58 @@ | ||
| # ------------------------------------ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| # ------------------------------------ | ||
|
|
||
| import os | ||
|
|
||
| from azure.keyvault.certificates import ApiVersion | ||
| from azure.keyvault.certificates._shared.client_base import DEFAULT_VERSION | ||
| from devtools_testutils import AzureRecordedTestCase, is_live | ||
| import pytest | ||
|
|
||
|
|
||
| def get_decorator(**kwargs): | ||
| """returns a test decorator for test parameterization""" | ||
| versions = kwargs.pop("api_versions", None) or ApiVersion | ||
| params = [pytest.param(api_version) for api_version in versions] | ||
| return params | ||
|
|
||
|
|
||
| class AsyncCertificatesClientPreparer(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) | ||
|
|
||
| async with client: | ||
| await fn(test_class, client) | ||
| return _preparer | ||
|
|
||
| def create_client(self, vault_uri, **kwargs): | ||
| from azure.keyvault.certificates.aio import CertificateClient | ||
|
|
||
| credential = self.get_credential(CertificateClient, is_async = True) | ||
|
|
||
| return self.create_client_from_credential( | ||
| CertificateClient, credential=credential, vault_url=vault_uri, **kwargs | ||
| ) | ||
|
|
||
| def _skip_if_not_configured(self, api_version, **kwargs): | ||
| if self.is_live and api_version != DEFAULT_VERSION: | ||
| pytest.skip("This test only uses the default API version for live tests") |
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
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
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
75 changes: 75 additions & 0 deletions
75
sdk/keyvault/azure-keyvault-certificates/tests/conftest.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,75 @@ | ||
| # -------------------------------------------------------------------------- | ||
| # | ||
| # 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 asyncio | ||
| 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 | ||
|
|
||
| @pytest.fixture(scope="session") | ||
| def event_loop(request): | ||
| loop = asyncio.get_event_loop() | ||
| yield loop | ||
| loop.close() |
Oops, something went wrong.
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.