From 809ae5c5d02a67550907ed84a599f8b3a8d1977a Mon Sep 17 00:00:00 2001 From: Lingxian Kong Date: Fri, 27 Jul 2018 14:46:38 +1200 Subject: [PATCH] Skip some tests for vault plugin Vault secretstore plugin doesn't support asymmetric key generation for now, so disable the related functional tests. With this patch, the following functional tests sould be skipped: api.v1.functional.test_orders.OrdersTestCase.test_encryption_using_generated_key api.v1.functional.test_rsa.RSATestCase.test_rsa_order_certificate_from_ordered_container api.v1.functional.test_rsa.RSATestCase.test_rsa_order_certificate_from_ordered_container_with_pass api.v1.functional.test_rsa.RSATestCase.test_rsa_order_container api.v1.functional.test_rsa.RSATestCase.test_rsa_order_container_with_passphrase Change-Id: If416f38cb87bdb279a05263b99b5f2af916c1229 --- barbican/tests/utils.py | 18 ++++-------------- .../api/v1/functional/test_orders.py | 3 +++ functionaltests/api/v1/functional/test_rsa.py | 8 ++++++-- functionaltests/run_tests.sh | 2 ++ tox.ini | 2 ++ 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/barbican/tests/utils.py b/barbican/tests/utils.py index 4a3acbc96..81b2936bc 100644 --- a/barbican/tests/utils.py +++ b/barbican/tests/utils.py @@ -610,20 +610,6 @@ def get_tomorrow_timestamp(): return tomorrow.isoformat() -def string_to_datetime(datetimestring, date_formats=None): - date_formats = date_formats or [ - '%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M:%S.%f', '%Y-%m-%dT%H:%M:%S.%fZ', - '%Y-%m-%dT%H:%M:%S.%f', "%Y-%m-%dT%H:%M:%SZ", "%Y-%m-%dT%H:%M:%S"] - - for dateformat in date_formats: - try: - return datetime.datetime.strptime(datetimestring, dateformat) - except ValueError: - continue - else: - raise - - def get_id_from_ref(ref): """Returns id from reference.""" ref_id = None @@ -676,5 +662,9 @@ def is_kmip_enabled(): return os.environ.get('KMIP_PLUGIN_ENABLED') is not None +def is_vault_enabled(): + return os.environ.get('VAULT_PLUGIN_ENABLED') is not None + + class DummyClassForTesting(object): pass diff --git a/functionaltests/api/v1/functional/test_orders.py b/functionaltests/api/v1/functional/test_orders.py index f50edcdcb..f0e74c7c8 100644 --- a/functionaltests/api/v1/functional/test_orders.py +++ b/functionaltests/api/v1/functional/test_orders.py @@ -16,6 +16,7 @@ from oslo_serialization import jsonutils import sys import time +import testtools from testtools import testcase from barbican.tests import utils @@ -567,6 +568,8 @@ class OrdersTestCase(base.TestCase): self.assertRegex(order_resp.model.order_ref, regex) @testcase.attr('positive') + @testtools.skipIf(utils.is_vault_enabled(), + "Vault does not support this operation") def test_encryption_using_generated_key(self): """Tests functionality of a generated asymmetric key pair.""" test_model = order_models.OrderModel(**self.asymmetric_data) diff --git a/functionaltests/api/v1/functional/test_rsa.py b/functionaltests/api/v1/functional/test_rsa.py index 011f95bab..45399fd60 100644 --- a/functionaltests/api/v1/functional/test_rsa.py +++ b/functionaltests/api/v1/functional/test_rsa.py @@ -236,6 +236,8 @@ class RSATestCase(base.TestCase): self.verify_container_keys_equal(secrets, with_passphrase=True) @testcase.attr('positive') + @testtools.skipIf(utils.is_vault_enabled(), + "Vault does not support this operation") def test_rsa_order_container(self): """Post an order for a container""" order_ref = self.order_container() @@ -244,7 +246,7 @@ class RSATestCase(base.TestCase): self.verify_container_keys_valid(secrets) @testcase.attr('positive') - @testtools.skipIf(utils.is_kmip_enabled(), + @testtools.skipIf(utils.is_kmip_enabled() or utils.is_vault_enabled(), "PyKMIP does not support this operation") def test_rsa_order_container_with_passphrase(self): """Post an order for a container with a passphrase""" @@ -265,6 +267,8 @@ class RSATestCase(base.TestCase): self.verify_container_keys_equal(secrets) @testcase.attr('positive') + @testtools.skipIf(utils.is_vault_enabled(), + "Vault does not support this operation") def test_rsa_order_certificate_from_ordered_container(self): """Post an order for a certificate""" order_ref = self.order_container() @@ -276,7 +280,7 @@ class RSATestCase(base.TestCase): self.verify_certificate_order_status(order_status) @testcase.attr('positive') - @testtools.skipIf(utils.is_kmip_enabled(), + @testtools.skipIf(utils.is_kmip_enabled() or utils.is_vault_enabled(), "PyKMIP does not support this operation") def test_rsa_order_certificate_from_ordered_container_with_pass(self): """Post an order for a certificate""" diff --git a/functionaltests/run_tests.sh b/functionaltests/run_tests.sh index 4baf923ff..35e1ade6f 100755 --- a/functionaltests/run_tests.sh +++ b/functionaltests/run_tests.sh @@ -26,6 +26,8 @@ plugin=$1 if [[ "$plugin" == "kmip" ]]; then export KMIP_PLUGIN_ENABLED=1 +elif [[ "$plugin" == "vault" ]]; then + export VAULT_PLUGIN_ENABLED=1 fi # run the tests sequentially diff --git a/tox.ini b/tox.ini index 4a1b02049..a840b921d 100644 --- a/tox.ini +++ b/tox.ini @@ -113,6 +113,7 @@ commands = coverage html -d cover coverage xml -o cover/coverage.xml passenv = KMIP_PLUGIN_ENABLED + VAULT_PLUGIN_ENABLED [testenv:py35functional] basepython = python3 @@ -126,6 +127,7 @@ commands = coverage html -d cover coverage xml -o cover/coverage.xml passenv = KMIP_PLUGIN_ENABLED + VAULT_PLUGIN_ENABLED [testenv:cmd] basepython = python3