-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Key Vault] Test keys library against managed HSM (#17458)
- Loading branch information
Showing
129 changed files
with
47,237 additions
and
18,951 deletions.
There are no files selected for viewing
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,17 @@ | ||
{ | ||
"include": [ | ||
{ | ||
"Agent": { | ||
"ubuntu-18.04": { | ||
"OSVmImage": "MMSUbuntu18.04", | ||
"Pool": "azsdk-pool-mms-ubuntu-1804-general" | ||
} | ||
}, | ||
"HSM": { | ||
"ArmTemplateParameters": "@{ enableHsm = $true }" | ||
}, | ||
"PythonVersion": "3.9", | ||
"CoverageArg": "" | ||
} | ||
] | ||
} |
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,74 @@ | ||
# ------------------------------------ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
# ------------------------------------ | ||
import os | ||
|
||
from azure.keyvault.keys._shared import HttpChallengeCache | ||
from devtools_testutils import AzureTestCase | ||
from parameterized import parameterized | ||
import pytest | ||
from six.moves.urllib_parse import urlparse | ||
|
||
|
||
def suffixed_test_name(testcase_func, param_num, param): | ||
suffix = "mhsm" if param.kwargs.get("is_hsm") else "vault" | ||
return "{}_{}".format(testcase_func.__name__, parameterized.to_safe_name(suffix)) | ||
|
||
|
||
class KeysTestCase(AzureTestCase): | ||
def setUp(self, *args, **kwargs): | ||
vault_playback_url = "https://vaultname.vault.azure.net" | ||
hsm_playback_url = "https://managedhsmname.managedhsm.azure.net" | ||
|
||
if self.is_live: | ||
self.vault_url = os.environ["AZURE_KEYVAULT_URL"] | ||
self._scrub_url(real_url=self.vault_url, playback_url=vault_playback_url) | ||
|
||
self.managed_hsm_url = os.environ.get("AZURE_MANAGEDHSM_URL") | ||
if self.managed_hsm_url: | ||
self._scrub_url(real_url=self.managed_hsm_url, playback_url=hsm_playback_url) | ||
else: | ||
self.vault_url = vault_playback_url | ||
self.managed_hsm_url = hsm_playback_url | ||
|
||
self._set_mgmt_settings_real_values() | ||
super(KeysTestCase, self).setUp(*args, **kwargs) | ||
|
||
def tearDown(self): | ||
HttpChallengeCache.clear() | ||
assert len(HttpChallengeCache._cache) == 0 | ||
super(KeysTestCase, self).tearDown() | ||
|
||
def create_key_client(self, vault_uri, **kwargs): | ||
if kwargs.pop("is_async", False): | ||
from azure.keyvault.keys.aio import KeyClient | ||
credential = self.get_credential(KeyClient, is_async=True) | ||
else: | ||
from azure.keyvault.keys import KeyClient | ||
credential = self.get_credential(KeyClient) | ||
return self.create_client_from_credential(KeyClient, credential=credential, vault_url=vault_uri, **kwargs) | ||
|
||
def create_crypto_client(self, key,**kwargs): | ||
if kwargs.pop("is_async", False): | ||
from azure.keyvault.keys.crypto.aio import CryptographyClient | ||
credential = self.get_credential(CryptographyClient, is_async=True) | ||
else: | ||
from azure.keyvault.keys.crypto import CryptographyClient | ||
credential = self.get_credential(CryptographyClient) | ||
return self.create_client_from_credential(CryptographyClient, credential=credential, key=key, **kwargs) | ||
|
||
def _scrub_url(self, real_url, playback_url): | ||
real = urlparse(real_url) | ||
playback = urlparse(playback_url) | ||
self.scrubber.register_name_pair(real.netloc, playback.netloc) | ||
|
||
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"] | ||
|
||
def _skip_if_not_configured(self, is_hsm): | ||
if self.is_live and is_hsm and self.managed_hsm_url is None: | ||
pytest.skip("No HSM endpoint for live testing") |
131 changes: 131 additions & 0 deletions
131
...keyvault/azure-keyvault-keys/tests/recordings/test_crypto_client.test_ec_key_id_mhsm.yaml
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,131 @@ | ||
interactions: | ||
- request: | ||
body: null | ||
headers: | ||
Accept: | ||
- application/json | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- '0' | ||
Content-Type: | ||
- application/json | ||
User-Agent: | ||
- azsdk-python-keyvault-keys/4.4.0b4 Python/3.5.3 (Windows-10-10.0.19041-SP0) | ||
method: POST | ||
uri: https://managedhsmname.managedhsm.azure.net/keys/livekvtesteckey33180f9c/create?api-version=7.2-preview | ||
response: | ||
body: | ||
string: '' | ||
headers: | ||
cache-control: | ||
- no-cache | ||
content-length: | ||
- '0' | ||
content-security-policy: | ||
- default-src 'self' | ||
content-type: | ||
- application/json; charset=utf-8 | ||
strict-transport-security: | ||
- max-age=31536000; includeSubDomains | ||
www-authenticate: | ||
- Bearer authorization="https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-2d7cd011db47", | ||
resource="https://managedhsm.azure.net" | ||
x-content-type-options: | ||
- nosniff | ||
x-frame-options: | ||
- SAMEORIGIN | ||
x-ms-server-latency: | ||
- '1' | ||
status: | ||
code: 401 | ||
message: Unauthorized | ||
- request: | ||
body: '{"kty": "EC-HSM"}' | ||
headers: | ||
Accept: | ||
- application/json | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- '17' | ||
Content-Type: | ||
- application/json | ||
User-Agent: | ||
- azsdk-python-keyvault-keys/4.4.0b4 Python/3.5.3 (Windows-10-10.0.19041-SP0) | ||
method: POST | ||
uri: https://managedhsmname.managedhsm.azure.net/keys/livekvtesteckey33180f9c/create?api-version=7.2-preview | ||
response: | ||
body: | ||
string: '{"attributes":{"created":1616194950,"enabled":true,"exportable":false,"recoverableDays":90,"recoveryLevel":"Recoverable+Purgeable","updated":1616194950},"key":{"crv":"P-256","key_ops":["verify","sign"],"kid":"https://managedhsmname.managedhsm.azure.net/keys/livekvtesteckey33180f9c/38f9028c28e24b9b80fe3b2800c5950d","kty":"EC-HSM","x":"aD-Od-CpwDHTx3T9XEPYR3-KxdmZg_wtFekJBlrAaSM","y":"exOWHTfjEM5Qwg6GAF09KXJpwN7Ov8LN_ZxxIlqpK9I"}}' | ||
headers: | ||
cache-control: | ||
- no-cache | ||
content-length: | ||
- '433' | ||
content-security-policy: | ||
- default-src 'self' | ||
content-type: | ||
- application/json; charset=utf-8 | ||
strict-transport-security: | ||
- max-age=31536000; includeSubDomains | ||
x-content-type-options: | ||
- nosniff | ||
x-frame-options: | ||
- SAMEORIGIN | ||
x-ms-keyvault-network-info: | ||
- addr=172.92.159.124 | ||
x-ms-keyvault-region: | ||
- eastus2 | ||
x-ms-server-latency: | ||
- '261' | ||
status: | ||
code: 200 | ||
message: OK | ||
- request: | ||
body: null | ||
headers: | ||
Accept: | ||
- application/json | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
User-Agent: | ||
- azsdk-python-keyvault-keys/4.4.0b4 Python/3.5.3 (Windows-10-10.0.19041-SP0) | ||
method: GET | ||
uri: https://managedhsmname.managedhsm.azure.net/keys/livekvtesteckey33180f9c/38f9028c28e24b9b80fe3b2800c5950d?api-version=7.2-preview | ||
response: | ||
body: | ||
string: '{"attributes":{"created":1616194950,"enabled":true,"exportable":false,"recoverableDays":90,"recoveryLevel":"Recoverable+Purgeable","updated":1616194950},"key":{"crv":"P-256","key_ops":["verify","sign"],"kid":"https://managedhsmname.managedhsm.azure.net/keys/livekvtesteckey33180f9c/38f9028c28e24b9b80fe3b2800c5950d","kty":"EC-HSM","x":"aD-Od-CpwDHTx3T9XEPYR3-KxdmZg_wtFekJBlrAaSM","y":"exOWHTfjEM5Qwg6GAF09KXJpwN7Ov8LN_ZxxIlqpK9I"}}' | ||
headers: | ||
cache-control: | ||
- no-cache | ||
content-length: | ||
- '433' | ||
content-security-policy: | ||
- default-src 'self' | ||
content-type: | ||
- application/json; charset=utf-8 | ||
strict-transport-security: | ||
- max-age=31536000; includeSubDomains | ||
x-content-type-options: | ||
- nosniff | ||
x-frame-options: | ||
- SAMEORIGIN | ||
x-ms-build-version: | ||
- 1.0.20210306-1-6fb7c19a-develop | ||
x-ms-keyvault-network-info: | ||
- addr=172.92.159.124 | ||
x-ms-keyvault-region: | ||
- eastus2 | ||
x-ms-server-latency: | ||
- '126' | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
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.