Skip to content

Commit

Permalink
python 2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
narrieta committed Apr 25, 2023
1 parent edd6b0b commit 60cf7c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion azurelinuxagent/common/utils/extensionprocessutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def handle_process_completion(process, command, timeout, stdout, stderr, error_c
return process_output


SAS_TOKEN_RE = re.compile(r'(https://\S+\?)((sv|st|se|sr|sp|sip|spr|sig)=\S+)+', flags=re.IGNORECASE)


def read_output(stdout, stderr):
"""
Read the output of the process sent to stdout and stderr and trim them to the max appropriate length.
Expand All @@ -106,7 +109,7 @@ def read_output(stdout, stderr):

def redact(s):
# redact query strings that look like SAS tokens
return re.sub(r'(https://\S+\?)((sv|st|se|sr|sp|sip|spr|sig)=\S+)+', r'\1<redacted>', s, flags=re.IGNORECASE)
return SAS_TOKEN_RE.sub(r'\1<redacted>', s)

return format_stdout_stderr(redact(stdout), redact(stderr))
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion tests/ga/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -3418,7 +3418,7 @@ def http_get_handler(url, *_, **kwargs):
self._assert_handler_status(protocol.report_vm_status, "Ready", 1, "1.0.0")
self.assertEqual("1", protocol.report_vm_status.call_args[0][0].vmAgent.vm_artifacts_aggregate_status.goal_state_aggregate_status.in_svd_seq_no, "SVD sequence number mismatch")

def test_it_should_(self):
def test_it_should_redact_access_tokens_in_extension_output(self):
original = r'''ONE https://foo.blob.core.windows.net/bar?sv=2000&ss=bfqt&srt=sco&sp=rw&se=2025&st=2022&spr=https&sig=SI%3D
TWO:HTTPS://bar.blob.core.com/foo/bar/foo.txt?sv=2018&sr=b&sig=Yx%3D&st=2023%3A52Z&se=9999%3A59%3A59Z&sp=r TWO
https://bar.com/foo?uid=2018&sr=b THREE'''
Expand Down

0 comments on commit 60cf7c1

Please sign in to comment.