File tree Expand file tree Collapse file tree 1 file changed +18
-11
lines changed
src/azure-cli-testsdk/azure/cli/testsdk Expand file tree Collapse file tree 1 file changed +18
-11
lines changed Original file line number Diff line number Diff line change @@ -216,23 +216,30 @@ class EmailAddressReplacer(RecordingProcessor):
216216
217217 EMAIL_REPLACEMENT = '[email protected] ' 218218
219+ def _replace_email_address (self , text ):
220+ pattern = r'[\w.%#+-]+[%40|@|_]microsoft.com'
221+ index = 0
222+ replaced_text = ''
223+ for match in re .finditer (pattern , text ):
224+ start = match .start ()
225+ end = match .end ()
226+ replaced_text += text [index :start ] + self .EMAIL_REPLACEMENT
227+ index = end
228+ if index < len (text ):
229+ replaced_text += text [index :]
230+ return replaced_text
231+
219232 def process_request (self , request ):
233+ request .uri = self ._replace_email_address (request .uri )
234+ if request .body :
235+ body = _byte_to_str (request .body )
236+ request .body = self ._replace_email_address (body )
220237 return request
221238
222239 def process_response (self , response ):
223240 if response ['body' ]['string' ]:
224241 body = _byte_to_str (response ['body' ]['string' ])
225- pattern = r'[\w.%#+-]+[%40|@|_]microsoft.com'
226- index = 0
227- replaced_body = ''
228- for match in re .finditer (pattern , body ):
229- start = match .start ()
230- end = match .end ()
231- replaced_body += body [index :start ] + self .EMAIL_REPLACEMENT
232- index = end
233- if index < len (body ):
234- replaced_body += body [index :]
235- response ['body' ]['string' ] = replaced_body
242+ response ['body' ]['string' ] = _replace_email_address (body )
236243 return response
237244
238245
You can’t perform that action at this time.
0 commit comments