Skip to content

Commit

Permalink
Don't encode path separators
Browse files Browse the repository at this point in the history
Encoding the path separators results in urls refused by by apache
with 404 unless AllowEncodedSlashes is turned on, which is not
the default.

The existing encoding of path separators seems unnecessary.

Change-Id: I3b77aafc6104119503363e5db36b0379964daba5
  • Loading branch information
rabi committed May 9, 2017
1 parent 31160e2 commit a625d3b
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 48 deletions.
10 changes: 5 additions & 5 deletions heatclient/tests/unit/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_list_event(self):
manager.list(stack_id, resource_name)
# Make sure url is correct.
manager._list.assert_called_once_with(
'/stacks/teststack%2Fabcd1234/'
'/stacks/teststack/abcd1234/'
'resources/testresource/events',
"events")
mock_re.assert_called_once_with(stack_id)
Expand All @@ -50,7 +50,7 @@ def test_list_event_with_unicode_resource_name(self):
manager.list(stack_id, resource_name)
# Make sure url is correct.
manager._list.assert_called_once_with(
'/stacks/teststack%2Fabcd1234/'
'/stacks/teststack/abcd1234/'
'resources/%E5%B7%A5%E4%BD%9C/'
'events', "events")
mock_re.assert_called_once_with(stack_id)
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_list_event_with_kwargs(self):
url, param = args[0]
self.assertEqual("events", param)
base_url, query_params = utils.parse_query_url(url)
expected_base_url = ('/stacks/teststack%2Fabcd1234/'
expected_base_url = ('/stacks/teststack/abcd1234/'
'resources/testresource/events')
self.assertEqual(expected_base_url, base_url)
expected_query_dict = {'marker': ['6d6935f4-0ae5'],
Expand All @@ -110,7 +110,7 @@ class FakeAPI(object):

def json_request(self, *args, **kwargs):
expect = ('GET',
'/stacks/teststack%2Fabcd1234/resources'
'/stacks/teststack/abcd1234/resources'
'/testresource/events/1')
assert args == expect
return {}, {'event': []}
Expand All @@ -137,7 +137,7 @@ class FakeAPI(object):

def json_request(self, *args, **kwargs):
expect = ('GET',
'/stacks/teststack%2Fabcd1234/resources'
'/stacks/teststack/abcd1234/resources'
'/%E5%B7%A5%E4%BD%9C/events/1')
assert args == expect
return {}, {'event': []}
Expand Down
12 changes: 6 additions & 6 deletions heatclient/tests/unit/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_get(self):
fields = {'stack_id': 'teststack',
'resource_name': 'testresource'}
expect = ('GET',
'/stacks/teststack%2Fabcd1234/resources'
'/stacks/teststack/abcd1234/resources'
'/testresource')
key = 'resource'

Expand All @@ -86,7 +86,7 @@ def test_get_with_attr(self):
'resource_name': 'testresource',
'with_attr': ['attr_a', 'attr_b']}
expect = ('GET',
'/stacks/teststack%2Fabcd1234/resources'
'/stacks/teststack/abcd1234/resources'
'/testresource?with_attr=attr_a&with_attr=attr_b')
key = 'resource'

Expand All @@ -98,7 +98,7 @@ def test_get_with_unicode_resource_name(self):
fields = {'stack_id': 'teststack',
'resource_name': u'\u5de5\u4f5c'}
expect = ('GET',
'/stacks/teststack%2Fabcd1234/resources'
'/stacks/teststack/abcd1234/resources'
'/%E5%B7%A5%E4%BD%9C')
key = 'resource'

Expand Down Expand Up @@ -154,7 +154,7 @@ def test_metadata(self):
fields = {'stack_id': 'teststack',
'resource_name': 'testresource'}
expect = ('GET',
'/stacks/teststack%2Fabcd1234/resources'
'/stacks/teststack/abcd1234/resources'
'/testresource/metadata')
key = 'metadata'

Expand Down Expand Up @@ -192,7 +192,7 @@ def test_signal(self):
'resource_name': 'testresource',
'data': 'Some content'}
expect = ('POST',
'/stacks/teststack%2Fabcd1234/resources'
'/stacks/teststack/abcd1234/resources'
'/testresource/signal')
key = 'signal'

