Browse Source

Merge "Check all_tenants value in share_networks api"

Zuul 1 month ago
parent
commit
15878d96f3

+ 2
- 1
manila/api/v2/share_networks.py View File

@@ -33,6 +33,7 @@ from manila.i18n import _
33 33
 from manila import policy
34 34
 from manila import quota
35 35
 from manila.share import rpcapi as share_rpcapi
36
+from manila import utils
36 37
 
37 38
 RESOURCE_NAME = 'share_network'
38 39
 RESOURCES_NAME = 'share_networks'
@@ -119,7 +120,7 @@ class ShareNetworkController(wsgi.Controller):
119 120
         elif context.is_admin and 'project_id' in search_opts:
120 121
             networks = db_api.share_network_get_all_by_project(
121 122
                 context, search_opts['project_id'])
122
-        elif context.is_admin and 'all_tenants' in search_opts:
123
+        elif context.is_admin and utils.is_all_tenants(search_opts):
123 124
             networks = db_api.share_network_get_all(context)
124 125
         else:
125 126
             networks = db_api.share_network_get_all_by_project(

+ 27
- 0
manila/tests/api/v2/test_share_networks.py View File

@@ -408,6 +408,33 @@ class ShareNetworkAPITest(test.TestCase):
408 408
             result[share_networks.RESOURCES_NAME][0],
409 409
             fake_share_network_shortened)
410 410
 
411
+    @mock.patch.object(db_api, 'share_network_get_all', mock.Mock())
412
+    def test_index_all_tenants_with_invaild_value(self):
413
+        req = fakes.HTTPRequest.blank(
414
+            '/share_networks?all_tenants=wonk',
415
+            use_admin_context=True)
416
+
417
+        self.assertRaises(exception.InvalidInput, self.controller.index, req)
418
+
419
+    @mock.patch.object(db_api, 'share_network_get_all_by_project', mock.Mock())
420
+    @mock.patch.object(db_api, 'share_network_get_all', mock.Mock())
421
+    def test_index_all_tenants_with_value_zero(self):
422
+        db_api.share_network_get_all_by_project.return_value = [
423
+            fake_share_network]
424
+        req = fakes.HTTPRequest.blank(
425
+            '/share_networks?all_tenants=0',
426
+            use_admin_context=True)
427
+
428
+        result = self.controller.index(req)
429
+
430
+        self.assertEqual(1, len(result[share_networks.RESOURCES_NAME]))
431
+        self._check_share_network_view_shortened(
432
+            result[share_networks.RESOURCES_NAME][0],
433
+            fake_share_network_shortened)
434
+        db_api.share_network_get_all_by_project.assert_called_once_with(
435
+            req.environ['manila.context'], self.context.project_id)
436
+        db_api.share_network_get_all.assert_not_called()
437
+
411 438
     @mock.patch.object(db_api, 'share_network_get_all_by_project', mock.Mock())
412 439
     def test_index_filter_by_project_id_non_admin_context(self):
413 440
         req = fakes.HTTPRequest.blank(

+ 8
- 0
releasenotes/notes/bug-1777551-security-networks-api-all-tenants-fix-a061274afe15180d.yaml View File

@@ -0,0 +1,8 @@
1
+---
2
+fixes:
3
+  - |
4
+    The ``all_tenants`` query parameter in the share networks API (GET
5
+    /v2/{project_id}/share-networks) has been fixed to accept 'f',
6
+    'false', 'off', 'n', 'no', or '0'. Setting the flag to any of these values
7
+    will retrieve security services only from the requester's project
8
+    namespace.

Loading…
Cancel
Save