Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test Proxy] Add registration methods for all sanitizers #20819

Merged
merged 3 commits into from
Oct 4, 2021
Merged
Changes from 1 commit
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
62 changes: 23 additions & 39 deletions tools/azure-sdk-tools/devtools_testutils/sanitizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ def add_body_key_sanitizer(**kwargs):
a simple replacement operation.
"""

request_args = {}
request_args["jsonPath"] = kwargs.get("json_path")
request_args["value"] = kwargs.get("value")
request_args["regex"] = kwargs.get("regex")
request_args["groupForReplace"] = kwargs.get("group_for_replace")

request_args = _get_request_args(**kwargs)
_send_request("BodyKeySanitizer", request_args)


Expand All @@ -50,11 +45,7 @@ def add_body_regex_sanitizer(**kwargs):
a simple replacement operation.
"""

request_args = {}
request_args["value"] = kwargs.get("value")
request_args["regex"] = kwargs.get("regex")
request_args["groupForReplace"] = kwargs.get("group_for_replace")

request_args = _get_request_args(**kwargs)
_send_request("BodyRegexSanitizer", request_args)


Expand All @@ -73,11 +64,7 @@ def add_continuation_sanitizer(**kwargs):
same value?
"""

request_args = {}
request_args["key"] = kwargs.get("key")
request_args["method"] = kwargs.get("method")
request_args["resetAfterFirst"] = kwargs.get("reset_after_first")

request_args = _get_request_args(**kwargs)
_send_request("ContinuationSanitizer", request_args)


Expand All @@ -94,11 +81,7 @@ def add_general_regex_sanitizer(**kwargs):
a simple replacement operation.
"""

request_args = {}
request_args["value"] = kwargs.get("value")
request_args["regex"] = kwargs.get("regex")
request_args["groupForReplace"] = kwargs.get("group_for_replace")

request_args = _get_request_args(**kwargs)
_send_request("GeneralRegexSanitizer", request_args)


Expand All @@ -118,12 +101,7 @@ def add_header_regex_sanitizer(**kwargs):
a simple replacement operation.
"""

request_args = {}
request_args["key"] = kwargs.get("key")
request_args["value"] = kwargs.get("value")
request_args["regex"] = kwargs.get("regex")
request_args["groupForReplace"] = kwargs.get("group_for_replace")

request_args = _get_request_args(**kwargs)
_send_request("HeaderRegexSanitizer", request_args)


Expand All @@ -142,9 +120,7 @@ def add_remove_header_sanitizer(**kwargs):
those lines. Don't worry about whitespace between the commas separating each key. They will be ignored.
"""

request_args = {}
request_args["headersForRemoval"] = kwargs.get("headers")

request_args = _get_request_args(**kwargs)
_send_request("RemoveHeaderSanitizer", request_args)


Expand All @@ -157,9 +133,7 @@ def add_request_subscription_id_sanitizer(**kwargs):
:keyword str value: The fake subscriptionId that will be placed where the real one is in the real request.
"""

request_args = {}
request_args["value"] = kwargs.get("value") or "fakevalue"

request_args = _get_request_args(**kwargs)
_send_request("ReplaceRequestSubscriptionId", request_args)


Expand All @@ -174,14 +148,24 @@ def add_uri_regex_sanitizer(**kwargs):
a simple replacement operation.
"""

request_args = _get_request_args(**kwargs)
_send_request("UriRegexSanitizer", request_args)


def _get_request_args(**kwargs):
# type: (**Any) -> Dict
"""Returns a dictionary of sanitizer constructor headers"""

request_args = {}
request_args["value"] = kwargs.get("value") or "fakevalue"
request_args["regex"] = (
kwargs.get("regex") or "(?<=\\/\\/)[a-z]+(?=(?:|-secondary)\\.(?:table|blob|queue)\\.core\\.windows\\.net)"
Copy link
Member

Choose a reason for hiding this comment

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

why getting rid of the second regex in your updates?

Copy link
Member Author

Choose a reason for hiding this comment

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

Having a storage-centric URI regex as the default regex doesn't really seem ideal going forward, so I thought I'd remove it while doing the refactoring to get request args from a helper method -- I'll try tracking down a more general URI regex that we could use here as a default, but until then I think it makes sense to remove since we have a regex that will work with Tables during the test refactoring

)
request_args["groupForReplace"] = kwargs.get("group_for_replace")

_send_request("UriRegexSanitizer", request_args)
request_args["headersForRemoval"] = kwargs.get("headers")
request_args["jsonPath"] = kwargs.get("json_path")
request_args["key"] = kwargs.get("key")
request_args["method"] = kwargs.get("method")
request_args["regex"] = kwargs.get("regex")
request_args["resetAfterFirst"] = kwargs.get("reset_after_first")
request_args["value"] = kwargs.get("value")
return request_args


def _send_request(sanitizer, parameters):
Expand Down