Expand All @@ -206,7 +206,7 @@ def test_mark_unhealthy(self):
'mark_unhealthy': 'True',
'resource_status_reason': 'Anything'}
expect = ('PATCH',
'/stacks/teststack%2Fabcd1234/resources'
'/stacks/teststack/abcd1234/resources'
'/testresource')
key = 'mark_unhealthy'

Expand Down
40 changes: 20 additions & 20 deletions heatclient/tests/unit/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def test_event_list(self):
rsrc_eventid2=eventid2
)

self.requests.get('http://heat.example.com/stacks/myStack%2F60f83b5e/'
self.requests.get('http://heat.example.com/stacks/myStack/60f83b5e/'
'resources/myDeployment/events',
headers={'Content-Type': 'application/json'},
json=resp_dict)
Expand Down Expand Up @@ -2622,9 +2622,9 @@ def test_event_list(self):
resource_name = 'testresource/1'
self.mock_request_get(
'/stacks/%s/resources/%s/events?sort_dir=asc' % (
parse.quote(stack_id, ''),
parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(
resource_name), '')),
resource_name))),
resp_dict)

self.m.ReplayAll()
Expand Down Expand Up @@ -2698,10 +2698,10 @@ def test_event_show(self):
self.mock_request_get(
'/stacks/%s/resources/%s/events/%s' %
(
parse.quote(stack_id, ''),
parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(
resource_name), ''),
parse.quote(self.event_id_one, '')
resource_name)),
parse.quote(self.event_id_one)
),
resp_dict)

Expand Down Expand Up @@ -3281,9 +3281,9 @@ def test_resource_show_with_attrs(self):
self.mock_request_get(
'/stacks/%s/resources/%s?with_attr=attr_a&with_attr=attr_b' %
(
parse.quote(stack_id, ''),
parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(
resource_name), '')
resource_name))
), resp_dict)

