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
Martin Krizek 3980eb8c09
Prevent losing unsafe from lookups (#77609)
* Prevent losing unsafe from lookups

This patch fixes a bug which under certain conditions results in data
returned from lookups not being marked as unsafe.

Each time Templar.do_template is invoked a new AnsibleContext is
created and stored effectively at two places:
1) as an instance variable in templar_obj.cur_context
2) as a local variable called new_context in do_template method of Templar

Due to custom functionality in Ansible's Context that allows for nested
templating it is possible that during resolving variable's value
template/do_template method is called recursively again, again creating
a new context. At that point the problem manifests itself because as
mentioned in 1) above the context is overwriten on the templar object
which means that any subsequent calls to _lookup will use the new
context to mark it as unsafe which is now different to the local
new_context which is used for testing for unsafe property.

The solution to the problem appears to be to restore the original
context inside do_template and also to eliminate the local variable
new_context to prevent problems in the future.

It appears that we don't have a better way of storing the context other
than as some form of global variable and so this appears to be the
"best" solution possible at this point. Hopefully data tagging will be
the solution here.

For more examples see unit and integration tests included in this patch.

Fixes #77535
4 years ago
..
_vendor Remove obsolete units.compat.mock compat layer. (#77118) 4 years ago
ansible_test Remove Shippable CI provider from ansible-test. 5 years ago
cli Remove obsolete units.compat.mock compat layer. (#77118) 4 years ago
compat Remove obsolete units.compat.mock compat layer. (#77118) 4 years ago
config Yolo (#77554) 4 years ago
errors Remove obsolete units.compat.mock compat layer. (#77118) 4 years ago
executor PlayIterator - remove deprecated states (#77444) 4 years ago
galaxy ansible-galaxy collection - ensure dependencies are a dict (#77561) 4 years ago
inventory Clean up unit test boilerplate. 6 years ago
inventory_test_data/group_vars Merge branch 'v2_final' into devel_switch_v2 11 years ago
mock Remove obsolete units.compat.mock compat layer. (#77118) 4 years ago
module_utils arg_spec - Return aliases in validation result and update aliases (#77576) 4 years ago
modules unarchive: fix io_buffer_size option, remove ignore.txt entry (#77271) 4 years ago
parsing Remove collections compat from controller code. 4 years ago
playbook Allow for lazy evaluation of Jinja2 expressions (#56116) 4 years ago
plugins Better info sourcing (#77511) 4 years ago
regex Add toggle to control invalid character substitution in group names (#52748) 7 years ago
template Prevent losing unsafe from lookups (#77609) 4 years ago
utils Remove obsolete units.compat.mock compat layer. (#77118) 4 years ago
vars Remove obsolete units.compat.mock compat layer. (#77118) 4 years ago
__init__.py Add empty-init code-smell script. (#18406) 9 years ago
requirements.txt ansible-test - split controller/target testing (#75605) 4 years ago
test_constants.py Remove some constants.py deprecated items (#70466) 6 years ago
test_context.py Clean up unit test boilerplate. 6 years ago