diff --git a/jenkins_jobs/cache.py b/jenkins_jobs/cache.py index 017692952..62621b563 100644 --- a/jenkins_jobs/cache.py +++ b/jenkins_jobs/cache.py @@ -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): diff --git a/jenkins_jobs/cli/entry.py b/jenkins_jobs/cli/entry.py index e67ecb249..3aa24fe17 100644 --- a/jenkins_jobs/cli/entry.py +++ b/jenkins_jobs/cli/entry.py @@ -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( diff --git a/tests/cachestorage/test_cachestorage.py b/tests/cachestorage/test_cachestorage.py index 34803895c..13c7b87a7 100644 --- a/tests/cachestorage/test_cachestorage.py +++ b/tests/cachestorage/test_cachestorage.py @@ -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 diff --git a/tests/cmd/subcommands/test_test.py b/tests/cmd/subcommands/test_test.py index 1e0234a93..ee7d93a7b 100644 --- a/tests/cmd/subcommands/test_test.py +++ b/tests/cmd/subcommands/test_test.py @@ -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) diff --git a/tests/modules/test_helpers.py b/tests/modules/test_helpers.py index f0cebb41d..6fc504960 100644 --- a/tests/modules/test_helpers.py +++ b/tests/modules/test_helpers.py @@ -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)