Skip to content

Commit a61a8e2

Browse files
authored
[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 <[email protected]>
1 parent 4c741c2 commit a61a8e2

File tree

47 files changed

+270
-228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+270
-228
lines changed

eng/target_proxy_version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0-dev.20240410.1
1+
1.0.0-dev.20240506.5

sdk/ai/azure-ai-generative/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def fake_datastore_key() -> str:
8686
return str(b64_key, "ascii")
8787

8888

89-
@pytest.fixture(autouse=True)
89+
@pytest.fixture(scope="session", autouse=True)
9090
def add_sanitizers(test_proxy, fake_datastore_key):
9191
"""Register recording sanitizers for the function under test"""
9292
add_remove_header_sanitizer(headers="x-azureml-token,Log-URL,Authorization")

sdk/ai/azure-ai-resources/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def fake_datastore_key() -> str:
100100
return str(b64_key, "ascii")
101101

102102

103-
@pytest.fixture(autouse=True)
103+
@pytest.fixture(scope="session", autouse=True)
104104
def add_sanitizers(test_proxy, fake_datastore_key):
105105
"""Register recording sanitizers for the function under test"""
106106
add_remove_header_sanitizer(headers="x-azureml-token,Log-URL,Authorization")

sdk/appconfiguration/azure-appconfiguration-provider/tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
add_general_string_sanitizer,
55
add_oauth_response_sanitizer,
66
set_custom_default_matcher,
7+
remove_batch_sanitizers,
78
)
89
import pytest
910

@@ -37,3 +38,8 @@ def add_sanitizers(test_proxy):
3738
add_general_regex_sanitizer(value="api-version=1970-01-01", regex="api-version=.+")
3839
set_custom_default_matcher(ignored_headers="x-ms-content-sha256, Accept", excluded_headers="Content-Length")
3940
add_oauth_response_sanitizer()
41+
42+
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
43+
# - AZSDK3430: $..id
44+
# - AZSDK3447: $.key
45+
remove_batch_sanitizers(["AZSDK3430", "AZSDK3447"])

sdk/appconfiguration/azure-appconfiguration/tests/conftest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# --------------------------------------------------------------------------
2626
import pytest
2727
import os
28-
from devtools_testutils import add_general_regex_sanitizer, test_proxy, set_bodiless_matcher
28+
from devtools_testutils import add_general_regex_sanitizer, test_proxy, set_bodiless_matcher, remove_batch_sanitizers
2929

3030

3131
@pytest.fixture(scope="session", autouse=True)
@@ -38,3 +38,9 @@ def add_sanitizers(test_proxy):
3838
add_general_regex_sanitizer(regex=client_secret, value="client-secret")
3939
tenant_id = os.environ.get("APPCONFIGURATION_TENANT_ID", "00000000-0000-0000-0000-000000000000")
4040
add_general_regex_sanitizer(value="00000000-0000-0000-0000-000000000000", regex=tenant_id)
41+
42+
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
43+
# - AZSDK3447: $.key
44+
# - AZSDK3490: $..etag
45+
# - AZSDK3493: $..name
46+
remove_batch_sanitizers(["AZSDK3447", "AZSDK3490", "AZSDK3493"])

sdk/cognitivelanguage/azure-ai-language-questionanswering/tests/conftest.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
# --------------------------------------------------------------------------
77
import pytest
88

9-
from devtools_testutils.sanitizers import add_header_regex_sanitizer, add_oauth_response_sanitizer
9+
from devtools_testutils.sanitizers import (
10+
add_header_regex_sanitizer,
11+
add_oauth_response_sanitizer,
12+
remove_batch_sanitizers
13+
)
1014

1115

1216
# Environment variable keys
@@ -40,6 +44,10 @@ def add_sanitizers(test_proxy, environment_variables):
4044
add_oauth_response_sanitizer()
4145
add_header_regex_sanitizer(key="Set-Cookie", value="[set-cookie;]")
4246

47+
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
48+
# - AZSDK3430: $..id
49+
remove_batch_sanitizers(["AZSDK3430"])
50+
4351

4452
@pytest.fixture(scope="session")
4553
def qna_creds(environment_variables):

sdk/communication/azure-communication-callautomation/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/communication/azure-communication-callautomation",
5-
"Tag": "python/communication/azure-communication-callautomation_707ce35a60"
5+
"Tag": "python/communication/azure-communication-callautomation_ab7206cdd8"
66
}

sdk/communication/azure-communication-callautomation/tests/conftest.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
set_default_session_settings,
1212
add_body_key_sanitizer,
1313
add_general_string_sanitizer,
14+
remove_batch_sanitizers,
1415
)
1516

