1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/test/units
Marius Gedminas 2efb692cc4 known_hosts: support --diff (#20349)
* known_hosts: support --diff

* known_hosts: support --diff also without --check

* Add unit tests and fix incorrect diff in one corner case

Tests are good!

* Refactor for readability

* Python 3 compat

* More Python 3 compat

* Add an integration test for known_hosts

* Handle ssh-keygen -HF returning non-zero exit code

AFAICT this is a bug in ssh-keygen in some newer OpenSSH versions
(>= 6.4 probably; see commit dd9d5cc670):
when you invoke ssh-keygen with -H and -F <host> options, it always
returns exit code 1.  This is because in ssh-keygen.c there's a function
do_known_hosts() which calls

  exit (find_host && !ctx.found_key);

at the end, and find_host is 1 (because we passed -F on the command line),
but ctx.found_key is always 0.  Why is found_key always 0?  Because the
callback passed to hostkeys_foreach(), which is known_hosts_hash(),
never bothers to set found_key to 1.

* This test does not need root

* Avoid ssh-ed25519 keys in sample known_hosts file

Older versions of OpenSSH do not like them and ssh-keygen -HF
aborts with an error when it sees such keys:

  line 5 invalid key: example.net...
  /root/ansible_testing/known_hosts is not a valid known_hosts file.

* Fix Python 3 errors

Specifically, the default mode of tempfile.NamedTemporaryFile is 'w+b',
which means Python 3 wants us to write bytes objects to it -- but the
keys we have are all unicode strings.
2017-02-08 09:56:03 -05:00
..
cli PEP 8 E111 & E114 cleanup. (#20838) 2017-01-30 15:01:47 -08:00
contrib PEP 8 W291 whitespace cleanup. 2017-01-27 17:08:02 -08:00
errors Add empty-init code-smell script. (#18406) 2016-11-07 15:02:13 -08:00
executor Combine jimi-c and bcoca's ideas and work on hooking module-utils into PluginLoader. 2017-01-31 09:41:24 -08:00
inventory Add lots of test cases to inventory/test_host.py (#17827) 2016-11-29 13:38:04 -05:00
inventory_test_data/group_vars Merge branch 'v2_final' into devel_switch_v2 2015-05-28 15:26:03 -05:00
mock Fix @contextmanager leak on exception. (#21031) 2017-02-03 17:19:59 -08:00
module_utils Fix @contextmanager leak on exception. (#21031) 2017-02-03 17:19:59 -08:00
modules known_hosts: support --diff (#20349) 2017-02-08 09:56:03 -05:00
parsing added docs for vault and made trigger shorter: !vault (#20985) 2017-02-03 15:28:50 -05:00
playbook PEP 8 indent cleanup. (#20800) 2017-01-29 07:28:53 +00:00
plugins Fix action test (#21102) 2017-02-07 13:35:51 -05:00
template PEP 8 indent cleanup. (#20800) 2017-01-29 07:28:53 +00:00
utils PEP 8 indent cleanup. (#20800) 2017-01-29 07:28:53 +00:00
vars PEP 8 indent cleanup. (#20800) 2017-01-29 07:28:53 +00:00
__init__.py Add empty-init code-smell script. (#18406) 2016-11-07 15:02:13 -08:00