Skip to content

Commit a61a8e2

Browse files
authored
[CI] Test updates for central sanitizers (Azure#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+

0 commit comments

Comments
 (0)