-
Notifications
You must be signed in to change notification settings - Fork 3.4k
{Test} Add email replacer for cli scenario test #31262
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| import os | ||
| import re | ||
| from contextlib import contextmanager | ||
|
|
||
| from .scenario_tests import (create_random_name as create_random_name_base, RecordingProcessor) | ||
|
|
@@ -210,6 +211,29 @@ def process_response(self, response): | |
| return response | ||
|
|
||
|
|
||
| class EmailAddressReplacer(RecordingProcessor): | ||
| """Replace email address like xxx@microsoft.com with test@example.com""" | ||
|
|
||
| EMAIL_REPLACEMENT = 'test@example.com' | ||
|
|
||
| def _replace_email_address(self, text): | ||
| pattern = r'[\w.%#+-]+[%40|@|_]microsoft.com' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I loose the regex to recognize all string in the format of I'm thinking that as long as the microsoft part is replaced, then the full string will be invalid so I restricted the pattern to recognize |
||
| return re.sub(pattern, self.EMAIL_REPLACEMENT, text) | ||
|
|
||
| def process_request(self, request): | ||
| request.uri = self._replace_email_address(request.uri) | ||
| if request.body: | ||
| body = _byte_to_str(request.body) | ||
| request.body = self._replace_email_address(body) | ||
| return request | ||
|
|
||
| def process_response(self, response): | ||
| if response['body']['string']: | ||
| body = _byte_to_str(response['body']['string']) | ||
| response['body']['string'] = self._replace_email_address(body) | ||
| return response | ||
|
|
||
|
|
||
| class AADAuthRequestFilter(RecordingProcessor): | ||
| """Remove oauth authentication requests and responses from recording. | ||
| This is derived from OAuthRequestResponsesFilter. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any source for this regex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The source is me😂 Any issue with this pattern?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am curious how
%#+-are chosen. Could you provide some examples? I understand there are email addresses likeIsaac.Newton@microsoft.comwhich contain[\w.].Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for example,
v-zhangsan@microsoft.comcontains-. But for%#+, I don't have any sample on top of my mind