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
5 changes: 4 additions & 1 deletion awscli/customizations/codeartifact/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ 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:
stderr = called_process_error.stderr.decode(
get_stderr_encoding()
).replace(auth_token, '******')
msg +=(
f' Stderr from command:\n'
f'{called_process_error.stderr.decode(get_stderr_encoding())}'
f'{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_from_stderr(self):
error_to_be_caught = subprocess.CalledProcessError(
returncode=1,
cmd=['cmd', 'with', 'auth-token', 'present'],
output=None,
stderr=b'Command error included auth-token.'
)
self.subprocess_utils.run.side_effect = error_to_be_caught
with self.assertRaises(CommandFailedError) as cm:
self.test_subject._run_commands('tool', ['cmd'])
error_message = str(cm.exception)
self.assertNotIn('auth-token', error_message)
self.assertIn('Stderr from command:\nCommand error included ******.',
error_message)

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