{Test} Add email replacer for cli scenario test#31262
Conversation
️✔️AzureCLI-FullTest
|
|
Hi @evelyn-ys, |
️✔️AzureCLI-BreakingChangeTest
|
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
| for match in re.finditer(pattern, text): | ||
| start = match.start() | ||
| end = match.end() | ||
| replaced_text += text[index:start] + self.EMAIL_REPLACEMENT | ||
| index = end |
| EMAIL_REPLACEMENT = 'test@example.com' | ||
|
|
||
| def _replace_email_address(self, text): | ||
| pattern = r'[\w.%#+-]+[%40|@|_]microsoft.com' |
There was a problem hiding this comment.
The source is me😂 Any issue with this pattern?
There was a problem hiding this comment.
I am curious how %#+- are chosen. Could you provide some examples? I understand there are email addresses like Isaac.Newton@microsoft.com which contain [\w.].
There was a problem hiding this comment.
for example, v-zhangsan@microsoft.com contains -. But for %#+, I don't have any sample on top of my mind
| EMAIL_REPLACEMENT = 'test@example.com' | ||
|
|
||
| def _replace_email_address(self, text): | ||
| pattern = r'[\w.%#+-]+[%40|@|_]microsoft.com' |
There was a problem hiding this comment.
For test_microsoft.com#EXT#@AzureSDKTeam.onmicrosoft.com, this regex only replaces the test_microsoft.com part. Should we consider replacing the full string test_microsoft.com#EXT#@AzureSDKTeam.onmicrosoft.com to avoid showing the tenant domain too?
There was a problem hiding this comment.
If I loose the regex to recognize all string in the format of xxx@xxx.xx, then test_microsoft.com#EXT#@AzureSDKTeam.onmicrosoft can be replaced, but there will be many mismatch for example ssh@10.172 and the recording file can't work.
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 [@|%40|_]microsoft.com only
Related command
Description
During recording tests, we may unintentionally record real email addresses in recording yaml files. This PR adds EmailAddressReplacer for ScenarioTests during live run to replace all microsoft email addresses with test@example.com
Please note that this replacer will only work during live run, so no existing recording files will be affected
Testing Guide
See the new test recording file
test_keyvault_private_endpoint_connection.yamlin commitTo try by yourself, run
azdev test $TEST_NAME --livewith any test that may record real email address and see the new recording fileHistory Notes
[Component Name 1] BREAKING CHANGE:
az command a: Make some customer-facing breaking change[Component Name 2]
az command b: Add some customer-facing featureThis checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.