1617
# 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):
2425
add_general_string_sanitizer(target=connection_str, value=fake_connection_str)
2526

2627
add_general_regex_sanitizer(regex="https://[^/]+", value="https://sanitized")
27-
add_body_key_sanitizer(json_path="callbackUri", value="https://sanitized")
28+
add_body_key_sanitizer(json_path="callbackUri", value="https://sanitized/")
2829
add_body_key_sanitizer(json_path="$..file.uri", value="https://REDACTED/prompt.wav")
2930
add_header_regex_sanitizer(key="Set-Cookie", value="sanitized")
3031
add_header_regex_sanitizer(key="Date", value="sanitized")
@@ -40,4 +41,8 @@ def start_proxy(test_proxy):
4041
add_header_regex_sanitizer(key="Repeatability-First-Sent", value="sanitized")
4142
add_header_regex_sanitizer(key="Repeatability-Request-ID", value="sanitized")
4243

43-
return
44+
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
45+
# - AZSDK3430: $..id
46+
remove_batch_sanitizers(["AZSDK3430"])
47+
48+
return

sdk/communication/azure-communication-jobrouter/tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
set_default_session_settings,
3636
add_uri_regex_sanitizer,
3737
add_body_key_sanitizer,
38+
remove_batch_sanitizers,
3839
)
3940
from router_test_constants import SANITIZED, FAKE_FUNCTION_URI, FAKE_ENDPOINT, FAKE_CONNECTION_STRING
4041
from azure.communication.jobrouter._shared.utils import parse_connection_str
@@ -69,6 +70,11 @@ def start_proxy(test_proxy):
6970
add_body_key_sanitizer(json_path="$..functionKey", value=SANITIZED)
7071
add_body_key_sanitizer(json_path="$..appKey", value=SANITIZED)
7172
add_body_key_sanitizer(json_path="$..clientId", value=SANITIZED)
73+
74+
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
75+
# - AZSDK3430: $..id
76+
# - AZSDK3493: $..name
77+
remove_batch_sanitizers(["AZSDK3430", "AZSDK3493"])
7278
return
7379

7480

sdk/communication/azure-communication-phonenumbers/test/conftest.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
add_general_string_sanitizer,
77
add_general_regex_sanitizer,
88
add_header_regex_sanitizer,
9-
test_proxy
9+
test_proxy,
10+
remove_batch_sanitizers,
1011
)
1112

1213

@@ -45,10 +46,10 @@ def add_sanitizers(test_proxy):
4546
add_body_key_sanitizer(json_path="phoneNumbers[*].id", value="sanitized")
4647
add_body_key_sanitizer(
4748
json_path="phoneNumbers[*].phoneNumber", value="sanitized")
48-
49+
4950
add_general_regex_sanitizer(
5051
regex=r"-[0-9a-fA-F]{32}\.[0-9a-zA-Z\.]*(\.com|\.net|\.test)", value=".sanitized.com")
51-
52+
5253
add_general_regex_sanitizer(regex=r"(?:(?:%2B)|\+)\d{10,15}", value="sanitized")
5354

5455
add_general_regex_sanitizer(
@@ -68,3 +69,9 @@ def add_sanitizers(test_proxy):
6869
add_header_regex_sanitizer(key="x-ms-request-id", value="sanitized")
6970
add_header_regex_sanitizer(
7071
key="Content-Security-Policy-Report-Only", value="sanitized")
72+
73+
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
74+
# - AZSDK3493: $..name
75+
# - AZSDK2003: Location
76+
remove_batch_sanitizers(["AZSDK3493", "AZSDK2003"])
77+

sdk/communication/azure-communication-rooms/tests/conftest.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@
2525
# --------------------------------------------------------------------------
2626
import pytest
2727
import os
28-
from devtools_testutils import add_general_string_sanitizer, add_header_regex_sanitizer, add_body_key_sanitizer, set_default_session_settings
28+
from devtools_testutils import (
29+
add_general_string_sanitizer,
30+
add_header_regex_sanitizer,
31+
set_default_session_settings,
32+
remove_batch_sanitizers,
33+
)
2934
from azure.communication.rooms._shared.utils import parse_connection_str
3035

3136
@pytest.fixture(scope="session", autouse=True)
@@ -52,3 +57,7 @@ def add_sanitizers(test_proxy):
5257
key="Content-Security-Policy-Report-Only", value="sanitized")
5358
add_header_regex_sanitizer(key="Repeatability-First-Sent", value="sanitized")
5459
add_header_regex_sanitizer(key="Repeatability-Request-ID", value="sanitized")
60+
61+
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
62+
# - AZSDK3430: $..id
63+
remove_batch_sanitizers(["AZSDK3430"])

