Fix the yaml load warning.
In the new version of PyYAML the API changed to be more explicit. Now the default value for the Loader is None, see: https://github.com/yaml/pyyaml/blob/5.1/lib3/yaml/__init__.py#L103 The load is unsafe. It's better to use safe_load function. Change-Id: Ia1cd16f2ff970ca220a266c99b6554dd4254ebd9
This commit is contained in:
parent
67dc0087a7
commit
0b4ed38ca6
@ -59,7 +59,7 @@ class JobCache(object):
|
||||
self.data = {}
|
||||
else:
|
||||
with io.open(self.cachefilename, "r", encoding="utf-8") as yfile:
|
||||
self.data = yaml.load(yfile)
|
||||
self.data = yaml.safe_load(yfile)
|
||||
logger.debug("Using cache: '{0}'".format(self.cachefilename))
|
||||
|
||||
def _lock(self):
|
||||
|
@ -101,7 +101,7 @@ class JenkinsJobs(object):
|
||||
with io.open(
|
||||
self.options.plugins_info_path, "r", encoding="utf-8"
|
||||
) as yaml_file:
|
||||
plugins_info = yaml.load(yaml_file)
|
||||
plugins_info = yaml.safe_load(yaml_file)
|
||||
if not isinstance(plugins_info, list):
|
||||
self.parser.error(
|
||||
"{0} must contain a Yaml list!".format(
|
||||
|
@ -40,6 +40,6 @@ class TestCaseJobCache(base.BaseTestCase):
|
||||
"""
|
||||
test_file = os.path.abspath(__file__)
|
||||
with mock.patch("os.path.join", return_value=test_file):
|
||||
with mock.patch("yaml.load"):
|
||||
with mock.patch("yaml.safe_load"):
|
||||
with mock.patch("jenkins_jobs.builder.JobCache._lock"):
|
||||
jenkins_jobs.builder.JobCache("dummy").data = None
|
||||
|
@ -213,7 +213,7 @@ class TestTests(CmdTestsBase):
|
||||
self.execute_jenkins_jobs_with_args(args)
|
||||
|
||||
with io.open(plugins_info_stub_yaml_file, "r", encoding="utf-8") as yaml_file:
|
||||
plugins_info_list = yaml.load(yaml_file)
|
||||
plugins_info_list = yaml.safe_load(yaml_file)
|
||||
|
||||
registry_mock.assert_called_with(mock.ANY, plugins_info_list)
|
||||
|
||||
|
@ -31,7 +31,7 @@ class TestCaseTestHelpers(base.BaseTestCase):
|
||||
|
||||
# Test default values
|
||||
default_root = XML.Element("testdefault")
|
||||
default_data = yaml.load("string: hello")
|
||||
default_data = yaml.safe_load("string: hello")
|
||||
default_mappings = [("default-string", "defaultString", "default")]
|
||||
|
||||
convert_mapping_to_xml(
|
||||
@ -42,7 +42,7 @@ class TestCaseTestHelpers(base.BaseTestCase):
|
||||
|
||||
# Test user input
|
||||
user_input_root = XML.Element("testUserInput")
|
||||
user_input_data = yaml.load("user-input-string: hello")
|
||||
user_input_data = yaml.safe_load("user-input-string: hello")
|
||||
user_input_mappings = [("user-input-string", "userInputString", "user-input")]
|
||||
|
||||
convert_mapping_to_xml(
|
||||
@ -53,7 +53,7 @@ class TestCaseTestHelpers(base.BaseTestCase):
|
||||
|
||||
# Test missing required input
|
||||
required_root = XML.Element("testrequired")
|
||||
required_data = yaml.load("string: hello")
|
||||
required_data = yaml.safe_load("string: hello")
|
||||
required_mappings = [("required-string", "requiredString", None)]
|
||||
|
||||
self.assertRaises(
|
||||
@ -67,7 +67,7 @@ class TestCaseTestHelpers(base.BaseTestCase):
|
||||
|
||||
# Test invalid user input for list
|
||||
user_input_root = XML.Element("testUserInput")
|
||||
user_input_data = yaml.load("user-input-string: bye")
|
||||
user_input_data = yaml.safe_load("user-input-string: bye")
|
||||
valid_inputs = ["hello"]
|
||||
user_input_mappings = [
|
||||
("user-input-string", "userInputString", "user-input", valid_inputs)
|
||||
@ -83,7 +83,7 @@ class TestCaseTestHelpers(base.BaseTestCase):
|
||||
|
||||
# Test invalid user input for dict
|
||||
user_input_root = XML.Element("testUserInput")
|
||||
user_input_data = yaml.load("user-input-string: later")
|
||||
user_input_data = yaml.safe_load("user-input-string: later")
|
||||
valid_inputs = {"hello": "world"}
|
||||
user_input_mappings = [
|
||||
("user-input-string", "userInputString", "user-input", valid_inputs)
|
||||
@ -99,7 +99,7 @@ class TestCaseTestHelpers(base.BaseTestCase):
|
||||
|
||||
# Test invalid key for dict
|
||||
user_input_root = XML.Element("testUserInput")
|
||||
user_input_data = yaml.load("user-input-string: world")
|
||||
user_input_data = yaml.safe_load("user-input-string: world")
|
||||
valid_inputs = {"hello": "world"}
|
||||
user_input_mappings = [
|
||||
("user-input-string", "userInputString", "user-input", valid_inputs)
|
||||
|
Loading…
Reference in New Issue
Block a user