[CI] Test updates for central sanitizers (#35385)
This PR updates our Python testing framework to adopt the new TestProxy which enables numerous common sanitizers. Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
This commit is contained in:
Родитель
4c741c2521
Коммит
a61a8e2a93
|
@ -1 +1 @@
|
|||
1.0.0-dev.20240410.1
|
||||
1.0.0-dev.20240506.5
|
||||
|
|
|
@ -86,7 +86,7 @@ def fake_datastore_key() -> str:
|
|||
return str(b64_key, "ascii")
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def add_sanitizers(test_proxy, fake_datastore_key):
|
||||
"""Register recording sanitizers for the function under test"""
|
||||
add_remove_header_sanitizer(headers="x-azureml-token,Log-URL,Authorization")
|
||||
|
|
|
@ -100,7 +100,7 @@ def fake_datastore_key() -> str:
|
|||
return str(b64_key, "ascii")
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def add_sanitizers(test_proxy, fake_datastore_key):
|
||||
"""Register recording sanitizers for the function under test"""
|
||||
add_remove_header_sanitizer(headers="x-azureml-token,Log-URL,Authorization")
|
||||
|
|
|
@ -4,6 +4,7 @@ from devtools_testutils import (
|
|||
add_general_string_sanitizer,
|
||||
add_oauth_response_sanitizer,
|
||||
set_custom_default_matcher,
|
||||
remove_batch_sanitizers,
|
||||
)
|
||||
import pytest
|
||||
|
||||
|
@ -37,3 +38,8 @@ def add_sanitizers(test_proxy):
|
|||
add_general_regex_sanitizer(value="api-version=1970-01-01", regex="api-version=.+")
|
||||
set_custom_default_matcher(ignored_headers="x-ms-content-sha256, Accept", excluded_headers="Content-Length")
|
||||
add_oauth_response_sanitizer()
|
||||
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3430: $..id
|
||||
# - AZSDK3447: $.key
|
||||
remove_batch_sanitizers(["AZSDK3430", "AZSDK3447"])
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
# --------------------------------------------------------------------------
|
||||
import pytest
|
||||
import os
|
||||
from devtools_testutils import add_general_regex_sanitizer, test_proxy, set_bodiless_matcher
|
||||
from devtools_testutils import add_general_regex_sanitizer, test_proxy, set_bodiless_matcher, remove_batch_sanitizers
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
|
@ -38,3 +38,9 @@ def add_sanitizers(test_proxy):
|
|||
add_general_regex_sanitizer(regex=client_secret, value="client-secret")
|
||||
tenant_id = os.environ.get("APPCONFIGURATION_TENANT_ID", "00000000-0000-0000-0000-000000000000")
|
||||
add_general_regex_sanitizer(value="00000000-0000-0000-0000-000000000000", regex=tenant_id)
|
||||
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3447: $.key
|
||||
# - AZSDK3490: $..etag
|
||||
# - AZSDK3493: $..name
|
||||
remove_batch_sanitizers(["AZSDK3447", "AZSDK3490", "AZSDK3493"])
|
||||
|
|
|
@ -6,7 +6,11 @@
|
|||
# --------------------------------------------------------------------------
|
||||
import pytest
|
||||
|
||||
from devtools_testutils.sanitizers import add_header_regex_sanitizer, add_oauth_response_sanitizer
|
||||
from devtools_testutils.sanitizers import (
|
||||
add_header_regex_sanitizer,
|
||||
add_oauth_response_sanitizer,
|
||||
remove_batch_sanitizers
|
||||
)
|
||||
|
||||
|
||||
# Environment variable keys
|
||||
|
@ -40,6 +44,10 @@ def add_sanitizers(test_proxy, environment_variables):
|
|||
add_oauth_response_sanitizer()
|
||||
add_header_regex_sanitizer(key="Set-Cookie", value="[set-cookie;]")
|
||||
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3430: $..id
|
||||
remove_batch_sanitizers(["AZSDK3430"])
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def qna_creds(environment_variables):
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
"AssetsRepo": "Azure/azure-sdk-assets",
|
||||
"AssetsRepoPrefixPath": "python",
|
||||
"TagPrefix": "python/communication/azure-communication-callautomation",
|
||||
"Tag": "python/communication/azure-communication-callautomation_707ce35a60"
|
||||
"Tag": "python/communication/azure-communication-callautomation_ab7206cdd8"
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ from devtools_testutils import (
|
|||
set_default_session_settings,
|
||||
add_body_key_sanitizer,
|
||||
add_general_string_sanitizer,
|
||||
remove_batch_sanitizers,
|
||||
)
|
||||
|
||||
# autouse=True will trigger this fixture on each pytest run, even if it's not explicitly used by a test method
|
||||
|
@ -24,7 +25,7 @@ def start_proxy(test_proxy):
|
|||
add_general_string_sanitizer(target=connection_str, value=fake_connection_str)
|
||||
|
||||
add_general_regex_sanitizer(regex="https://[^/]+", value="https://sanitized")
|
||||
add_body_key_sanitizer(json_path="callbackUri", value="https://sanitized")
|
||||
add_body_key_sanitizer(json_path="callbackUri", value="https://sanitized/")
|
||||
add_body_key_sanitizer(json_path="$..file.uri", value="https://REDACTED/prompt.wav")
|
||||
add_header_regex_sanitizer(key="Set-Cookie", value="sanitized")
|
||||
add_header_regex_sanitizer(key="Date", value="sanitized")
|
||||
|
@ -40,4 +41,8 @@ def start_proxy(test_proxy):
|
|||
add_header_regex_sanitizer(key="Repeatability-First-Sent", value="sanitized")
|
||||
add_header_regex_sanitizer(key="Repeatability-Request-ID", value="sanitized")
|
||||
|
||||
return
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3430: $..id
|
||||
remove_batch_sanitizers(["AZSDK3430"])
|
||||
|
||||
return
|
||||
|
|
|
@ -35,6 +35,7 @@ from devtools_testutils import (
|
|||
set_default_session_settings,
|
||||
add_uri_regex_sanitizer,
|
||||
add_body_key_sanitizer,
|
||||
remove_batch_sanitizers,
|
||||
)
|
||||
from router_test_constants import SANITIZED, FAKE_FUNCTION_URI, FAKE_ENDPOINT, FAKE_CONNECTION_STRING
|
||||
from azure.communication.jobrouter._shared.utils import parse_connection_str
|
||||
|
@ -69,6 +70,11 @@ def start_proxy(test_proxy):
|
|||
add_body_key_sanitizer(json_path="$..functionKey", value=SANITIZED)
|
||||
add_body_key_sanitizer(json_path="$..appKey", value=SANITIZED)
|
||||
add_body_key_sanitizer(json_path="$..clientId", value=SANITIZED)
|
||||
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3430: $..id
|
||||
# - AZSDK3493: $..name
|
||||
remove_batch_sanitizers(["AZSDK3430", "AZSDK3493"])
|
||||
return
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@ from devtools_testutils import (
|
|||
add_general_string_sanitizer,
|
||||
add_general_regex_sanitizer,
|
||||
add_header_regex_sanitizer,
|
||||
test_proxy
|
||||
test_proxy,
|
||||
remove_batch_sanitizers,
|
||||
)
|
||||
|
||||
|
||||
|
@ -45,10 +46,10 @@ def add_sanitizers(test_proxy):
|
|||
add_body_key_sanitizer(json_path="phoneNumbers[*].id", value="sanitized")
|
||||
add_body_key_sanitizer(
|
||||
json_path="phoneNumbers[*].phoneNumber", value="sanitized")
|
||||
|
||||
|
||||
add_general_regex_sanitizer(
|
||||
regex=r"-[0-9a-fA-F]{32}\.[0-9a-zA-Z\.]*(\.com|\.net|\.test)", value=".sanitized.com")
|
||||
|
||||
|
||||
add_general_regex_sanitizer(regex=r"(?:(?:%2B)|\+)\d{10,15}", value="sanitized")
|
||||
|
||||
add_general_regex_sanitizer(
|
||||
|
@ -68,3 +69,9 @@ def add_sanitizers(test_proxy):
|
|||
add_header_regex_sanitizer(key="x-ms-request-id", value="sanitized")
|
||||
add_header_regex_sanitizer(
|
||||
key="Content-Security-Policy-Report-Only", value="sanitized")
|
||||
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3493: $..name
|
||||
# - AZSDK2003: Location
|
||||
remove_batch_sanitizers(["AZSDK3493", "AZSDK2003"])
|
||||
|
||||
|
|
|
@ -25,7 +25,12 @@
|
|||
# --------------------------------------------------------------------------
|
||||
import pytest
|
||||
import os
|
||||
from devtools_testutils import add_general_string_sanitizer, add_header_regex_sanitizer, add_body_key_sanitizer, set_default_session_settings
|
||||
from devtools_testutils import (
|
||||
add_general_string_sanitizer,
|
||||
add_header_regex_sanitizer,
|
||||
set_default_session_settings,
|
||||
remove_batch_sanitizers,
|
||||
)
|
||||
from azure.communication.rooms._shared.utils import parse_connection_str
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
|
@ -52,3 +57,7 @@ def add_sanitizers(test_proxy):
|
|||
key="Content-Security-Policy-Report-Only", value="sanitized")
|
||||
add_header_regex_sanitizer(key="Repeatability-First-Sent", value="sanitized")
|
||||
add_header_regex_sanitizer(key="Repeatability-Request-ID", value="sanitized")
|
||||
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3430: $..id
|
||||
remove_batch_sanitizers(["AZSDK3430"])
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
"AssetsRepo": "Azure/azure-sdk-assets",
|
||||
"AssetsRepoPrefixPath": "python",
|
||||
"TagPrefix": "python/containerregistry/azure-containerregistry",
|
||||
"Tag": "python/containerregistry/azure-containerregistry_790d3fef6e"
|
||||
"Tag": "python/containerregistry/azure-containerregistry_02a9c147da"
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ from devtools_testutils import (
|
|||
add_uri_regex_sanitizer,
|
||||
test_proxy,
|
||||
is_live,
|
||||
remove_batch_sanitizers,
|
||||
)
|
||||
from testcase import import_image, is_public_endpoint
|
||||
from constants import HELLO_WORLD
|
||||
|
@ -54,3 +55,10 @@ def add_sanitizers(test_proxy):
|
|||
add_general_regex_sanitizer(regex=client_id, value="client-id")
|
||||
client_secret = os.environ.get("CONTAINERREGISTRY_CLIENT_SECRET", "client-secret")
|
||||
add_general_regex_sanitizer(regex=client_secret, value="client-secret")
|
||||
tenant_id = os.environ.get("CONTAINERREGISTRY_TENANT_ID", "tenant-id")
|
||||
add_general_regex_sanitizer(regex=tenant_id, value="00000000-0000-0000-0000-000000000000")
|
||||
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3493: $..name
|
||||
# - AZSDK2003: Location
|
||||
remove_batch_sanitizers(["AZSDK3493", "AZSDK2003"])
|
||||
|
|
|
@ -6,15 +6,11 @@ These libraries follow the [Azure SDK Design Guidelines for Python](https://azur
|
|||
|
||||
If you are a client library developer, please reference [client library developer reference](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md) for more information.
|
||||
|
||||
[Source code](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/)
|
||||
[Source code](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/)
|
||||
| [Package (Pypi)][package]
|
||||
| [Package (Conda)](https://anaconda.org/microsoft/azure-core/)
|
||||
| [API reference documentation](https://docs.microsoft.com/python/api/overview/azure/core-readme)
|
||||
|
||||
## _Disclaimer_
|
||||
|
||||
_Azure SDK Python packages support for Python 2.7 has ended 01 January 2022. For more information and questions, please refer to <https://github.com/Azure/azure-sdk-for-python/issues/20691>_
|
||||
|
||||
## Getting started
|
||||
|
||||
Typically, you will not need to install azure core;
|
||||
|
|
|
@ -15,6 +15,7 @@ from devtools_testutils import (
|
|||
add_oauth_response_sanitizer,
|
||||
add_body_key_sanitizer,
|
||||
test_proxy,
|
||||
remove_batch_sanitizers,
|
||||
)
|
||||
|
||||
|
||||
|
@ -38,6 +39,9 @@ def add_sanitizers(test_proxy):
|
|||
value="redacted",
|
||||
regex="([0-9a-f-]{36})",
|
||||
)
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3496: "$..resourceLocation"
|
||||
remove_batch_sanitizers(["AZSDK3496"])
|
||||
|
||||
|
||||
def skip_flaky_test(f):
|
||||
|
|
|
@ -74,7 +74,7 @@ class TestClassifiersAsync(DocumentIntelligenceTest):
|
|||
assert len(result.doc_types) == 5
|
||||
for doc_type, doc_details in result.doc_types.items():
|
||||
assert doc_type
|
||||
assert doc_details.azure_blob_source.container_url.endswith("training-data-classifier")
|
||||
assert doc_details.azure_blob_source.container_url
|
||||
assert doc_details.azure_blob_source.prefix.startswith(doc_type)
|
||||
|
||||
classifier = client.get_classifier(result.classifier_id)
|
||||
|
@ -160,7 +160,7 @@ class TestClassifiersAsync(DocumentIntelligenceTest):
|
|||
assert len(result.doc_types) == 5
|
||||
for doc_type, doc_details in result.doc_types.items():
|
||||
assert doc_type
|
||||
assert doc_details.azure_blob_file_list_source.container_url.endswith("training-data-classifier")
|
||||
assert doc_details.azure_blob_file_list_source.container_url
|
||||
assert doc_details.azure_blob_file_list_source.file_list.startswith(doc_type)
|
||||
|
||||
classifier = client.get_classifier(result.classifier_id)
|
||||
|
|
|
@ -76,7 +76,7 @@ class TestClassifiersAsync(AsyncDocumentIntelligenceTest):
|
|||
assert len(result.doc_types) == 5
|
||||
for doc_type, doc_details in result.doc_types.items():
|
||||
assert doc_type
|
||||
assert doc_details.azure_blob_source.container_url.endswith("training-data-classifier")
|
||||
assert doc_details.azure_blob_source.container_url
|
||||
assert doc_details.azure_blob_source.prefix.startswith(doc_type)
|
||||
|
||||
classifier = await client.get_classifier(result.classifier_id)
|
||||
|
@ -165,7 +165,7 @@ class TestClassifiersAsync(AsyncDocumentIntelligenceTest):
|
|||
assert len(result.doc_types) == 5
|
||||
for doc_type, doc_details in result.doc_types.items():
|
||||
assert doc_type
|
||||
assert doc_details.azure_blob_file_list_source.container_url.endswith("training-data-classifier")
|
||||
assert doc_details.azure_blob_file_list_source.container_url
|
||||
assert doc_details.azure_blob_file_list_source.file_list.startswith(doc_type)
|
||||
|
||||
classifier = await client.get_classifier(result.classifier_id)
|
||||
|
|
|
@ -17,6 +17,7 @@ from devtools_testutils import (
|
|||
add_oauth_response_sanitizer,
|
||||
add_body_key_sanitizer,
|
||||
test_proxy,
|
||||
remove_batch_sanitizers,
|
||||
)
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
|
@ -42,6 +43,10 @@ def add_sanitizers(test_proxy):
|
|||
value="redacted",
|
||||
regex="([0-9a-f-]{36})",
|
||||
)
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3447: $.key
|
||||
# - AZSDK2003: Location
|
||||
remove_batch_sanitizers(["AZSDK3447", "AZSDK2003"])
|
||||
|
||||
def skip_flaky_test(f):
|
||||
@wraps(f)
|
||||
|
|
|
@ -69,7 +69,7 @@ class TestClassifier(FormRecognizerTest):
|
|||
assert result.description == "IRS document classifier"
|
||||
for doc_type, source in result.doc_types.items():
|
||||
assert doc_type
|
||||
assert source.source.container_url.endswith("training-data-classifier")
|
||||
assert source.source.container_url
|
||||
assert source.source.prefix
|
||||
|
||||
@FormRecognizerPreparer()
|
||||
|
@ -124,7 +124,7 @@ class TestClassifier(FormRecognizerTest):
|
|||
assert result.description is None
|
||||
for doc_type, source in result.doc_types.items():
|
||||
assert doc_type
|
||||
assert source.source.container_url.endswith("training-data-classifier")
|
||||
assert source.source.container_url
|
||||
assert source.source.file_list
|
||||
|
||||
@FormRecognizerPreparer()
|
||||
|
|
|
@ -71,7 +71,7 @@ class TestClassifiersAsync(AsyncFormRecognizerTest):
|
|||
assert result.description == "IRS document classifier"
|
||||
for doc_type, source in result.doc_types.items():
|
||||
assert doc_type
|
||||
assert source.source.container_url.endswith("training-data-classifier")
|
||||
assert source.source.container_url
|
||||
assert source.source.prefix
|
||||
|
||||
@FormRecognizerPreparer()
|
||||
|
@ -127,7 +127,7 @@ class TestClassifiersAsync(AsyncFormRecognizerTest):
|
|||
assert result.description is None
|
||||
for doc_type, source in result.doc_types.items():
|
||||
assert doc_type
|
||||
assert source.source.container_url.endswith("training-data-classifier")
|
||||
assert source.source.container_url
|
||||
assert source.source.file_list
|
||||
|
||||
@FormRecognizerPreparer()
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
"AssetsRepo": "Azure/azure-sdk-assets",
|
||||
"AssetsRepoPrefixPath": "python",
|
||||
"TagPrefix": "python/healthinsights/azure-healthinsights-radiologyinsights",
|
||||
"Tag": "python/healthinsights/azure-healthinsights-radiologyinsights_69d7fab8d7"
|
||||
"Tag": "python/healthinsights/azure-healthinsights-radiologyinsights_d1fac89a24"
|
||||
}
|
||||
|
|
|
@ -39,6 +39,6 @@ def add_sanitizers(test_proxy):
|
|||
)
|
||||
healthinsights_key = os.environ.get("HEALTHINSIGHTS_KEY", "00000000000000000000000000000000")
|
||||
add_general_regex_sanitizer(
|
||||
regex=healthinsights_endpoint, value="https://fake_ad_resource.cognitiveservices.azure.com"
|
||||
regex=healthinsights_endpoint, value="https://fake_ad_resource.cognitiveservices.azure.com/"
|
||||
)
|
||||
add_general_regex_sanitizer(regex=healthinsights_key, value="00000000000000000000000000000000")
|
||||
|
|
|
@ -13,6 +13,7 @@ from devtools_testutils import (
|
|||
add_oauth_response_sanitizer,
|
||||
add_uri_regex_sanitizer,
|
||||
is_live,
|
||||
remove_batch_sanitizers,
|
||||
)
|
||||
|
||||
os.environ['PYTHONHASHSEED'] = '0'
|
||||
|
@ -48,6 +49,11 @@ def add_sanitizers(test_proxy):
|
|||
add_uri_regex_sanitizer(regex="keys/([^/]*)\\?api-version=(\\S*)", value="keys/$1?api-version=sanitized")
|
||||
add_oauth_response_sanitizer()
|
||||
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3430: $..id
|
||||
# - AZSDK3493: $..name
|
||||
remove_batch_sanitizers(["AZSDK3430", "AZSDK3493"])
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def patch_async_sleep():
|
||||
|
|
|
@ -27,7 +27,13 @@ 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
|
||||
from devtools_testutils import (
|
||||
is_live,
|
||||
test_proxy,
|
||||
add_oauth_response_sanitizer,
|
||||
add_general_regex_sanitizer,
|
||||
remove_batch_sanitizers,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
|
@ -42,6 +48,11 @@ def add_sanitizers(test_proxy):
|
|||
add_general_regex_sanitizer(regex=keyvault_subscription_id, value="00000000-0000-0000-0000-000000000000")
|
||||
add_oauth_response_sanitizer()
|
||||
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3430: $..id
|
||||
# - AZSDK3493: $..name
|
||||
remove_batch_sanitizers(["AZSDK3430", "AZSDK3493"])
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def patch_async_sleep():
|
||||
|
@ -72,4 +83,4 @@ def patch_sleep():
|
|||
def event_loop(request):
|
||||
loop = asyncio.get_event_loop()
|
||||
yield loop
|
||||
loop.close()
|
||||
loop.close()
|
||||
|
|
|
@ -8,7 +8,12 @@ import os
|
|||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from devtools_testutils import add_general_string_sanitizer, add_oauth_response_sanitizer, is_live
|
||||
from devtools_testutils import (
|
||||
add_general_string_sanitizer,
|
||||
add_oauth_response_sanitizer,
|
||||
is_live,
|
||||
remove_batch_sanitizers
|
||||
)
|
||||
from azure.keyvault.keys._shared.client_base import DEFAULT_VERSION, ApiVersion
|
||||
|
||||
os.environ['PYTHONHASHSEED'] = '0'
|
||||
|
@ -42,6 +47,11 @@ def add_sanitizers(test_proxy):
|
|||
add_general_string_sanitizer(target=azure_attestation_uri, value="https://fakeattestation.azurewebsites.net")
|
||||
add_oauth_response_sanitizer()
|
||||
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3430: $..id
|
||||
# - AZSDK3447: $.key
|
||||
remove_batch_sanitizers(["AZSDK3430", "AZSDK3447",])
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def patch_async_sleep():
|
||||
|
|
|
@ -26,7 +26,13 @@
|
|||
import os
|
||||
import pytest
|
||||
from unittest import mock
|
||||
from devtools_testutils import is_live, test_proxy, add_oauth_response_sanitizer, add_general_regex_sanitizer
|
||||
from devtools_testutils import (
|
||||
is_live,
|
||||
test_proxy,
|
||||
add_oauth_response_sanitizer,
|
||||
add_general_regex_sanitizer,
|
||||
remove_batch_sanitizers
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
|
@ -41,6 +47,10 @@ def add_sanitizers(test_proxy):
|
|||
add_general_regex_sanitizer(regex=keyvault_subscription_id, value="00000000-0000-0000-0000-000000000000")
|
||||
add_oauth_response_sanitizer()
|
||||
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3430: $..id
|
||||
remove_batch_sanitizers(["AZSDK3430"])
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def patch_async_sleep():
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
"AssetsRepo": "Azure/azure-sdk-assets",
|
||||
"AssetsRepoPrefixPath": "python",
|
||||
"TagPrefix": "python/keyvault/azure-mgmt-keyvault",
|
||||
"Tag": "python/keyvault/azure-mgmt-keyvault_3a21675fd7"
|
||||
"Tag": "python/keyvault/azure-mgmt-keyvault_f804319f08"
|
||||
}
|
||||
|
|
|
@ -12,7 +12,8 @@ from devtools_testutils import (
|
|||
add_general_regex_sanitizer,
|
||||
add_header_regex_sanitizer,
|
||||
add_oauth_response_sanitizer,
|
||||
test_proxy
|
||||
test_proxy,
|
||||
remove_batch_sanitizers,
|
||||
)
|
||||
|
||||
# autouse=True will trigger this fixture on each pytest run, even if it's not explicitly used by a test method
|
||||
|
@ -28,4 +29,8 @@ def add_sanitizers(test_proxy):
|
|||
add_general_regex_sanitizer(regex=subscription_key, value="AzureMapsSubscriptionKey")
|
||||
add_general_regex_sanitizer(regex=tenant_id, value="MyTenantId")
|
||||
add_general_regex_sanitizer(regex=client_secret, value="MyClientSecret")
|
||||
# add_oauth_response_sanitizer()
|
||||
# add_oauth_response_sanitizer()
|
||||
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3493: $..name
|
||||
remove_batch_sanitizers(["AZSDK3493"])
|
||||
|
|
|
@ -12,7 +12,8 @@ from devtools_testutils import (
|
|||
add_general_regex_sanitizer,
|
||||
add_header_regex_sanitizer,
|
||||
add_oauth_response_sanitizer,
|
||||
test_proxy
|
||||
test_proxy,
|
||||
remove_batch_sanitizers,
|
||||
)
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
|
@ -24,3 +25,8 @@ def add_sanitizers(test_proxy):
|
|||
add_general_regex_sanitizer(regex=tenant_id, value="MyTenantId")
|
||||
add_general_regex_sanitizer(regex=client_secret, value="MyClientSecret")
|
||||
# add_oauth_response_sanitizer()
|
||||
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3430: $..id
|
||||
# - AZSDK3493: $..name
|
||||
remove_batch_sanitizers(["AZSDK3430", "AZSDK3493"])
|
||||
|
|
|
@ -206,6 +206,7 @@ class TestComponent(AzureRecordedTestCase):
|
|||
recorded_component_name="component_name",
|
||||
)
|
||||
|
||||
@pytest.mark.live_test_only("Needs re-recording to work with new test proxy sanitizers")
|
||||
def test_automl_component(self, client: MLClient, registry_client: MLClient, randstr: Callable[[str], str]) -> None:
|
||||
expected_component_dict = {
|
||||
"description": "Component that executes an AutoML Classification task model training in a pipeline.",
|
||||
|
@ -1222,6 +1223,7 @@ class TestComponent(AzureRecordedTestCase):
|
|||
|
||||
assert component._get_origin_code_value() == created_component._get_origin_code_value()
|
||||
|
||||
@pytest.mark.live_test_only("Needs re-recording to work with new test proxy sanitizers")
|
||||
def test_load_component_from_flow_in_registry(self, registry_client: MLClient, randstr):
|
||||
target_path: str = "./tests/test_configs/flows/runs/with_environment.yml"
|
||||
component = load_component(
|
||||
|
|
|
@ -24,6 +24,7 @@ from devtools_testutils import (
|
|||
is_live,
|
||||
set_bodiless_matcher,
|
||||
set_custom_default_matcher,
|
||||
remove_batch_sanitizers,
|
||||
)
|
||||
from devtools_testutils.fake_credentials import FakeTokenCredential
|
||||
from devtools_testutils.helpers import is_live_and_not_recording
|
||||
|
@ -87,7 +88,7 @@ def _query_param_regex(name, *, only_value=True) -> str:
|
|||
return rf'{name_regex}{value_regex}(?=[{QUERY_STRING_DELIMETER}"\s]|$)'
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def add_sanitizers(test_proxy, fake_datastore_key):
|
||||
add_remove_header_sanitizer(headers="x-azureml-token,Log-URL,Authorization")
|
||||
set_custom_default_matcher(
|
||||
|
@ -95,6 +96,10 @@ def add_sanitizers(test_proxy, fake_datastore_key):
|
|||
excluded_headers="x-ms-meta-name, x-ms-meta-version,x-ms-blob-type,If-None-Match,Content-Type,Content-MD5,Content-Length",
|
||||
ignored_query_parameters="api-version",
|
||||
)
|
||||
|
||||
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000")
|
||||
add_general_regex_sanitizer(regex=subscription_id, value="00000000-0000-0000-0000-000000000000")
|
||||
|
||||
add_body_key_sanitizer(json_path="$.key", value=fake_datastore_key)
|
||||
add_body_key_sanitizer(json_path="$....key", value=fake_datastore_key)
|
||||
add_body_key_sanitizer(json_path="$.properties.properties.['mlflow.source.git.repoURL']", value="fake_git_url")
|
||||
|
@ -126,6 +131,12 @@ def add_sanitizers(test_proxy, fake_datastore_key):
|
|||
# masks signature in SAS uri
|
||||
add_general_regex_sanitizer(value="000000000000000000000000000000000000", regex=_query_param_regex("sig"))
|
||||
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3430: $..id
|
||||
# - AZSDK3493: $..name
|
||||
# - AZSDK2003: Location
|
||||
remove_batch_sanitizers(["AZSDK3430", "AZSDK3493", "AZSDK2003"])
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption("--location", action="store", default="eastus2euap")
|
||||
|
|
|
@ -168,10 +168,9 @@ class TestPipelineBuilder:
|
|||
def sub_components(input_path: Input):
|
||||
if is_true:
|
||||
node = single_output_component_func(component_in_path=input_path, component_in_number=0.2)
|
||||
return {"component_out_path": node.outputs["component_out_path"]}
|
||||
else:
|
||||
node = single_output_component_func(component_in_path=input_path, component_in_number=0.7)
|
||||
return {"component_out_path": node.outputs["component_out_path"]}
|
||||
return {"component_out_path": node.outputs["component_out_path"]}
|
||||
|
||||
@dsl.pipeline
|
||||
def pipeline_func(input_path: Input):
|
||||
|
|
|
@ -89,6 +89,7 @@ class TestEnvironment(AzureRecordedTestCase):
|
|||
assert env_dump["id"] == ARM_ID_PREFIX + environment_id
|
||||
assert env_dump["image"] == environment.image
|
||||
|
||||
@pytest.mark.live_test_only("Needs re-recording to work with new test proxy sanitizers")
|
||||
def test_environment_create_or_update_docker_context(
|
||||
self, client: MLClient, env_name: Callable[[str], str]
|
||||
) -> None:
|
||||
|
@ -218,6 +219,7 @@ class TestEnvironment(AzureRecordedTestCase):
|
|||
sleep_if_live(2)
|
||||
assert client.environments.get(name, label="latest").version == version
|
||||
|
||||
@pytest.mark.live_test_only("Needs re-recording to work with new test proxy sanitizers")
|
||||
def test_registry_environment_create_conda_and_get(
|
||||
self, only_registry_client: MLClient, env_name: Callable[[str], str]
|
||||
) -> None:
|
||||
|
|
|
@ -14,7 +14,8 @@ from devtools_testutils import (
|
|||
add_header_regex_sanitizer,
|
||||
add_oauth_response_sanitizer,
|
||||
add_uri_string_sanitizer,
|
||||
test_proxy
|
||||
test_proxy,
|
||||
remove_batch_sanitizers,
|
||||
)
|
||||
|
||||
# Ignore async tests for PyPy
|
||||
|
@ -36,3 +37,7 @@ def add_sanitizers(test_proxy):
|
|||
add_header_regex_sanitizer(key="x-ms-encryption-key", value="Sanitized")
|
||||
|
||||
add_uri_string_sanitizer(target=".preprod.", value=".")
|
||||
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3493: $..name
|
||||
remove_batch_sanitizers(["AZSDK3493"])
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
"AssetsRepo": "Azure/azure-sdk-assets",
|
||||
"AssetsRepoPrefixPath": "python",
|
||||
"TagPrefix": "python/tables/azure-data-tables",
|
||||
"Tag": "python/tables/azure-data-tables_602e1ddae5"
|
||||
"Tag": "python/tables/azure-data-tables_4f55d47a10"
|
||||
}
|
||||
|
|
|
@ -26,7 +26,13 @@
|
|||
import os
|
||||
|
||||
import pytest
|
||||
from devtools_testutils import add_general_regex_sanitizer, add_body_key_sanitizer, test_proxy
|
||||
from devtools_testutils import (
|
||||
add_general_regex_sanitizer,
|
||||
add_body_key_sanitizer,
|
||||
test_proxy,
|
||||
add_oauth_response_sanitizer,
|
||||
remove_batch_sanitizers,
|
||||
)
|
||||
|
||||
# fixture needs to be visible from conftest
|
||||
|
||||
|
@ -53,3 +59,7 @@ def add_sanitizers(test_proxy):
|
|||
add_general_regex_sanitizer(value="00000000-0000-0000-0000-000000000000", regex=challenge_tenant_id)
|
||||
# sanitizes access tokens in response bodies
|
||||
add_body_key_sanitizer(json_path="$..access_token", value="access_token")
|
||||
add_oauth_response_sanitizer()
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3490: $..etag
|
||||
remove_batch_sanitizers(["AZSDK3490"])
|
||||
|
|
|
@ -233,7 +233,8 @@ class TestStorageRetry(AzureRecordedTestCase, TableTestCase):
|
|||
# prepare a table
|
||||
with TableClient(url, table_name, credential=tables_primary_storage_account_key) as client:
|
||||
client.create_table()
|
||||
time.sleep(10)
|
||||
if self.is_live:
|
||||
time.sleep(15)
|
||||
|
||||
# test get_entity() without the entity
|
||||
with TableClient(
|
||||
|
@ -262,7 +263,8 @@ class TestStorageRetry(AzureRecordedTestCase, TableTestCase):
|
|||
# prepare an entity
|
||||
with TableClient(url, table_name, credential=tables_primary_storage_account_key) as client:
|
||||
client.create_entity(entity)
|
||||
time.sleep(10)
|
||||
if self.is_live:
|
||||
time.sleep(15)
|
||||
|
||||
# test get_entity() when the entity is ready
|
||||
with TableClient(
|
||||
|
@ -329,7 +331,8 @@ class TestStorageRetry(AzureRecordedTestCase, TableTestCase):
|
|||
# prepare a table
|
||||
with TableClient(url, table_name, credential=tables_primary_storage_account_key) as client:
|
||||
client.create_table()
|
||||
time.sleep(10)
|
||||
if self.is_live:
|
||||
time.sleep(15)
|
||||
|
||||
# test get_entity() without the entity
|
||||
with TableClient(
|
||||
|
@ -358,7 +361,8 @@ class TestStorageRetry(AzureRecordedTestCase, TableTestCase):
|
|||
# prepare an entity
|
||||
with TableClient(url, table_name, credential=tables_primary_storage_account_key) as client:
|
||||
client.create_entity(entity)
|
||||
time.sleep(10)
|
||||
if self.is_live:
|
||||
time.sleep(15)
|
||||
|
||||
# test get_entity() when the entity is ready
|
||||
with TableClient(
|
||||
|
|
|
@ -42,7 +42,8 @@ class TestStorageRetry(AzureRecordedTestCase, TableTestCase):
|
|||
# prepare a table
|
||||
with TableClient(url, table_name, credential=tables_primary_cosmos_account_key) as client:
|
||||
client.create_table()
|
||||
time.sleep(10)
|
||||
if self.is_live:
|
||||
time.sleep(15)
|
||||
|
||||
# test get_entity() without the entity
|
||||
with TableClient(
|
||||
|
@ -71,7 +72,8 @@ class TestStorageRetry(AzureRecordedTestCase, TableTestCase):
|
|||
# prepare an entity
|
||||
with TableClient(url, table_name, credential=tables_primary_cosmos_account_key) as client:
|
||||
client.create_entity(entity)
|
||||
time.sleep(10)
|
||||
if self.is_live:
|
||||
time.sleep(10)
|
||||
|
||||
# test get_entity() when the entity is ready
|
||||
with TableClient(
|
||||
|
@ -138,7 +140,8 @@ class TestStorageRetry(AzureRecordedTestCase, TableTestCase):
|
|||
# prepare a table
|
||||
with TableClient(url, table_name, credential=tables_primary_cosmos_account_key) as client:
|
||||
client.create_table()
|
||||
time.sleep(10)
|
||||
if self.is_live:
|
||||
time.sleep(15)
|
||||
|
||||
# test get_entity() without the entity
|
||||
with TableClient(
|
||||
|
@ -167,7 +170,8 @@ class TestStorageRetry(AzureRecordedTestCase, TableTestCase):
|
|||
# prepare an entity
|
||||
with TableClient(url, table_name, credential=tables_primary_cosmos_account_key) as client:
|
||||
client.create_entity(entity)
|
||||
time.sleep(10)
|
||||
if self.is_live:
|
||||
time.sleep(15)
|
||||
|
||||
# test get_entity() when the entity is ready
|
||||
with TableClient(
|
||||
|
|
|
@ -224,7 +224,8 @@ class TestTableClient(AzureRecordedTestCase, TableTestCase):
|
|||
|
||||
with TableClient(url, table_name, credential=tables_primary_storage_account_key) as client:
|
||||
client.create_table()
|
||||
time.sleep(10)
|
||||
if self.is_live:
|
||||
time.sleep(15)
|
||||
|
||||
with TableClient(
|
||||
url, table_name, credential=tables_primary_storage_account_key, location_mode=LocationMode.SECONDARY
|
||||
|
|
|
@ -224,7 +224,8 @@ class TestTableClientAsync(AzureRecordedTestCase, AsyncTableTestCase):
|
|||
|
||||
async with TableClient(url, table_name, credential=tables_primary_storage_account_key) as client:
|
||||
await client.create_table()
|
||||
time.sleep(10)
|
||||
if self.is_live:
|
||||
time.sleep(15)
|
||||
|
||||
async with TableClient(
|
||||
url, table_name, credential=tables_primary_storage_account_key, location_mode=LocationMode.SECONDARY
|
||||
|
|
|
@ -10,14 +10,21 @@ from devtools_testutils import (
|
|||
add_remove_header_sanitizer,
|
||||
add_general_regex_sanitizer,
|
||||
add_oauth_response_sanitizer,
|
||||
remove_batch_sanitizers,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def add_sanitizers(test_proxy):
|
||||
add_remove_header_sanitizer(headers="Ocp-Apim-Subscription-Key")
|
||||
add_remove_header_sanitizer(headers="Ocp-Apim-Subscription-Key,Cookie")
|
||||
|
||||
add_general_regex_sanitizer(
|
||||
value="fakeendpoint",
|
||||
regex="(?<=\\/\\/)[a-z-]+(?=\\.cognitiveservices\\.azure\\.com)"
|
||||
)
|
||||
add_oauth_response_sanitizer()
|
||||
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3430: $..id
|
||||
# - AZSDK3493: $..name
|
||||
remove_batch_sanitizers(["AZSDK3430", "AZSDK3493"])
|
||||
|
|
|
@ -14,7 +14,8 @@ from devtools_testutils import (
|
|||
is_live,
|
||||
add_remove_header_sanitizer,
|
||||
add_general_regex_sanitizer,
|
||||
add_oauth_response_sanitizer
|
||||
add_oauth_response_sanitizer,
|
||||
remove_batch_sanitizers,
|
||||
)
|
||||
from azure.storage.blob import BlobServiceClient
|
||||
|
||||
|
@ -26,8 +27,7 @@ if sys.version_info < (3, 5):
|
|||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def add_sanitizers(test_proxy):
|
||||
add_remove_header_sanitizer(headers="Ocp-Apim-Subscription-Key")
|
||||
add_remove_header_sanitizer(headers="Retry-After")
|
||||
add_remove_header_sanitizer(headers="Ocp-Apim-Subscription-Key,Retry-After,Cookie")
|
||||
add_general_regex_sanitizer(
|
||||
value="fakeendpoint",
|
||||
regex="(?<=\\/\\/)[a-z-]+(?=\\.cognitiveservices\\.azure\\.com)"
|
||||
|
@ -38,6 +38,11 @@ def add_sanitizers(test_proxy):
|
|||
)
|
||||
add_oauth_response_sanitizer()
|
||||
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3430: $..id
|
||||
# - AZSDK3424: $..to
|
||||
remove_batch_sanitizers(["AZSDK3430", "AZSDK3424"])
|
||||
|
||||
# run tests
|
||||
yield
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import pytest
|
||||
from devtools_testutils import test_proxy, add_remove_header_sanitizer
|
||||
from devtools_testutils import test_proxy, add_remove_header_sanitizer, remove_batch_sanitizers
|
||||
|
||||
# autouse=True will trigger this fixture on each pytest run, even if it's not explicitly used by a test method
|
||||
# def start_proxy(test_proxy):
|
||||
|
@ -9,3 +9,8 @@ from devtools_testutils import test_proxy, add_remove_header_sanitizer
|
|||
@pytest.fixture(scope="session", autouse=True)
|
||||
def add_sanitizers(test_proxy):
|
||||
add_remove_header_sanitizer(headers="Ocp-Apim-Subscription-Key")
|
||||
|
||||
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
|
||||
# - AZSDK3430: $..id
|
||||
# - AZSDK3424: $..to
|
||||
remove_batch_sanitizers(["AZSDK3430", "AZSDK3424"])
|
||||
|
|
|
@ -40,6 +40,7 @@ from .sanitizers import (
|
|||
add_uri_regex_sanitizer,
|
||||
add_uri_string_sanitizer,
|
||||
add_uri_subscription_id_sanitizer,
|
||||
remove_batch_sanitizers,
|
||||
PemCertificate,
|
||||
Sanitizer,
|
||||
set_bodiless_matcher,
|
||||
|
@ -75,6 +76,7 @@ __all__ = [
|
|||
"add_uri_regex_sanitizer",
|
||||
"add_uri_string_sanitizer",
|
||||
"add_uri_subscription_id_sanitizer",
|
||||
"remove_batch_santizers",
|
||||
"AzureMgmtPreparer",
|
||||
"AzureMgmtRecordedTestCase",
|
||||
"AzureRecordedTestCase",
|
||||
|
|
|
@ -32,19 +32,6 @@ _LOGGER = logging.getLogger()
|
|||
load_dotenv(find_dotenv())
|
||||
|
||||
|
||||
def _sanitize_token(token, fake_token):
|
||||
add_general_string_sanitizer(value=fake_token, target=token)
|
||||
|
||||
# By this point, the token sig value should've been sanitized.
|
||||
token = re.sub(r"(?<=sig=)[^&]*", SANITIZED, token)
|
||||
add_general_string_sanitizer(value=fake_token, target=token)
|
||||
|
||||
url_safe_token = token.replace("/", "%2F")
|
||||
add_general_string_sanitizer(value=fake_token, target=url_safe_token)
|
||||
async_token = token.replace("%3A", ":")
|
||||
add_general_string_sanitizer(value=fake_token, target=async_token)
|
||||
|
||||
|
||||
class AzureRecordedTestCase(object):
|
||||
"""Test class for use by data-plane tests that use the azure-sdk-tools test proxy.
|
||||
|
||||
|
@ -255,45 +242,16 @@ class AzureRecordedTestCase(object):
|
|||
time.sleep(seconds)
|
||||
|
||||
def generate_sas(self, *args, **kwargs):
|
||||
"""Generates a SAS token using a generation function and arguments, and sanitizes token params in recordings.
|
||||
"""This is a deprecated method that just returns the token from the passed-in function as-is.
|
||||
|
||||
By default, this sanitizes the values of the `sig`, `st`, and `se` parameters to "fake_token_value", "start",
|
||||
and "end", respectively. By providing a dictionary of `fake_parameters` mapping parameter names to values they
|
||||
should be sanitized with, you can customize this sanitization and include other parameters.
|
||||
SAS token sanitization is now handled by test proxy centrally.
|
||||
|
||||
:keyword fake_parameters: A dictionary with token parameter names as keys, and the values to sanitize these keys
|
||||
with as values. For example: {"sktid": "00000000-0000-0000-0000-000000000000", "sig": "sanitized"}
|
||||
with as values. For example: {"sktid": "00000000-0000-0000-0000-000000000000", "sig": "Sanitized"}
|
||||
:paramtype fake_parameters: Dict[str, str]
|
||||
:keyword str fake_value: The value used to sanitize `sig`. Defaults to "Sanitized".
|
||||
"""
|
||||
sas_func = args[0]
|
||||
sas_func_pos_args = args[1:]
|
||||
|
||||
fake_value = kwargs.pop("fake_value", SANITIZED)
|
||||
fake_parameters = kwargs.pop("fake_parameters", {})
|
||||
token = sas_func(*sas_func_pos_args, **kwargs)
|
||||
|
||||
fake_token = self._create_fake_token(token, fake_value, fake_parameters)
|
||||
_sanitize_token(token, fake_token)
|
||||
|
||||
if self.is_live:
|
||||
return token
|
||||
return fake_token
|
||||
|
||||
def _create_fake_token(self, token: str, fake_sig_value: str, fake_parameters: Dict[str, str]) -> str:
|
||||
"""Returns a replacement value for sanitizing `sig`, `st`, `se`, and provided params of a given SAS token."""
|
||||
parameters = token.split("&")
|
||||
|
||||
for idx, parameter in enumerate(parameters):
|
||||
key = parameter.split("=")[0]
|
||||
fake_value = fake_parameters.get(key)
|
||||
if fake_value is not None:
|
||||
parameters[idx] = "=".join([key, fake_value])
|
||||
elif key == "sig":
|
||||
parameters[idx] = "=".join([key, fake_sig_value])
|
||||
elif key == "st":
|
||||
parameters[idx] = "=".join([key, "start"])
|
||||
elif key == "se":
|
||||
parameters[idx] = "=".join([key, "end"])
|
||||
|
||||
return "&".join(parameters)
|
||||
return token
|
||||
|
|
|
@ -30,6 +30,7 @@ from .sanitizers import (
|
|||
add_batch_sanitizers,
|
||||
Sanitizer,
|
||||
set_custom_default_matcher,
|
||||
remove_batch_sanitizers,
|
||||
)
|
||||
|
||||
|
||||
|
@ -303,146 +304,34 @@ def set_common_sanitizers() -> None:
|
|||
batch_sanitizers[Sanitizer.REMOVE_HEADER] = [{"headers": headers_to_ignore}]
|
||||
|
||||
# Remove OAuth interactions, which can contain client secrets and aren't necessary for playback testing
|
||||
batch_sanitizers[Sanitizer.OAUTH_RESPONSE] = [None]
|
||||
# TODO: Determine why this breaks some test playbacks. Since sensitive info in OAuth responses is sanitized
|
||||
# through other sanitizers, it's fine to keep this off for now.
|
||||
# batch_sanitizers[Sanitizer.OAUTH_RESPONSE] = [None]
|
||||
|
||||
# Body key sanitizers for sensitive fields in JSON requests/responses
|
||||
batch_sanitizers[Sanitizer.BODY_KEY] = [
|
||||
{"json_path": "$..access_token", "value": FAKE_ACCESS_TOKEN},
|
||||
{"json_path": "$..AccessToken", "value": FAKE_ACCESS_TOKEN},
|
||||
{"json_path": "$..targetModelLocation", "value": SANITIZED},
|
||||
{"json_path": "$..targetResourceId", "value": SANITIZED},
|
||||
{"json_path": "$..urlSource", "value": SANITIZED},
|
||||
{"json_path": "$..azureBlobSource.containerUrl", "value": SANITIZED},
|
||||
{"json_path": "$..source", "value": SANITIZED},
|
||||
{"json_path": "$..resourceLocation", "value": SANITIZED},
|
||||
{"json_path": "Location", "value": SANITIZED},
|
||||
{"json_path": "$..to", "value": SANITIZED},
|
||||
{"json_path": "$..from", "value": SANITIZED},
|
||||
{"json_path": "$..sasUri", "value": SANITIZED},
|
||||
{"json_path": "$..containerUri", "value": SANITIZED},
|
||||
{"json_path": "$..inputDataUri", "value": SANITIZED},
|
||||
{"json_path": "$..outputDataUri", "value": SANITIZED},
|
||||
# {"json_path": "$..id", "value": SANITIZED},
|
||||
{"json_path": "$..token", "value": SANITIZED},
|
||||
{"json_path": "$..appId", "value": SANITIZED},
|
||||
{"json_path": "$..userId", "value": SANITIZED},
|
||||
{"json_path": "$..storageAccount", "value": SANITIZED},
|
||||
{"json_path": "$..resourceGroup", "value": SANITIZED},
|
||||
{"json_path": "$..guardian", "value": SANITIZED},
|
||||
{"json_path": "$..scan", "value": SANITIZED},
|
||||
{"json_path": "$..catalog", "value": SANITIZED},
|
||||
{"json_path": "$..lastModifiedBy", "value": SANITIZED},
|
||||
{"json_path": "$..managedResourceGroupName", "value": SANITIZED},
|
||||
{"json_path": "$..friendlyName", "value": SANITIZED},
|
||||
{"json_path": "$..createdBy", "value": SANITIZED},
|
||||
{"json_path": "$..credential", "value": SANITIZED},
|
||||
{"json_path": "$..aliasPrimaryConnectionString", "value": SANITIZED},
|
||||
{"json_path": "$..aliasSecondaryConnectionString", "value": SANITIZED},
|
||||
{"json_path": "$..connectionString", "value": SANITIZED},
|
||||
{"json_path": "$..primaryConnectionString", "value": SANITIZED},
|
||||
{"json_path": "$..secondaryConnectionString", "value": SANITIZED},
|
||||
{"json_path": "$..sshPassword", "value": SANITIZED},
|
||||
{"json_path": "$..primaryKey", "value": SANITIZED},
|
||||
{"json_path": "$..secondaryKey", "value": SANITIZED},
|
||||
{"json_path": "$..runAsPassword", "value": SANITIZED},
|
||||
{"json_path": "$..adminPassword", "value": SANITIZED},
|
||||
{"json_path": "$..adminPassword.value", "value": SANITIZED},
|
||||
{"json_path": "$..administratorLoginPassword", "value": SANITIZED},
|
||||
{"json_path": "$..accessSAS", "value": SANITIZED},
|
||||
{"json_path": "$..WEBSITE_AUTH_ENCRYPTION_KEY", "value": SANITIZED},
|
||||
{"json_path": "$..storageContainerWriteSas", "value": SANITIZED},
|
||||
{"json_path": "$..storageContainerUri", "value": SANITIZED},
|
||||
{"json_path": "$..storageContainerReadListSas", "value": SANITIZED},
|
||||
{"json_path": "$..storageAccountPrimaryKey", "value": SANITIZED},
|
||||
{"json_path": "$..uploadUrl", "value": SANITIZED},
|
||||
{"json_path": "$..secondaryReadonlyMasterKey", "value": SANITIZED},
|
||||
{"json_path": "$..primaryMasterKey", "value": SANITIZED},
|
||||
{"json_path": "$..primaryReadonlyMasterKey", "value": SANITIZED},
|
||||
{"json_path": "$..secondaryMasterKey", "value": SANITIZED},
|
||||
{"json_path": "$..scriptUrlSasToken", "value": SANITIZED},
|
||||
{"json_path": "$..privateKey", "value": SANITIZED},
|
||||
{"json_path": "$..password", "value": SANITIZED},
|
||||
{"json_path": "$..logLink", "value": SANITIZED},
|
||||
{"json_path": "$..keyVaultClientSecret", "value": SANITIZED},
|
||||
{"json_path": "$..httpHeader", "value": SANITIZED},
|
||||
{"json_path": "$..functionKey", "value": SANITIZED},
|
||||
{"json_path": "$..fencingClientPassword", "value": SANITIZED},
|
||||
{"json_path": "$..encryptedCredential", "value": SANITIZED},
|
||||
{"json_path": "$..clientSecret", "value": SANITIZED},
|
||||
{"json_path": "$..certificatePassword", "value": SANITIZED},
|
||||
{"json_path": "$..authHeader", "value": SANITIZED},
|
||||
{"json_path": "$..atlasKafkaSecondaryEndpoint", "value": SANITIZED},
|
||||
{"json_path": "$..atlasKafkaPrimaryEndpoint", "value": SANITIZED},
|
||||
{"json_path": "$..appkey", "value": SANITIZED},
|
||||
{"json_path": "$..acrToken", "value": SANITIZED},
|
||||
{"json_path": "$..accountKey", "value": SANITIZED},
|
||||
{"json_path": "$..accountName", "value": SANITIZED},
|
||||
{"json_path": "$..decryptionKey", "value": SANITIZED},
|
||||
{"json_path": "$..applicationId", "value": SANITIZED},
|
||||
{"json_path": "$..apiKey", "value": SANITIZED},
|
||||
{"json_path": "$..userName", "value": SANITIZED},
|
||||
{"json_path": "$.properties.DOCKER_REGISTRY_SERVER_PASSWORD", "value": SANITIZED},
|
||||
{"json_path": "$.value[*].key", "value": SANITIZED},
|
||||
# {"json_path": "$.key", "value": SANITIZED},
|
||||
{"json_path": "$..clientId", "value": FAKE_ID},
|
||||
{"json_path": "$..principalId", "value": FAKE_ID},
|
||||
{"json_path": "$..tenantId", "value": FAKE_ID},
|
||||
]
|
||||
batch_sanitizers[Sanitizer.BODY_KEY] = []
|
||||
|
||||
# Body regex sanitizers for sensitive patterns in request/response bodies
|
||||
batch_sanitizers[Sanitizer.BODY_REGEX] = [
|
||||
{"regex": "(client_id=)(?<secret>[^&\\\"]+)", "group_for_replace": "secret", "value": SANITIZED},
|
||||
{"regex": "client_secret=(?<secret>[^&\\\"]+)", "group_for_replace": "secret", "value": SANITIZED},
|
||||
{"regex": "client_assertion=(?<secret>[^&\\\"]+)", "group_for_replace": "secret", "value": SANITIZED},
|
||||
{"regex": "(?:[\\?&](sv|sig|se|srt|ss|st|sp)=)(?<secret>[^&\\\"\\s]*)",
|
||||
"group_for_replace": "secret", "value": SANITIZED},
|
||||
{"regex": "refresh_token=(?<group>.*?)(?=&|$)", "group_for_replace": "group", "value": SANITIZED},
|
||||
{"regex": "access_token=(?<group>.*?)(?=&|$)", "group_for_replace": "group", "value": SANITIZED},
|
||||
{"regex": "token=(?<token>[^&\\\"]+)($|&)", "group_for_replace": "token", "value": SANITIZED},
|
||||
{"regex": "-----BEGIN PRIVATE KEY-----\\n(?<cert>.+\\n)*-----END PRIVATE KEY-----\\n", "group_for_replace": "cert", "value": SANITIZED},
|
||||
{"regex": "(?<=<UserDelegationKey>).*?(?:<Value>)(?<group>.*)(?:</Value>)", "group_for_replace": "group", "value": SANITIZED},
|
||||
{"regex": "(?<=<UserDelegationKey>).*?(?:<SignedTid>)(?<group>.*)(?:</SignedTid>)", "group_for_replace": "group", "value": SANITIZED},
|
||||
{"regex": "(?<=<UserDelegationKey>).*?(?:<SignedOid>)(?<group>.*)(?:</SignedOid>)", "group_for_replace": "group", "value": SANITIZED},
|
||||
{"regex": "(?:Password=)(?<pwd>.*?)(?:;)", "group_for_replace": "pwd", "value": SANITIZED},
|
||||
{"regex": "(?:User ID=)(?<id>.*?)(?:;)", "group_for_replace": "id", "value": SANITIZED},
|
||||
{"regex": "(?:<PrimaryKey>)(?<key>.*)(?:</PrimaryKey>)", "group_for_replace": "key", "value": SANITIZED},
|
||||
{"regex": "(?:<SecondaryKey>)(?<key>.*)(?:</SecondaryKey>)", "group_for_replace": "key", "value": SANITIZED},
|
||||
]
|
||||
batch_sanitizers[Sanitizer.BODY_REGEX] = []
|
||||
|
||||
# General regex sanitizers for sensitive patterns throughout interactions
|
||||
batch_sanitizers[Sanitizer.GENERAL_REGEX] = [
|
||||
{"regex": "SharedAccessKey=(?<key>[^;\\\"]+)", "group_for_replace": "key", "value": SANITIZED},
|
||||
{"regex": "AccountKey=(?<key>[^;\\\"]+)", "group_for_replace": "key", "value": SANITIZED},
|
||||
{"regex": "accesskey=(?<key>[^;\\\"]+)", "group_for_replace": "key", "value": SANITIZED},
|
||||
{"regex": "Accesskey=(?<key>[^;\\\"]+)", "group_for_replace": "key", "value": SANITIZED},
|
||||
{"regex": "Secret=(?<key>[^;\\\"]+)", "group_for_replace": "key", "value": SANITIZED},
|
||||
{"regex": "(?:[\\?&](sig|se|st)=)(?<secret>[^&\\\"\\s]*)", "group_for_replace": "secret", "value": SANITIZED},
|
||||
]
|
||||
|
||||
# Header regex sanitizers for sensitive patterns in request/response headers
|
||||
batch_sanitizers[Sanitizer.HEADER_REGEX] = [
|
||||
{"key": "subscription-key", "value": SANITIZED},
|
||||
{"key": "x-ms-encryption-key", "value": SANITIZED},
|
||||
{"key": "x-ms-rename-source", "value": SANITIZED},
|
||||
{"key": "x-ms-file-rename-source", "value": SANITIZED},
|
||||
{"key": "x-ms-copy-source", "value": SANITIZED},
|
||||
{"key": "x-ms-copy-source-authorization", "value": SANITIZED},
|
||||
{"key": "x-ms-file-rename-source-authorization", "value": SANITIZED},
|
||||
{"key": "x-ms-encryption-key-sha256", "value": SANITIZED},
|
||||
{"key": "api-key", "value": SANITIZED},
|
||||
{"key": "aeg-sas-token", "value": SANITIZED},
|
||||
{"key": "aeg-sas-key", "value": SANITIZED},
|
||||
{"key": "aeg-channel-name", "value": SANITIZED},
|
||||
{"key": "SupplementaryAuthorization", "value": SERVICEBUS_FAKE_SAS},
|
||||
]
|
||||
batch_sanitizers[Sanitizer.HEADER_REGEX] = []
|
||||
|
||||
# URI regex sanitizers for sensitive patterns in request/response URLs
|
||||
batch_sanitizers[Sanitizer.URI_REGEX] = [
|
||||
{"regex": "sig=(?<sig>[^&]+)", "group_for_replace": "sig", "value": SANITIZED}
|
||||
]
|
||||
batch_sanitizers[Sanitizer.URI_REGEX] = []
|
||||
|
||||
# Send all the above sanitizers to the test proxy in a single, batch request
|
||||
add_batch_sanitizers(sanitizers=batch_sanitizers)
|
||||
|
||||
# Remove certain sanitizers that are too aggressive and cause excessive playback failures
|
||||
# - AZSDK2030: operation-location
|
||||
remove_batch_sanitizers(["AZSDK2030"])
|
||||
|
||||
|
||||
def start_test_proxy(request) -> None:
|
||||
"""Starts the test proxy and returns when the proxy server is ready to receive requests.
|
||||
|
|
|
@ -472,6 +472,35 @@ def add_batch_sanitizers(sanitizers: Dict[str, List[Optional[Dict[str, str]]]],
|
|||
)
|
||||
|
||||
|
||||
def remove_batch_sanitizers(sanitizers: List[str], headers: Optional[Dict] = None) -> None:
|
||||
"""Removes a batch of sanitizers.
|
||||
|
||||
Sanitizers are denoted by their ID, which is a string. This method will remove all sanitizers with the provided
|
||||
IDs.
|
||||
|
||||
:param sanitizers: A list of sanitizer IDs to remove.
|
||||
:type sanitizers: list[str]
|
||||
:param headers: Optional headers to include in the request.
|
||||
:type headers: dict
|
||||
"""
|
||||
|
||||
data = {"Sanitizers" : sanitizers}
|
||||
|
||||
headers_to_send = {"Content-Type": "application/json"}
|
||||
if headers is not None:
|
||||
for key in headers:
|
||||
if headers[key] is not None:
|
||||
headers_to_send[key] = headers[key]
|
||||
|
||||
http_client = get_http_client()
|
||||
http_client.request(
|
||||
method="POST",
|
||||
url="{}/Admin/RemoveSanitizers".format(PROXY_URL),
|
||||
headers=headers_to_send,
|
||||
body=json.dumps(data).encode("utf-8"),
|
||||
)
|
||||
|
||||
|
||||
# ----------TRANSFORMS----------
|
||||
#
|
||||
# A transform extends functionality of the test proxy by applying to responses just before they are returned during
|
||||
|
@ -520,7 +549,7 @@ def add_header_transform(**kwargs) -> None:
|
|||
|
||||
def add_storage_request_id_transform() -> None:
|
||||
"""Registers a transform that ensures a response's "x-ms-client-request-id" header matches the request's.
|
||||
|
||||
|
||||
This method should be called during test case execution, rather than at a session, module, or class level.
|
||||
"""
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче