You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/test/units
Adrian Likins 29bdd0b326 Better handling of malformed vault data envelope (#32515)
If an embedded vaulted variable ('!vault' in yaml)
had an invalid format, it would eventually cause
an error for seemingly unrelated reasons.
"Invalid" meaning not valid hexlify (extra chars,
non-hex chars, etc).

For ex, if a host_vars file had invalid vault format
variables, on py2, it would cause an error like:

  'ansible.vars.hostvars.HostVars object' has no
  attribute u'broken.example.com'

Depending on where the invalid vault is, it could
also cause "VARIABLE IS NOT DEFINED!". The behavior
can also change if ansible-playbook is py2 or py3.

Root cause is errors from binascii.unhexlify() not
being handled consistently.

Fix is to add a AnsibleVaultFormatError exception and
raise it on any unhexlify() errors and to handle it
properly elsewhere.

Add a _unhexlify() that try/excepts around a binascii.unhexlify()
and raises an AnsibleVaultFormatError on invalid vault data.
This is so the same exception type is always raised for this
case. Previous it was different between py2 and py3.

binascii.unhexlify() raises a binascii.Error if the hexlified
blobs in a vault data blob are invalid.

On py2, binascii.Error is a subclass of Exception.
On py3, binascii.Error is a subclass of TypeError

When decrypting content of vault encrypted variables,
if a binascii.Error is raised it propagates up to
playbook.base.Base.post_validate(). post_validate()
handles exceptions for TypeErrors but not for
base Exception subclasses (like py2 binascii.Error).

* Add a display.warning on vault format errors
* Unit tests for _unhexlify, parse_vaulttext*
* Add intg test cases for invalid vault formats

Fixes #28038

(cherry picked from commit 9c58827410)
8 years ago
..
cli Don't ask for password confirm on 'ansible-vault edit' (#30514) 8 years ago
contrib Update vmware_inventory (#26308) 9 years ago
errors test/: PEP8 compliancy (#24803) 9 years ago
executor better cleanup on task results display (#27175) 8 years ago
inventory INI inventory plugin: add documentation about variable types (#25798) 9 years ago
inventory_test_data/group_vars Merge branch 'v2_final' into devel_switch_v2 11 years ago
mock Support multiple vault passwords (#22756) 9 years ago
module_utils Make ansible_selinux facts a consistent type (#31065) 8 years ago
modules Fix ios_config file prompt issue (#32744) (#32780) 8 years ago
parsing Better handling of malformed vault data envelope (#32515) 8 years ago
playbook Fix include_role unit tests (#31920) 8 years ago
plugins tests for InventoryModule error conditions (#31381) 8 years ago
template template: fix KeyError: 'undefined variable: 0 (#27972) 9 years ago
utils test/: PEP8 compliancy (#24803) 9 years ago
vars make groups magic var dependant on inventory (#28677) 8 years ago
__init__.py Add empty-init code-smell script. (#18406) 9 years ago
ansible.cfg Fix ansible-test config management. 8 years ago
conftest.py Fix bugs in ansible-test units command. (#24044) 9 years ago
test_constants.py 1st part of ansible config, adds ansible-config to view/manage configs (#12797) 9 years ago