-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Graph] Support special characters in object names (#22739)
- Loading branch information
Showing
5 changed files
with
424 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,26 +180,33 @@ def process_response(self, response): | |
return response | ||
|
||
|
||
class MSGraphUserReplacer(RecordingProcessor): | ||
def __init__(self, test_user, mock_user): | ||
self.test_user = test_user | ||
self.mock_user = mock_user | ||
class MSGraphNameReplacer(RecordingProcessor): | ||
"""If a name appears in URL, it should be percent-encoded, e.g. | ||
- test-name+/ is encoded as test-name%2B%2F | ||
- [email protected] is encoded as example%40example.com | ||
Theoretically, GeneralNameReplacer should also follow this pattern, but since we haven't seen any ARM name that | ||
is percent-encoded, we only replace percent-encoded names for MS Graph for better test performance. | ||
""" | ||
def __init__(self, test_name, mock_name): | ||
from urllib.parse import quote | ||
self.test_name = test_name | ||
self.test_name_encoded = quote(test_name, safe='') | ||
self.mock_name = mock_name | ||
self.mock_name_encoded = quote(mock_name, safe='') | ||
|
||
def process_request(self, request): | ||
if self.test_user in request.uri: | ||
request.uri = request.uri.replace(self.test_user, self.mock_user) | ||
request.uri = request.uri.replace(self.test_name_encoded, self.mock_name_encoded) | ||
|
||
if request.body: | ||
body = _byte_to_str(request.body) | ||
if self.test_user in body: | ||
request.body = body.replace(self.test_user, self.mock_user) | ||
request.body = body.replace(self.test_name, self.mock_name) | ||
|
||
return request | ||
|
||
def process_response(self, response): | ||
if response['body']['string']: | ||
response['body']['string'] = response['body']['string'].replace(self.test_user, | ||
self.mock_user) | ||
response['body']['string'] = response['body']['string'].replace(self.test_name, self.mock_name) | ||
return response | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.