Don't put project_id in path if it wasn't there

This fixes the case that when a request looking like
http://example.com/resource/volume
and containing a token comes to the proxy, we translate it to
http://cinder.local/volume/<project_id>

This happens because we populate the project_id information of
a request either from the url, or from the token.

Change-Id: Ie83fec4910eff750ba15f5485428c23ec3505e3b
This commit is contained in:
Kristi Nikolla 2018-06-07 00:27:15 -04:00
parent 955f28d397
commit 61a8444c27
2 changed files with 18 additions and 1 deletions

View File

@ -84,6 +84,7 @@ class RequestDetails(object):
self.service = get_service(local_path)
self.version = utils.safe_pop(local_path)
self.project_id = utils.pop_if_uuid(local_path)
self.project_in_path = True if self.project_id else False
self.action = local_path[:] # NOTE(knikolla): This includes
self.resource_type = utils.safe_pop(local_path) # this
self.resource_id = utils.pop_if_uuid(local_path) # and this
@ -194,7 +195,7 @@ class RequestHandler(object):
self.details.service,
self.details.version,
self.details.action,
project_id=project_id
project_id=project_id if self.details.project_in_path else None
)
request_kwargs = {

View File

@ -392,6 +392,22 @@ class TestVolumesV2(base.BaseTest):
self.assertEqual(response.get_data(as_text=True),
fake_response)
def test_unversioned_call_no_action_no_aggregation_token(self):
self.config_fixture.load_raw_values(aggregation=False)
fake_response = uuid.uuid4().hex
self.requests_fixture.get(
self._construct_url(sp='default'),
text=fake_response,
status_code=200,
request_headers=self.auth.get_headers(),
headers={'CONTENT-TYPE': 'application/json'})
response = self.app.get('volume', headers=self.auth.get_headers())
self.assertEqual(response.status_code, 200)
self.assertEqual(response.get_data(as_text=True),
fake_response)
def test_volume_versioned_calls_no_action(self):
response = self.app.get(
'/volume/v2',