From 04c153cc0be36d4307e5da7269f2166c52f83df8 Mon Sep 17 00:00:00 2001 From: Ken Dreyer Date: Wed, 26 Apr 2017 19:15:13 -0600 Subject: [PATCH] create_node: avoid double-encoding Prior to this change, create_node() would double-encode certain url params: once when quote()'ing in _get_encoded_params(), and again in urlencode(). This would cause HTTP 400 errors when creating a node with a name that contains a url-encodable character, like "my+test+node". Reviewed-by: Alfredo Deza Change-Id: I237e2988e168af81e623d3f065753f2e9b617696 --- jenkins/__init__.py | 2 +- tests/test_node.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/jenkins/__init__.py b/jenkins/__init__.py index 26672b9..4105c89 100755 --- a/jenkins/__init__.py +++ b/jenkins/__init__.py @@ -287,7 +287,7 @@ class Jenkins(object): if variables: if format_spec == CREATE_NODE: - url_path = format_spec % urlencode(self._get_encoded_params(variables)) + url_path = format_spec % urlencode(variables) else: url_path = format_spec % self._get_encoded_params(variables) else: diff --git a/tests/test_node.py b/tests/test_node.py index 4d28241..a4e7064 100644 --- a/tests/test_node.py +++ b/tests/test_node.py @@ -253,6 +253,14 @@ class JenkinsCreateNodeTest(JenkinsNodesTestBase): actual) self._check_requests(jenkins_mock.call_args_list) + def test_build_url(self): + j = jenkins.Jenkins('https://test.noexist/') + # Note the use of a URL-encodable character "+" here. + variables = {'name': '10.0.0.1+test-node'} + result = j._build_url(jenkins.CREATE_NODE, variables=variables) + expected = 'https://test.noexist/computer/doCreateItem?name=10.0.0.1%2Btest-node' + self.assertEqual(result, expected) + @patch.object(jenkins.Jenkins, 'jenkins_open') def test_already_exists(self, jenkins_mock): jenkins_mock.side_effect = [