Skip to content

Instantly share code, notes, and snippets.

@denismakogon
Last active August 29, 2015 14:04
Show Gist options
  • Save denismakogon/0ed14d89b752630c4273 to your computer and use it in GitHub Desktop.
Save denismakogon/0ed14d89b752630c4273 to your computer and use it in GitHub Desktop.
def test_exception_and_masking_password(self):
fd, tmpfilename = tempfile.mkstemp()
fp = os.fdopen(fd, 'w+')
with open(tmpfilename, 'w') as fp:
fp.write('#!/bin/bash\n'
'# This is to test stdout and stderr\n'
'# when a non-zero exit code is returned\n'
'echo "This goes to stdout"\n'
'echo "This goes to stderr" 1>&2\n'
' exit 38\n')
os.chmod(tmpfilename, 0o755)
err = self.assertRaises(processutils.ProcessExecutionError,
processutils.execute,
tmpfilename, 'password="secret"', 'something')
self.assertEqual(err.exit_code, 38)
self.assertTrue(err.stdout == "This goes to stdout\n")
self.assertTrue(err.stderr == "This goes to stderr\n")
self.assertTrue(err.cmd == tmpfilename + ' ' +
'password="***" something')
self.assertFalse('password="secret"' in err.cmd)
self.assertTrue('password="***"' in err.cmd)
os.unlink(tmpfilename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment