From 3c4daedbbab16e555a7cd17e689ce7db763bd7a3 Mon Sep 17 00:00:00 2001 From: Yikun Jiang Date: Thu, 8 Nov 2018 14:39:03 +0800 Subject: [PATCH] Add policy test for volume GET_ALL_POLICY Add policy test for volume GET_ALL_POLICY, and remove it from test policy file. This is one of the serious patches of policy-in-code test, see more information on [1] and [2]. [1] 530fb9319ce21b7ff99e55f095c04f13f0785842 [2] f207bac80924ffaf6d4c2a500c295d0e2e71966e Change-Id: Id391454fe1e9cc574ea2c996ffeed32e928af397 --- .../unit/api/v3/test_volume_protection.py | 32 +++++++++++++++++++ cinder/tests/unit/policy.json | 1 - 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/cinder/tests/unit/api/v3/test_volume_protection.py b/cinder/tests/unit/api/v3/test_volume_protection.py index c825431dd7f..42c90921804 100644 --- a/cinder/tests/unit/api/v3/test_volume_protection.py +++ b/cinder/tests/unit/api/v3/test_volume_protection.py @@ -118,6 +118,38 @@ class VolumeProtectionTests(test.TestCase): # expected? self.assertEqual(http_client.NOT_FOUND, response.status_int) + def test_admin_can_get_all_volumes_detail(self): + # Make sure administrators are authorized to list volumes + admin_context = self.admin_context + + volume = self._create_fake_volume(admin_context) + path = '/v3/%(project_id)s/volumes/detail' % { + 'project_id': admin_context.project_id, 'volume_id': volume.id + } + + response = self._get_request_response(admin_context, path, 'GET') + + self.assertEqual(http_client.OK, response.status_int) + res_vol = response.json_body['volumes'][0] + + self.assertEqual(volume.id, res_vol['id']) + + def test_owner_can_get_all_volumes_detail(self): + # Make sure owners are authorized to list volumes + user_context = self.user_context + + volume = self._create_fake_volume(user_context) + path = '/v3/%(project_id)s/volumes/detail' % { + 'project_id': user_context.project_id, 'volume_id': volume.id + } + + response = self._get_request_response(user_context, path, 'GET') + + self.assertEqual(http_client.OK, response.status_int) + res_vol = response.json_body['volumes'][0] + + self.assertEqual(volume.id, res_vol['id']) + @mock.patch.object(volume_api.API, 'get_volume') def test_admin_can_force_delete_volumes(self, mock_volume): # Make sure administrators are authorized to force delete volumes diff --git a/cinder/tests/unit/policy.json b/cinder/tests/unit/policy.json index 657aefe0bb3..464199e7ce8 100644 --- a/cinder/tests/unit/policy.json +++ b/cinder/tests/unit/policy.json @@ -4,7 +4,6 @@ "volume:create": "", "volume:create_from_image": "", - "volume:get_all": "", "volume:get_volume_metadata": "", "volume:get_volume_image_metadata": "", "volume:create_volume_metadata": "",