Browse Source

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
Kristi Nikolla 10 months ago
parent
commit
61a8444c27
2 changed files with 18 additions and 1 deletions
  1. 2
    1
      mixmatch/proxy.py
  2. 16
    0
      mixmatch/tests/unit/test_volumes.py

+ 2
- 1
mixmatch/proxy.py View File

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

+ 16
- 0
mixmatch/tests/unit/test_volumes.py View File

@@ -392,6 +392,22 @@ class TestVolumesV2(base.BaseTest):
392 392
         self.assertEqual(response.get_data(as_text=True),
393 393
                          fake_response)
394 394
 
395
+    def test_unversioned_call_no_action_no_aggregation_token(self):
396
+        self.config_fixture.load_raw_values(aggregation=False)
397
+        fake_response = uuid.uuid4().hex
398
+
399
+        self.requests_fixture.get(
400
+            self._construct_url(sp='default'),
401
+            text=fake_response,
402
+            status_code=200,
403
+            request_headers=self.auth.get_headers(),
404
+            headers={'CONTENT-TYPE': 'application/json'})
405
+
406
+        response = self.app.get('volume', headers=self.auth.get_headers())
407
+        self.assertEqual(response.status_code, 200)
408
+        self.assertEqual(response.get_data(as_text=True),
409
+                         fake_response)
410
+
395 411
     def test_volume_versioned_calls_no_action(self):
396 412
         response = self.app.get(
397 413
             '/volume/v2',

Loading…
Cancel
Save