Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions awscli/customizations/codeartifact/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class CommandFailedError(Exception):
def __init__(self, called_process_error, auth_token):
msg = str(called_process_error).replace(auth_token, '******')
if called_process_error.stderr is not None:
msg +=(
f' Stderr from command:\n'
f'{called_process_error.stderr.decode(get_stderr_encoding())}'
)
stderr = called_process_error.stderr.decode(
get_stderr_encoding()
).replace(auth_token, '******')
msg += f' Stderr from command:\n{stderr}'
Exception.__init__(self, msg)


Expand Down
15 changes: 15 additions & 0 deletions tests/unit/customizations/codeartifact/test_adapter_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ def test_run_commands_command_failed_redact_auth_token(self):
):
self.test_subject._run_commands('tool', ['cmd'])

def test_run_commands_command_failed_redact_auth_token_in_stderr(self):
error_to_be_caught = subprocess.CalledProcessError(
returncode=1,
cmd=['cmd'],
output=None,
stderr=b'Command error message containing auth-token here.'
)
self.subprocess_utils.run.side_effect = error_to_be_caught
with self.assertRaisesRegex(
CommandFailedError,
rf"(?=.*cmd)(?!.*auth-token)"
rf"(?=.*Stderr from command:\nCommand error message containing \*\*\*\*\*\* here.)"
):
self.test_subject._run_commands('tool', ['cmd'])

def test_run_commands_nonexistent_command(self):
self.subprocess_utils.run.side_effect = OSError(
errno.ENOENT, 'not found error'
Expand Down