From 26c700da60565e0a3d0f8c7aa25c9208bdce00ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Piwowarski?= Date: Thu, 18 May 2023 10:39:15 +0200 Subject: [PATCH] Fix test_secret_stores tests There were five minor issues with the test_secret_stores tests: 1) There is a typo in some test cases. They are calling unset_peferred_secret_store instead of unset_peferred_secret_store 2) Set and unset preferred secret stores API calls in the SecretStoresClient expect 200 response status code when in fact they should expect 204 instead [1]. 3) test_get_preferred_secret_store test expects to get preferred secret store when in fact none is set for the project. 4) skip_checks() function did not call super's skip_checks() 5) test_set_unset_preferred_secret_store test expects to get preferred secret store for a project when there is no preferred secret store set for it. [1] https://docs.openstack.org/barbican/rocky/api/reference/store_backends.html#post-v1-secret-stores-secret-store-id-preferred Change-Id: Ic211ea87006662c5a24aef3d1b78a5aa85b5e35b --- .../key_manager/json/secret_stores_client.py | 8 +++---- .../tests/rbac/v1/test_secret_stores.py | 22 ++++++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/barbican_tempest_plugin/services/key_manager/json/secret_stores_client.py b/barbican_tempest_plugin/services/key_manager/json/secret_stores_client.py index cb5fd5e..6d3094c 100644 --- a/barbican_tempest_plugin/services/key_manager/json/secret_stores_client.py +++ b/barbican_tempest_plugin/services/key_manager/json/secret_stores_client.py @@ -49,12 +49,10 @@ class SecretStoresClient(base.BarbicanTempestClient): def set_preferred_secret_store(self, secret_store_id): uri = '/v1/secret-stores/{}/preferred'.format(secret_store_id) - resp, body = self.post(uri) - self.expected_success(200, resp.status) - return json.loads(body.decode('UTF-8')) + resp, body = self.post(uri, None) + self.expected_success(204, resp.status) def unset_preferred_secret_store(self, secret_store_id): uri = '/v1/secret-stores/{}/preferred'.format(secret_store_id) resp, body = self.delete(uri) - self.expected_success(200, resp.status) - return json.loads(body.decode('UTF-8')) + self.expected_success(204, resp.status) diff --git a/barbican_tempest_plugin/tests/rbac/v1/test_secret_stores.py b/barbican_tempest_plugin/tests/rbac/v1/test_secret_stores.py index 6f0a00d..2e637d8 100644 --- a/barbican_tempest_plugin/tests/rbac/v1/test_secret_stores.py +++ b/barbican_tempest_plugin/tests/rbac/v1/test_secret_stores.py @@ -97,6 +97,7 @@ class ProjectMemberTests(base.BarbicanV1RbacBase, BarbicanV1RbacSecretStores): We need to set up the devstack plugin to use multiple backends so we can run these tests. """ + super().skip_checks() if not CONF.barbican_tempest.enable_multiple_secret_stores: raise cls.skipException("enable_multiple_secret_stores is not " "configured. Skipping RBAC tests.") @@ -125,6 +126,18 @@ class ProjectMemberTests(base.BarbicanV1RbacBase, BarbicanV1RbacSecretStores): self.assertTrue(resp['global_default']) def test_get_preferred_secret_store(self): + # First use project admin to set preferred secret store + resp = self.do_request('list_secret_stores') + secret_store_id = self.ref_to_uuid( + resp['secret_stores'][0]['secret_store_ref'] + ) + admin_client = self.os_project_admin.secret_v1.SecretStoresClient() + self.do_request('set_preferred_secret_store', + client=admin_client, + secret_store_id=secret_store_id) + + # Check that other users in project can view the newly set + # preferred secret store resp = self.do_request('get_preferred_secret_store') self.assertEqual('ACTIVE', resp['status']) @@ -142,7 +155,7 @@ class ProjectMemberTests(base.BarbicanV1RbacBase, BarbicanV1RbacSecretStores): secret_store_id = self.ref_to_uuid( resp['secret_stores'][0]['secret_store_ref'] ) - self.do_request('unset_peferred_secret_store', + self.do_request('unset_preferred_secret_store', expected_status=exceptions.Forbidden, secret_store_id=secret_store_id) @@ -172,11 +185,10 @@ class ProjectAdminTests(ProjectMemberTests): ) self.do_request('set_preferred_secret_store', secret_store_id=secret_store_id) - self.do_request('unset_peferred_secret_store', + self.do_request('unset_preferred_secret_store', secret_store_id=secret_store_id) - resp = self.do_request('get_preferred_secret_store') - self.assertEqual(secret_store_id, - self.ref_to_uuid(resp['secret_store_ref'])) + self.do_request('get_preferred_secret_store', + expected_status=exceptions.NotFound) class ProjectReaderTests(ProjectMemberTests):