mirror of
https://github.com/ansible/awx.git
synced 2026-03-23 20:05:03 -02:30
add protection for job-compatible vars
This commit is contained in:
@@ -44,6 +44,16 @@ def test_parse_yaml_or_json(input_, output):
|
|||||||
assert common.parse_yaml_or_json(input_) == output
|
assert common.parse_yaml_or_json(input_) == output
|
||||||
|
|
||||||
|
|
||||||
|
def test_recursive_vars_not_allowed():
|
||||||
|
rdict = {}
|
||||||
|
rdict['a'] = rdict
|
||||||
|
# YAML dumper will use a tag to give recursive data
|
||||||
|
data = yaml.dump(rdict, default_flow_style=False)
|
||||||
|
with pytest.raises(ParseError) as exc:
|
||||||
|
common.parse_yaml_or_json(data, silent_failure=False)
|
||||||
|
assert 'Circular reference detected' in str(exc)
|
||||||
|
|
||||||
|
|
||||||
class TestParserExceptions:
|
class TestParserExceptions:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -630,8 +630,16 @@ def parse_yaml_or_json(vars_str, silent_failure=True):
|
|||||||
vars_dict = yaml.safe_load(vars_str)
|
vars_dict = yaml.safe_load(vars_str)
|
||||||
# Can be None if '---'
|
# Can be None if '---'
|
||||||
if vars_dict is None:
|
if vars_dict is None:
|
||||||
return {}
|
vars_dict = {}
|
||||||
validate_vars_type(vars_dict)
|
validate_vars_type(vars_dict)
|
||||||
|
if not silent_failure:
|
||||||
|
# is valid YAML, check that it is compatible with JSON
|
||||||
|
try:
|
||||||
|
json.dumps(vars_dict)
|
||||||
|
except (ValueError, TypeError, AssertionError) as json_err2:
|
||||||
|
raise ParseError(_(
|
||||||
|
'Variables not compatible with JSON standard (error: {json_error})').format(
|
||||||
|
json_error=str(json_err2)))
|
||||||
except (yaml.YAMLError, TypeError, AttributeError, AssertionError) as yaml_err:
|
except (yaml.YAMLError, TypeError, AttributeError, AssertionError) as yaml_err:
|
||||||
if silent_failure:
|
if silent_failure:
|
||||||
return {}
|
return {}
|
||||||
|
|||||||
Reference in New Issue
Block a user