Skip to content

[CI] Test updates for central sanitizers #35385

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 4 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion eng/target_proxy_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0-dev.20240410.1
1.0.0-dev.20240506.5
2 changes: 1 addition & 1 deletion sdk/ai/azure-ai-generative/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion sdk/ai/azure-ai-resources/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
add_general_string_sanitizer,
add_oauth_response_sanitizer,
set_custom_default_matcher,
remove_batch_sanitizers,
)
import pytest

Expand Down Expand Up @@ -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"])
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"])
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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
Expand All @@ -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")
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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
Expand Down Expand Up @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
add_general_string_sanitizer,
add_general_regex_sanitizer,
add_header_regex_sanitizer,
test_proxy
test_proxy,
remove_batch_sanitizers,
)


Expand Down Expand Up @@ -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(
Expand All @@ -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"])

11 changes: 10 additions & 1 deletion sdk/communication/azure-communication-rooms/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 changes: 1 addition & 1 deletion sdk/containerregistry/azure-containerregistry/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
add_uri_regex_sanitizer,
test_proxy,
is_live,
remove_batch_sanitizers,
)
from testcase import import_image, is_public_endpoint
from constants import HELLO_WORLD
Expand Down Expand Up @@ -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 changes: 1 addition & 5 deletions sdk/core/azure-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
add_oauth_response_sanitizer,
add_body_key_sanitizer,
test_proxy,
remove_batch_sanitizers,
)


Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_build_classifier(self, client, documentintelligence_training_data_class
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)
Expand Down Expand Up @@ -160,7 +160,7 @@ def test_build_classifier_file_list(self, client, documentintelligence_training_
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async def test_build_classifier(self, client, documentintelligence_training_data
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)
Expand Down Expand Up @@ -165,7 +165,7 @@ async def test_build_classifier_file_list(
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
add_oauth_response_sanitizer,
add_body_key_sanitizer,
test_proxy,
remove_batch_sanitizers,
)

@pytest.fixture(scope="session", autouse=True)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_build_classifier(self, client, formrecognizer_training_data_classifier,
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()
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_build_classifier_file_list(self, client, formrecognizer_training_data_c
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def test_build_classifier(self, client, formrecognizer_training_data_class
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()
Expand Down Expand Up @@ -127,7 +127,7 @@ async def test_build_classifier_file_list(self, client, formrecognizer_training_
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
add_oauth_response_sanitizer,
add_uri_regex_sanitizer,
is_live,
remove_batch_sanitizers,
)

os.environ['PYTHONHASHSEED'] = '0'
Expand Down Expand Up @@ -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():
Expand Down
Loading
Loading