diff --git a/manila/api/v1/security_service.py b/manila/api/v1/security_service.py index dca6add24a..64edcbe538 100644 --- a/manila/api/v1/security_service.py +++ b/manila/api/v1/security_service.py @@ -28,6 +28,7 @@ from manila import db from manila import exception from manila.i18n import _ from manila import policy +from manila import utils RESOURCE_NAME = 'security_service' @@ -106,7 +107,7 @@ class SecurityServiceController(wsgi.Controller): security_services = share_nw['security_services'] del search_opts['share_network_id'] else: - if 'all_tenants' in search_opts and context.is_admin: + if context.is_admin and utils.is_all_tenants(search_opts): policy.check_policy(context, RESOURCE_NAME, 'get_all_security_services') security_services = db.security_service_get_all(context) diff --git a/manila/tests/api/v1/test_security_service.py b/manila/tests/api/v1/test_security_service.py index 56125b45ef..5dce4b8745 100644 --- a/manila/tests/api/v1/test_security_service.py +++ b/manila/tests/api/v1/test_security_service.py @@ -313,6 +313,25 @@ class ShareApiTest(test.TestCase): fake_context, fake_context.project_id ) + @mock.patch.object(db, 'security_service_get_all', mock.Mock()) + def test_security_services_list_all_tenants_with_invalid_value(self): + req = fakes.HTTPRequest.blank( + '/security-services?all_tenants=nerd', + use_admin_context=True) + self.assertRaises(exception.InvalidInput, self.controller.index, req) + + @mock.patch.object(db, 'security_service_get_all_by_project', mock.Mock()) + def test_security_services_list_all_tenants_with_value_zero(self): + db.security_service_get_all_by_project.return_value = [] + req = fakes.HTTPRequest.blank( + '/security-services?all_tenants=0', + use_admin_context=True) + res_dict = self.controller.index(req) + self.assertEqual({'security_services': []}, res_dict) + db.security_service_get_all_by_project.assert_called_once_with( + req.environ['manila.context'], + req.environ['manila.context'].project_id) + @mock.patch.object(db, 'security_service_get_all_by_project', mock.Mock()) def test_security_services_list_admin_context_invalid_opts(self): db.security_service_get_all_by_project.return_value = [ diff --git a/releasenotes/notes/bug-1777551-security-services-api-all-tenants-fix-e820ec370d7df473.yaml b/releasenotes/notes/bug-1777551-security-services-api-all-tenants-fix-e820ec370d7df473.yaml new file mode 100644 index 0000000000..c14d5b7e45 --- /dev/null +++ b/releasenotes/notes/bug-1777551-security-services-api-all-tenants-fix-e820ec370d7df473.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + The ``all_tenants`` query parameter in the security services API (GET + /v2/{project_id}/security-services) has been fixed to accept 'f', + 'false', 'off', 'n', 'no', or '0'. Setting the flag to any of these values + will retrieve security services only from the requester's project + namespace.