Skip to content
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

KeyVaultBackupClient tests #13709

Merged
merged 3 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions sdk/keyvault/azure-keyvault-administration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,21 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import os
import sys

import pytest

if sys.version_info < (3, 5, 3):
collect_ignore_glob = ["*_async.py"]


@pytest.fixture(scope="class")
def managed_hsm(request):
"""Fixture for tests requiring a Managed HSM instance"""

playback_url = "https://managedhsm"
request.cls.managed_hsm = {
"url": os.environ.get("MANAGED_HSM_URL", playback_url),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need to add MANAGED_HSM_URL to the tests.yml file and as a secret to the pipeline?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To run the tests live, yes. For now I don't plan to try that because the managed HSM instance is in the pre-prod cloud, making authentication complicated.

"playback_url": playback_url,
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
-e ../../../tools/azure-sdk-tools
-e ../../core/azure-core
-e ../../identity/azure-identity
-e ../../storage/azure-storage-blob
-e ../azure-mgmt-keyvault
../azure-keyvault-nspkg
aiohttp>=3.0; python_version >= '3.5'
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from datetime import datetime, timedelta

from azure.storage.blob import BlobServiceClient, generate_account_sas, ResourceTypes, AccountSasPermissions
from devtools_testutils import AzureMgmtPreparer


class BlobContainerPreparer(AzureMgmtPreparer):
def __init__(self, **kwargs):
super(BlobContainerPreparer, self).__init__("container", 24, random_name_enabled=True, **kwargs)

def create_resource(self, name, **kwargs):
if self.is_live:
storage_account = kwargs.pop("storage_account")
storage_account_key = kwargs.pop("storage_account_key")
sas_token = generate_account_sas(
account_name=storage_account.name,
account_key=storage_account_key,
resource_types=ResourceTypes(container=True, object=True),
permission=AccountSasPermissions(
create=True, list=True, write=True, read=True, add=True, delete=True, delete_previous_version=True
),
expiry=datetime.utcnow() + timedelta(minutes=5),
)
blob_client = BlobServiceClient(storage_account.primary_endpoints.blob, sas_token)
container = blob_client.create_container(name)
container_uri = storage_account.primary_endpoints.blob + container.container_name
self.test_class_instance.scrubber.register_name_pair(sas_token, "redacted")
self.test_class_instance.scrubber.register_name_pair(container_uri, "https://storage/container")
else:
sas_token = "fake-sas"
container_uri = "https://storage/container"
return {"container_uri": container_uri, "sas_token": sas_token}
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
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-administration/4.0.0b2 Python/3.5.4 (Windows-10-10.0.19041-SP0)
method: POST
uri: https://managedhsm/backup?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.windows-ppe.net/f686d426-8d16-42db-81b7-ab578e110ccd",
resource="https://managedhsm-int.azure-int.net"
x-content-type-options:
- nosniff
x-frame-options:
- SAMEORIGIN
x-ms-server-latency:
- '2'
status:
code: 401
message: Unauthorized
- request:
body: '{"storageResourceUri": "https://storname.blob.core.windows.net/containerlpibiggddqawmbw",
"token": "redacted"}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '235'
Content-Type:
- application/json
User-Agent:
- azsdk-python-keyvault-administration/4.0.0b2 Python/3.5.4 (Windows-10-10.0.19041-SP0)
method: POST
uri: https://managedhsm/backup?api-version=7.2-preview
response:
body:
string: '{"status":"InProgress","statusDetails":null,"error":{"code":null,"message":null,"innererror":null},"startTime":1599693259,"endTime":null,"jobId":"0c6890ada4cf411987b1c8fff2e8d20f","azureStorageBlobContainerUri":null}'
headers:
azure-asyncoperation:
- https://managedhsm/backup/0c6890ada4cf411987b1c8fff2e8d20f/pending
cache-control:
- no-cache
content-length:
- '216'
content-security-policy:
- default-src 'self'
content-type:
- application/json; charset=utf-8
date:
- Wed, 09 Sep 2020 23:14:19 GMT
server:
- Kestrel
strict-transport-security:
- max-age=31536000; includeSubDomains
x-content-type-options:
- nosniff
x-frame-options:
- SAMEORIGIN
x-ms-keyvault-network-info:
- addr=24.17.201.78
x-ms-keyvault-region:
- EASTUS
x-ms-server-latency:
- '962'
status:
code: 202
message: ''
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- azsdk-python-keyvault-administration/4.0.0b2 Python/3.5.4 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://managedhsm/backup/0c6890ada4cf411987b1c8fff2e8d20f/pending
response:
body:
string: '{"azureStorageBlobContainerUri":"https://storname.blob.core.windows.net/containerlpibiggddqawmbw/mhsm-chriss-eu2-2020090923141950","endTime":1599693269,"error":null,"jobId":"0c6890ada4cf411987b1c8fff2e8d20f","startTime":1599693259,"status":"Succeeded","statusDetails":null}'
headers:
cache-control:
- no-cache
content-length:
- '289'
content-security-policy:
- default-src 'self'
content-type:
- application/json; charset=utf-8
date:
- Wed, 09 Sep 2020 23:14:29 GMT
server:
- Kestrel
strict-transport-security:
- max-age=31536000; includeSubDomains
x-content-type-options:
- nosniff
x-frame-options:
- SAMEORIGIN
x-ms-build-version:
- 1.0.20200909-2-c73be597-develop
x-ms-keyvault-network-info:
- addr=24.17.201.78
x-ms-keyvault-region:
- EASTUS
x-ms-server-latency:
- '599'
status:
code: 200
message: OK
- request:
body: '{"folderToRestore": "mhsm-chriss-eu2-2020090923141950", "sasTokenParameters":
{"storageResourceUri": "https://storname.blob.core.windows.net/containerlpibiggddqawmbw",
"token": "redacted"}}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '314'
Content-Type:
- application/json
User-Agent:
- azsdk-python-keyvault-administration/4.0.0b2 Python/3.5.4 (Windows-10-10.0.19041-SP0)
method: PUT
uri: https://managedhsm/restore?api-version=7.2-preview
response:
body:
string: '{"endTime":null,"error":{"code":null,"innererror":null,"message":null},"jobId":"f45c5ed12efc498990690cc92ed43684","startTime":1599693271,"status":"InProgress","statusDetails":null}'
headers:
azure-asyncoperation:
- https://managedhsm/restore/f45c5ed12efc498990690cc92ed43684/pending
cache-control:
- no-cache
content-length:
- '180'
content-security-policy:
- default-src 'self'
content-type:
- application/json; charset=utf-8
date:
- Wed, 09 Sep 2020 23:14:30 GMT
server:
- Kestrel
strict-transport-security:
- max-age=31536000; includeSubDomains
x-content-type-options:
- nosniff
x-frame-options:
- SAMEORIGIN
x-ms-keyvault-network-info:
- addr=24.17.201.78
x-ms-keyvault-region:
- EASTUS
x-ms-server-latency:
- '812'
status:
code: 202
message: ''
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- azsdk-python-keyvault-administration/4.0.0b2 Python/3.5.4 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://managedhsm/restore/f45c5ed12efc498990690cc92ed43684/pending
response:
body:
string: '{"endTime":null,"error":{"code":null,"innererror":null,"message":null},"jobId":"f45c5ed12efc498990690cc92ed43684","startTime":1599693271,"status":"InProgress","statusDetails":null}'
headers:
cache-control:
- no-cache
content-length:
- '180'
content-security-policy:
- default-src 'self'
content-type:
- application/json; charset=utf-8
date:
- Wed, 09 Sep 2020 23:14:42 GMT
server:
- Kestrel
strict-transport-security:
- max-age=31536000; includeSubDomains
x-content-type-options:
- nosniff
x-frame-options:
- SAMEORIGIN
x-ms-build-version:
- 1.0.20200909-2-c73be597-develop
x-ms-keyvault-network-info:
- addr=24.17.201.78
x-ms-keyvault-region:
- EASTUS
x-ms-server-latency:
- '534'
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- azsdk-python-keyvault-administration/4.0.0b2 Python/3.5.4 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://managedhsm/restore/f45c5ed12efc498990690cc92ed43684/pending
response:
body:
string: '{"endTime":1599693288,"error":null,"jobId":"f45c5ed12efc498990690cc92ed43684","startTime":1599693271,"status":"Succeeded","statusDetails":null}'
headers:
cache-control:
- no-cache
content-length:
- '143'
content-security-policy:
- default-src 'self'
content-type:
- application/json; charset=utf-8
date:
- Wed, 09 Sep 2020 23:14:50 GMT
server:
- Kestrel
strict-transport-security:
- max-age=31536000; includeSubDomains
x-content-type-options:
- nosniff
x-frame-options:
- SAMEORIGIN
x-ms-build-version:
- 1.0.20200909-2-c73be597-develop
x-ms-keyvault-network-info:
- addr=24.17.201.78
x-ms-keyvault-region:
- EASTUS
x-ms-server-latency:
- '656'
status:
code: 200
message: OK
version: 1
Loading