Skip to content

Commit

Permalink
Increase verbosity for tests on CI, enable stderr on error
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Feb 25, 2021
1 parent d7948a1 commit f2c9ece
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions infracheck/checks/ssh-fingerprint
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ class SshFingerprintScan:

@staticmethod
def _get_fingerprint(domain: str, method: str, port: int) -> str:
out = subprocess.check_output(['ssh-keyscan', '-t', method, '-p', str(port), domain], stderr=subprocess.DEVNULL)
return out.decode('utf-8')
try:
out = subprocess.check_output(['ssh-keyscan', '-t', method, '-p', str(port), domain],
stderr=subprocess.PIPE)

return out.decode('utf-8')
except subprocess.CalledProcessError as err:
return err.stderr.decode('utf-8') + "\n" + err.stdout.decode('utf-8')


if __name__ == '__main__':
Expand Down
10 changes: 10 additions & 0 deletions tests/functional_test_ssh_fingerprint_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,13 @@ def test_missing_host_parameter(self):

self.assertIn('You need to provide a HOST', result.output.strip())
self.assertFalse(result.exit_status)

def test_reports_stderr_messages(self):
result = run_check('ssh-fingerprint', {
'HOST': 'non-existing-host',
'PORT': 3222,
'EXPECTED_FINGERPRINT': 'BAKUNIN'
}, {})

self.assertIn('getaddrinfo non-existing-host: Name or service not known', result.output.strip())
self.assertFalse(result.exit_status)

0 comments on commit f2c9ece

Please sign in to comment.