sdk/containerregistry/azure-containerregistry/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/containerregistry/azure-containerregistry",
5-
"Tag": "python/containerregistry/azure-containerregistry_790d3fef6e"
5+
"Tag": "python/containerregistry/azure-containerregistry_02a9c147da"
66
}

sdk/containerregistry/azure-containerregistry/tests/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
add_uri_regex_sanitizer,
1414
test_proxy,
1515
is_live,
16+
remove_batch_sanitizers,
1617
)
1718
from testcase import import_image, is_public_endpoint
1819
from constants import HELLO_WORLD
@@ -54,3 +55,10 @@ def add_sanitizers(test_proxy):
5455
add_general_regex_sanitizer(regex=client_id, value="client-id")
5556
client_secret = os.environ.get("CONTAINERREGISTRY_CLIENT_SECRET", "client-secret")
5657
add_general_regex_sanitizer(regex=client_secret, value="client-secret")
58+
tenant_id = os.environ.get("CONTAINERREGISTRY_TENANT_ID", "tenant-id")
59+
add_general_regex_sanitizer(regex=tenant_id, value="00000000-0000-0000-0000-000000000000")
60+
61+
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
62+
# - AZSDK3493: $..name
63+
# - AZSDK2003: Location
64+
remove_batch_sanitizers(["AZSDK3493", "AZSDK2003"])

sdk/core/azure-core/README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@ These libraries follow the [Azure SDK Design Guidelines for Python](https://azur
66

77
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.
88

9-
[Source code](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/)
9+
[Source code](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/)
1010
| [Package (Pypi)][package]
1111
| [Package (Conda)](https://anaconda.org/microsoft/azure-core/)
1212
| [API reference documentation](https://docs.microsoft.com/python/api/overview/azure/core-readme)
1313

14-
## _Disclaimer_
15-
16-
_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>_
17-
1814
## Getting started
1915

2016
Typically, you will not need to install azure core;

sdk/documentintelligence/azure-ai-documentintelligence/tests/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
add_oauth_response_sanitizer,
1616
add_body_key_sanitizer,
1717
test_proxy,
18+
remove_batch_sanitizers,
1819
)
1920

2021

@@ -38,6 +39,9 @@ def add_sanitizers(test_proxy):
3839
value="redacted",
3940
regex="([0-9a-f-]{36})",
4041
)
42+
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
43+
# - AZSDK3496: "$..resourceLocation"
44+
remove_batch_sanitizers(["AZSDK3496"])
4145

4246

4347
def skip_flaky_test(f):

sdk/documentintelligence/azure-ai-documentintelligence/tests/test_dmac_classifiers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_build_classifier(self, client, documentintelligence_training_data_class
7474
assert len(result.doc_types) == 5
7575
for doc_type, doc_details in result.doc_types.items():
7676
assert doc_type
77-
assert doc_details.azure_blob_source.container_url.endswith("training-data-classifier")
77+
assert doc_details.azure_blob_source.container_url
7878
assert doc_details.azure_blob_source.prefix.startswith(doc_type)
7979

8080
classifier = client.get_classifier(result.classifier_id)
@@ -160,7 +160,7 @@ def test_build_classifier_file_list(self, client, documentintelligence_training_
160160
assert len(result.doc_types) == 5
161161
for doc_type, doc_details in result.doc_types.items():
162162
assert doc_type
163-
assert doc_details.azure_blob_file_list_source.container_url.endswith("training-data-classifier")
163+
assert doc_details.azure_blob_file_list_source.container_url
164164
assert doc_details.azure_blob_file_list_source.file_list.startswith(doc_type)
165165

166166
classifier = client.get_classifier(result.classifier_id)

sdk/documentintelligence/azure-ai-documentintelligence/tests/test_dmac_classifiers_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ async def test_build_classifier(self, client, documentintelligence_training_data
7676
assert len(result.doc_types) == 5
7777
for doc_type, doc_details in result.doc_types.items():
7878
assert doc_type
79-
assert doc_details.azure_blob_source.container_url.endswith("training-data-classifier")
79+
assert doc_details.azure_blob_source.container_url
8080
assert doc_details.azure_blob_source.prefix.startswith(doc_type)
8181

8282
classifier = await client.get_classifier(result.classifier_id)
@@ -165,7 +165,7 @@ async def test_build_classifier_file_list(
165165
assert len(result.doc_types) == 5
166166
for doc_type, doc_details in result.doc_types.items():
167167
assert doc_type
168-
assert doc_details.azure_blob_file_list_source.container_url.endswith("training-data-classifier")
168+
assert doc_details.azure_blob_file_list_source.container_url
169169
assert doc_details.azure_blob_file_list_source.file_list.startswith(doc_type)
170170

171171
classifier = await client.get_classifier(result.classifier_id)

sdk/formrecognizer/azure-ai-formrecognizer/tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
add_oauth_response_sanitizer,
1818
add_body_key_sanitizer,
1919
test_proxy,
20+
remove_batch_sanitizers,
2021
)
2122

2223
@pytest.fixture(scope="session", autouse=True)
@@ -42,6 +43,10 @@ def add_sanitizers(test_proxy):
4243
value="redacted",
4344
regex="([0-9a-f-]{36})",
4445
)
46+
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
47+
# - AZSDK3447: $.key
48+
# - AZSDK2003: Location
49+
remove_batch_sanitizers(["AZSDK3447", "AZSDK2003"])
4550

4651
def skip_flaky_test(f):
4752
@wraps(f)

sdk/formrecognizer/azure-ai-formrecognizer/tests/test_dmac_classifiers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def test_build_classifier(self, client, formrecognizer_training_data_classifier,
6969
assert result.description == "IRS document classifier"
7070
for doc_type, source in result.doc_types.items():
7171
assert doc_type
72-
assert source.source.container_url.endswith("training-data-classifier")
72+
assert source.source.container_url
7373
assert source.source.prefix
7474

7575
@FormRecognizerPreparer()
@@ -124,7 +124,7 @@ def test_build_classifier_file_list(self, client, formrecognizer_training_data_c
124124
assert result.description is None
125125
for doc_type, source in result.doc_types.items():
126126
assert doc_type
127-
assert source.source.container_url.endswith("training-data-classifier")
127+
assert source.source.container_url
128128
assert source.source.file_list
129129

130130
@FormRecognizerPreparer()

sdk/formrecognizer/azure-ai-formrecognizer/tests/test_dmac_classifiers_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async def test_build_classifier(self, client, formrecognizer_training_data_class
7171
assert result.description == "IRS document classifier"
7272
for doc_type, source in result.doc_types.items():
7373
assert doc_type
74-
assert source.source.container_url.endswith("training-data-classifier")
74+
assert source.source.container_url
7575
assert source.source.prefix
7676

7777
@FormRecognizerPreparer()
@@ -127,7 +127,7 @@ async def test_build_classifier_file_list(self, client, formrecognizer_training_
127127
assert result.description is None
128128
for doc_type, source in result.doc_types.items():
129129
assert doc_type
130-
assert source.source.container_url.endswith("training-data-classifier")
130+
assert source.source.container_url
131131
assert source.source.file_list
132132

133133
@FormRecognizerPreparer()

sdk/healthinsights/azure-healthinsights-radiologyinsights/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/healthinsights/azure-healthinsights-radiologyinsights",
5-
"Tag": "python/healthinsights/azure-healthinsights-radiologyinsights_69d7fab8d7"
5+
"Tag": "python/healthinsights/azure-healthinsights-radiologyinsights_d1fac89a24"
66
}

sdk/healthinsights/azure-healthinsights-radiologyinsights/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ def add_sanitizers(test_proxy):
3939
)
4040
healthinsights_key = os.environ.get("HEALTHINSIGHTS_KEY", "00000000000000000000000000000000")
4141
add_general_regex_sanitizer(
42-
regex=healthinsights_endpoint, value="https://fake_ad_resource.cognitiveservices.azure.com"
42+
regex=healthinsights_endpoint, value="https://fake_ad_resource.cognitiveservices.azure.com/"
4343
)
4444
add_general_regex_sanitizer(regex=healthinsights_key, value="00000000000000000000000000000000")

sdk/keyvault/azure-keyvault-administration/tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
add_oauth_response_sanitizer,
1414
add_uri_regex_sanitizer,
1515
is_live,
16+
remove_batch_sanitizers,
1617
)
1718

1819
os.environ['PYTHONHASHSEED'] = '0'
@@ -48,6 +49,11 @@ def add_sanitizers(test_proxy):
4849
add_uri_regex_sanitizer(regex="keys/([^/]*)\\?api-version=(\\S*)", value="keys/$1?api-version=sanitized")
4950
add_oauth_response_sanitizer()
5051

52+
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
53+
# - AZSDK3430: $..id
54+
# - AZSDK3493: $..name
55+
remove_batch_sanitizers(["AZSDK3430", "AZSDK3493"])
56+
5157

5258
@pytest.fixture(scope="session", autouse=True)
5359
def patch_async_sleep():

0 commit comments

Comments
 (0)