summaryrefslogtreecommitdiff
path: root/functionaltests/client/v1/functional/test_secrets.py
diff options
context:
space:
mode:
authorMauricio Harley <mharley@redhat.com>2022-11-24 10:50:27 +0100
committerAndre Aranha <afariasa@redhat.com>2023-02-07 13:50:51 +0100
commit7f6b3cf790e7d37e85fb38d300fb43573f31184c (patch)
treea89292f06044ac6a5368d8261e015900b0864536 /functionaltests/client/v1/functional/test_secrets.py
parent3ffa1600af21620d7f141faee9389c7e7e9079e3 (diff)
downloadpython-barbicanclient-7f6b3cf790e7d37e85fb38d300fb43573f31184c.tar.gz
Added the force parameter to consumer removal and the corresponding CLI commands
When deleting a secret that has consumers, the --force parameter must be specified in the CLI. Change-Id: I49d19ac843d5c805fd7f533d07a3a719ce9a1104
Diffstat (limited to 'functionaltests/client/v1/functional/test_secrets.py')
-rw-r--r--functionaltests/client/v1/functional/test_secrets.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/functionaltests/client/v1/functional/test_secrets.py b/functionaltests/client/v1/functional/test_secrets.py
index 205cc58..645094a 100644
--- a/functionaltests/client/v1/functional/test_secrets.py
+++ b/functionaltests/client/v1/functional/test_secrets.py
@@ -288,6 +288,83 @@ class SecretsTestCase(base.TestCase):
)
self.assertIn('remove_consumer() missing', str(e))
+ @testcase.attr('positive')
+ def test_secret_delete_without_consumers_no_force(self):
+ new_secret = self.barbicanclient.secrets.create(
+ **secret_create_defaults_data)
+
+ secret_ref = self.cleanup.add_entity(new_secret)
+
+ self.barbicanclient.secrets.delete(secret_ref, force=False)
+ resp = self.barbicanclient.secrets.get(secret_ref)
+ self.assertRaises(exceptions.HTTPClientError, getattr, resp, "name")
+ self.cleanup.delete_entity(secret_ref)
+
+ @testcase.attr('positive')
+ def test_secret_delete_without_consumers_with_force(self):
+ new_secret = self.barbicanclient.secrets.create(
+ **secret_create_defaults_data)
+
+ secret_ref = self.cleanup.add_entity(new_secret)
+
+ self.barbicanclient.secrets.delete(secret_ref, force=True)
+ resp = self.barbicanclient.secrets.get(secret_ref)
+ self.assertRaises(exceptions.HTTPClientError, getattr, resp, "name")
+ self.cleanup.delete_entity(secret_ref)
+
+ @testcase.attr('negative')
+ def test_secret_delete_with_consumers_no_force(self):
+ """Deleting a secret with consumers.
+
+ Tries to delete a secret with consumers, but
+ without providing the 'force' parameter.
+ """
+ new_secret = self.barbicanclient.secrets.create(
+ **secret_create_defaults_data)
+
+ secret_ref = self.cleanup.add_entity(new_secret)
+ self.assertIsNotNone(secret_ref)
+
+ secret = self.barbicanclient.secrets.register_consumer(
+ secret_ref,
+ service="service1",
+ resource_type="type1",
+ resource_id="id1"
+ )
+ self.assertEqual(secret_ref, secret.secret_ref)
+
+ e = self.assertRaises(ValueError, self.barbicanclient.secrets.delete,
+ secret.secret_ref)
+
+ self.assertIn("Secret has consumers! Remove them first or use the "
+ "force parameter to delete it.", str(e))
+
+ @testcase.attr('positive')
+ def test_secret_delete_with_consumers_with_force(self):
+ """Deleting a secret with consumers.
+
+ Tries to delete a secret with consumers,
+ making the 'force' parameter equals True.
+ """
+ new_secret = self.barbicanclient.secrets.create(
+ **secret_create_defaults_data)
+
+ secret_ref = self.cleanup.add_entity(new_secret)
+ self.assertIsNotNone(secret_ref)
+
+ secret = self.barbicanclient.secrets.register_consumer(
+ secret_ref,
+ service="service1",
+ resource_type="type1",
+ resource_id="id1"
+ )
+ self.assertEqual(secret_ref, secret.secret_ref)
+
+ self.barbicanclient.secrets.delete(secret.secret_ref, True)
+ resp = self.barbicanclient.secrets.get(secret_ref)
+ self.assertRaises(exceptions.HTTPClientError, getattr, resp, "name")
+ self.cleanup.delete_entity(secret_ref)
+
@testcase.attr('negative')
def test_secret_delete_doesnt_exist(self):
"""Deletes a non-existent secret.