ansible/test/integration
Adrian Likins 9c58827410
Better handling of malformed vault data envelope (#32515)
* Better handling of malformed vault data envelope

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
2017-11-10 14:24:56 -05:00
..
targets Better handling of malformed vault data envelope (#32515) 2017-11-10 14:24:56 -05:00
asa.yaml
cloud-config-aws.yml.template Add region to ansible-test AWS cloud config. (#30733) 2017-09-22 00:19:21 -07:00
cloud-config-azure.yml.template
cloud-config-cs.ini.template
dellos6.yaml
dellos9.yaml
dellos10.yaml
eos.yaml eos_static_route DI module (#32587) 2017-11-07 11:13:03 +00:00
integration.cfg Fix ansible-test config management. 2017-10-04 12:52:36 -07:00
integration_config.yml
inventory Fix fact failures cause by ordering of collectors (#30777) 2017-09-28 10:36:22 -04:00
inventory.network
inventory.networking.template
inventory.remote.template
inventory.winrm.template
ios.yaml
iosxr.yaml
junos.yaml
network-all.yaml
network-integration.cfg Increase socket connect retry timeout for integration test (#30681) 2017-09-21 15:02:19 +05:30
nxos.yaml Integration Tests only: add static route, snmp_user, snapshot and hsrp it cases (#28933) 2017-10-26 11:27:55 -04:00
ops.yaml
platform_agnostic.yaml
target-prefixes.network
vyos.yaml Add vyos_vlan DI module (#32072) 2017-10-27 15:21:37 +05:30
windows-integration.cfg Fix ansible-test config management. 2017-10-04 12:52:36 -07:00