From 9bf7f8150937e87d8165fe4ac9c14462f1aacfda Mon Sep 17 00:00:00 2001 From: Jeff Schroeder Date: Wed, 7 Aug 2019 21:05:03 -0500 Subject: [PATCH] Fix reconfig_credential() to send the xml data Previously, reconfig_credential() passed empty `data` with `Content-Length: 0` to the credentials configuration rather than the credentials data. This patch fixes the issue by passing the config_xml data to the configuration API to properly update the credential. Change-Id: Idef50f5a31d55991698b6217f55f15a9308b8526 --- jenkins/__init__.py | 9 +++++++-- tests/test_credential.py | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/jenkins/__init__.py b/jenkins/__init__.py index 6236f4c..d9387d2 100755 --- a/jenkins/__init__.py +++ b/jenkins/__init__.py @@ -2136,9 +2136,14 @@ class Jenkins(object): folder_url, short_name = self._get_job_folder(folder_name) name = self._get_tag_text('id', config_xml) self.assert_credential_exists(name, folder_name, domain_name) + + reconfig_url = self._build_url(CONFIG_CREDENTIAL, locals()) + self.jenkins_open(requests.Request( - 'POST', self._build_url(CONFIG_CREDENTIAL, locals()) - )) + 'POST', reconfig_url, + data=config_xml.encode('utf-8'), + headers=DEFAULT_HEADERS + )) def list_credentials(self, folder_name, domain_name='_'): '''List credentials in domain of folder diff --git a/tests/test_credential.py b/tests/test_credential.py index 8e4e5f7..8e7418b 100644 --- a/tests/test_credential.py +++ b/tests/test_credential.py @@ -332,6 +332,10 @@ class JenkinsReconfigCredentialTest(JenkinsCredentialTestBase): jenkins_mock.call_args_list[2][0][0].url, self.make_url('job/Test%20Folder/credentials/store/folder/domain/' '_/credential/Test%20Credential/config.xml')) + self.assertEqual( + jenkins_mock.call_args_list[2][0][0].data, + self.config_xml.encode('utf-8')) + self._check_requests(jenkins_mock.call_args_list)