summaryrefslogtreecommitdiff
path: root/functionaltests
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
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')
-rw-r--r--functionaltests/cli/v1/behaviors/consumer_behaviors.py48
-rw-r--r--functionaltests/cli/v1/behaviors/secret_behaviors.py2
-rw-r--r--functionaltests/client/v1/functional/test_secrets.py77
-rw-r--r--functionaltests/common/cleanup.py20
4 files changed, 145 insertions, 2 deletions
diff --git a/functionaltests/cli/v1/behaviors/consumer_behaviors.py b/functionaltests/cli/v1/behaviors/consumer_behaviors.py
new file mode 100644
index 0000000..14d5578
--- /dev/null
+++ b/functionaltests/cli/v1/behaviors/consumer_behaviors.py
@@ -0,0 +1,48 @@
+# Copyright 2022 Red Hat Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+
+from functionaltests.cli.v1.behaviors import base_behaviors
+
+
+class ConsumerBehaviors(base_behaviors.BaseBehaviors):
+
+ def __init__(self):
+ super(ConsumerBehaviors, self).__init__()
+ self.LOG = logging.getLogger(type(self).__name__)
+
+ def register_consumer(self, secret_href, service, resource_type,
+ resource_id):
+ argv = ['secret', 'consumer', 'create']
+ self.add_auth_and_endpoint(argv)
+
+ argv.extend(['--service-type-name', service])
+ argv.extend(['--resource-type', resource_type])
+ argv.extend(['--resource-id', resource_id])
+ argv.extend([secret_href])
+
+ stdout, stderr = self.issue_barbican_command(argv)
+
+ def remove_consumer(self, secret_href, service, resource_type,
+ resource_id):
+ argv = ['secret', 'consumer', 'delete']
+ self.add_auth_and_endpoint(argv)
+
+ argv.extend(['--service-type-name', service])
+ argv.extend(['--resource-type', resource_type])
+ argv.extend(['--resource-id', resource_id])
+ argv.extend([secret_href])
+
+ stdout, stderr = self.issue_barbican_command(argv)
diff --git a/functionaltests/cli/v1/behaviors/secret_behaviors.py b/functionaltests/cli/v1/behaviors/secret_behaviors.py
index 733da3a..f0d5bd8 100644
--- a/functionaltests/cli/v1/behaviors/secret_behaviors.py
+++ b/functionaltests/cli/v1/behaviors/secret_behaviors.py
@@ -46,7 +46,7 @@ class SecretBehaviors(base_behaviors.BaseBehaviors):
:param secret_href the href to the secret to delete
"""
- argv = ['secret', 'delete']
+ argv = ['secret', 'delete', '--force']
self.add_auth_and_endpoint(argv)
argv.extend([secret_href])
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.
diff --git a/functionaltests/common/cleanup.py b/functionaltests/common/cleanup.py
index 031ed58..37439bb 100644
--- a/functionaltests/common/cleanup.py
+++ b/functionaltests/common/cleanup.py
@@ -58,6 +58,24 @@ class CleanUp(object):
self.created_entities[entity_type].append(entity_ref)
return entity_ref
+ def delete_entity(self, entity):
+ """Deletes an entity from Barbican
+
+ Used for testing. Individually deletes an entity.
+
+ """
+ entity_type = entity.lower()
+ if 'acl' in entity_type:
+ entity_type = 'acl'
+ elif 'secret' in entity_type:
+ entity_type = 'secret'
+ elif 'container' in entity_type:
+ entity_type = 'container'
+ else:
+ entity_type = 'order'
+
+ self.created_entities[entity_type].remove(entity)
+
def _delete_all_containers(self):
"""Helper method to delete all containers used for testing"""
for container_ref in self.created_entities['container']:
@@ -66,7 +84,7 @@ class CleanUp(object):
def _delete_all_secrets(self):
"""Helper method to delete all secrets used for testing"""
for secret_ref in self.created_entities['secret']:
- self.barbicanclient.secrets.delete(secret_ref)
+ self.barbicanclient.secrets.delete(secret_ref, True)
def _delete_all_acls(self):
"""Helper method to delete all acls used for testing"""