Sanitize url in get_info() function
Change-Id: I540f6d636e277d0ad230f844d2db6220edfb672f Closes-Bug: #1698815
This commit is contained in:
parent
828eb92c48
commit
16007e0185
@ -544,6 +544,7 @@ class Jenkins(object):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
url = '/'.join((item, INFO)).lstrip('/')
|
url = '/'.join((item, INFO)).lstrip('/')
|
||||||
|
url = quote(url)
|
||||||
if query:
|
if query:
|
||||||
url += query
|
url += query
|
||||||
try:
|
try:
|
||||||
|
@ -39,6 +39,16 @@ class JenkinsGetJobsTestBase(JenkinsJobsTestBase):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
jobs_in_unsafe_name_folders = copy.deepcopy(jobs_in_folder)
|
||||||
|
jobs_in_unsafe_name_folders[1].insert(
|
||||||
|
0, {'name': 'my spaced folder', 'jobs': None})
|
||||||
|
jobs_in_unsafe_name_folders.append(
|
||||||
|
# my_folder1/my\ spaced\ folder jobs
|
||||||
|
[
|
||||||
|
{'name': 'my job 5'}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def build_jobs_list_responses(jobs_list, server_url):
|
def build_jobs_list_responses(jobs_list, server_url):
|
||||||
responses = []
|
responses = []
|
||||||
|
@ -59,3 +59,20 @@ class JenkinsGetAllJobsTest(JenkinsGetJobsTestBase):
|
|||||||
self.assertEqual(len(expected_fullnames), len(jobs_info))
|
self.assertEqual(len(expected_fullnames), len(jobs_info))
|
||||||
got_fullnames = [job[u"fullname"] for job in jobs_info]
|
got_fullnames = [job[u"fullname"] for job in jobs_info]
|
||||||
self.assertEqual(expected_fullnames, got_fullnames)
|
self.assertEqual(expected_fullnames, got_fullnames)
|
||||||
|
|
||||||
|
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||||
|
def test_unsafe_chars(self, jenkins_mock):
|
||||||
|
response = build_jobs_list_responses(
|
||||||
|
self.jobs_in_unsafe_name_folders, 'http://example.com/')
|
||||||
|
jenkins_mock.side_effect = iter(response)
|
||||||
|
|
||||||
|
jobs_info = self.j.get_all_jobs()
|
||||||
|
|
||||||
|
expected_fullnames = [
|
||||||
|
u"my_job1", u"my_job2",
|
||||||
|
u"my_folder1/my_job3", u"my_folder1/my_job4",
|
||||||
|
u"my_folder1/my spaced folder/my job 5"
|
||||||
|
]
|
||||||
|
self.assertEqual(len(expected_fullnames), len(jobs_info))
|
||||||
|
got_fullnames = [job[u"fullname"] for job in jobs_info]
|
||||||
|
self.assertEqual(expected_fullnames, got_fullnames)
|
||||||
|
Loading…
Reference in New Issue
Block a user