self.m.ReplayAll()
Expand Down Expand Up @@ -3323,9 +3323,9 @@ def test_resource_signal(self):
self.mock_request_post(
'/stacks/%s/resources/%s/signal' %
(
parse.quote(stack_id, ''),
parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(
resource_name), '')
resource_name))
),
'',
data={'message': 'Content'}
Expand All @@ -3345,9 +3345,9 @@ def test_resource_signal_no_data(self):
self.mock_request_post(
'/stacks/%s/resources/%s/signal' %
(
parse.quote(stack_id, ''),
parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(
resource_name), '')
resource_name))
),
'',
data=None
Expand Down Expand Up @@ -3405,9 +3405,9 @@ def test_resource_signal_data_file(self):
self.mock_request_post(
'/stacks/%s/resources/%s/signal' %
(
parse.quote(stack_id, ''),
parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(
resource_name), '')
resource_name))
),
'',
data={'message': 'Content'}
Expand All @@ -3430,9 +3430,9 @@ def test_resource_mark_unhealthy(self):
self.mock_request_patch(
'/stacks/%s/resources/%s' %
(
parse.quote(stack_id, ''),
parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(
resource_name), '')
resource_name))
),
'',
req_headers=False,
Expand All @@ -3453,9 +3453,9 @@ def test_resource_mark_unhealthy_reset(self):
self.mock_request_patch(
'/stacks/%s/resources/%s' %
(
parse.quote(stack_id, ''),
parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(
resource_name), '')
resource_name))
),
'',
req_headers=False,
Expand All @@ -3476,9 +3476,9 @@ def test_resource_mark_unhealthy_no_reason(self):
self.mock_request_patch(
'/stacks/%s/resources/%s' %
(
parse.quote(stack_id, ''),
parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(
resource_name), '')
resource_name))
),
'',
req_headers=False,
Expand Down
8 changes: 4 additions & 4 deletions heatclient/v1/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def list(self, stack_id, resource_name=None, **kwargs):
else:
stack_id = self._resolve_stack_id(stack_id)
url = '/stacks/%s/resources/%s/events' % (
parse.quote(stack_id, ''),
parse.quote(encodeutils.safe_encode(resource_name), ''))
parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(resource_name)))
if params:
# convert to a sorted dict for python3 predictible order
params = collections.OrderedDict(sorted(params.items()))
Expand All @@ -81,8 +81,8 @@ def get(self, stack_id, resource_name, event_id):
"""
stack_id = self._resolve_stack_id(stack_id)
url_str = '/stacks/%s/resources/%s/events/%s' % (
parse.quote(stack_id, ''),
parse.quote(encodeutils.safe_encode(resource_name), ''),
parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(resource_name)),
parse.quote(event_id, ''))
resp = self.client.get(url_str)
body = utils.get_response_body(resp)
Expand Down
4 changes: 2 additions & 2 deletions heatclient/v1/resource_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get(self, resource_type, with_description=False):
"""
url_str = '/%s/%s' % (
self.KEY,
parse.quote(encodeutils.safe_encode(resource_type), ''))
parse.quote(encodeutils.safe_encode(resource_type)))
resp = self.client.get(url_str,
params={'with_description': with_description})
body = utils.get_response_body(resp)
Expand All @@ -77,7 +77,7 @@ def get(self, resource_type, with_description=False):
def generate_template(self, resource_type, template_type='cfn'):
url_str = '/%s/%s/template' % (
self.KEY,
parse.quote(encodeutils.safe_encode(resource_type), ''))
parse.quote(encodeutils.safe_encode(resource_type)))
if template_type:
url_str += '?%s' % parse.urlencode(
{'template_type': template_type}, True)
Expand Down
18 changes: 9 additions & 9 deletions heatclient/v1/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def get(self, stack_id, resource_name, with_attr=None):
"""
stack_id = self._resolve_stack_id(stack_id)
url_str = '/stacks/%s/resources/%s' % (
parse.quote(stack_id, ''),
parse.quote(encodeutils.safe_encode(resource_name), ''))
parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(resource_name)))
if with_attr:
params = {'with_attr': with_attr}
url_str += '?%s' % parse.urlencode(params, True)
Expand All @@ -97,8 +97,8 @@ def metadata(self, stack_id, resource_name):
"""
stack_id = self._resolve_stack_id(stack_id)
url_str = '/stacks/%s/resources/%s/metadata' % (
parse.quote(stack_id, ''),
parse.quote(encodeutils.safe_encode(resource_name), ''))
parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(resource_name)))
resp = self.client.get(url_str)
body = utils.get_response_body(resp)
return body.get('metadata')
Expand All @@ -111,8 +111,8 @@ def signal(self, stack_id, resource_name, data=None):
"""
stack_id = self._resolve_stack_id(stack_id)
url_str = '/stacks/%s/resources/%s/signal' % (
parse.quote(stack_id, ''),
parse.quote(encodeutils.safe_encode(resource_name), ''))
parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(resource_name)))
resp = self.client.post(url_str, data=data)
body = utils.get_response_body(resp)
return body
Expand All @@ -128,8 +128,8 @@ def mark_unhealthy(self, stack_id, resource_name,
"""
stack_id = self._resolve_stack_id(stack_id)
url_str = '/stacks/%s/resources/%s' % (
parse.quote(stack_id, ''),
parse.quote(encodeutils.safe_encode(resource_name), ''))
parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(resource_name)))
resp = self.client.patch(
url_str,
data={"mark_unhealthy": mark_unhealthy,
Expand All @@ -142,7 +142,7 @@ def generate_template(self, resource_name):
"""Deprecated in favor of generate_template in ResourceTypeManager."""

url_str = '/resource_types/%s/template' % (
parse.quote(encodeutils.safe_encode(resource_name), ''))
parse.quote(encodeutils.safe_encode(resource_name)))
resp = self.client.get(url_str)
body = utils.get_response_body(resp)
return body
2 changes: 1 addition & 1 deletion heatclient/v1/software_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def metadata(self, server_id):
:rtype: list of :class:`SoftwareDeployment`
"""
url = '/software_deployments/metadata/%s' % parse.quote(
server_id, '')
server_id)
resp = self.client.get(url)
body = utils.get_response_body(resp)
return body.get('metadata')
Expand Down
2 changes: 1 addition & 1 deletion heatclient/v1/template_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get(self, template_version, **kwargs):
:param template_version: template version to get the functions for
"""
url_str = '/template_versions/%s/functions' % (
parse.quote(encodeutils.safe_encode(template_version), ''))
parse.quote(encodeutils.safe_encode(template_version)))

params = {}
if 'with_condition_func' in kwargs:
Expand Down

0 comments on commit a625d3b

Please sign in to comment.