Make vault tests conditional

This commit is contained in:
Nuwan Goonasekera
2021-11-27 20:51:36 +05:30
parent 062618bd2e
commit 569db6b465
5 changed files with 33 additions and 17 deletions
+1 -1
View File
@@ -182,7 +182,7 @@ class MockAppConfig(GalaxyDataTestConfig, CommonConfigurationMixin):
self.enable_tool_shed_check = False
self.monitor_thread_join_timeout = 1
self.integrated_tool_panel_config = None
self.vault_config_file = None
self.vault_config_file = kwargs.get('vault_config_file')
@property
def config_dict(self):
+2 -2
View File
@@ -265,8 +265,8 @@ class ProvidesUserFileSourcesUserContext:
@property
def vault(self):
user = self.trans.user
return user and user.personal_vault or defaultdict(lambda: None)
user_vault = self.trans.user_vault
return user_vault or defaultdict(lambda: None)
class DictFileSourcesUserContext:
+1 -1
View File
@@ -1,6 +1,6 @@
import json
import os
from typing import cast, Any
from typing import Any, cast
from requests import (
get,
@@ -1,3 +1,5 @@
# to run tests, start vault with:
# $ vault server -dev -dev-root-token-id=galaxy_test_token
type: hashicorp
vault_address: http://localhost:8200
vault_token: galaxy_test_token
vault_address: ${vault_address}
vault_token: ${vault_token}
+25 -11
View File
@@ -7,34 +7,44 @@ from abc import ABC
from cryptography.fernet import InvalidToken
from galaxy.app_unittest_utils.galaxy_mock import MockApp, MockAppConfig
from galaxy.security.vault import NullVault, Vault, VaultFactory
from galaxy.security.vault import Vault, VaultFactory
class VaultTestBase(ABC, unittest.TestCase):
def __init__(self):
self.vault = NullVault() # type: Vault
class VaultTestBase(ABC):
vault: Vault
def test_read_write_secret(self):
self.vault.write_secret("my/test/secret", "hello world")
self.assertEqual(self.vault.read_secret("my/test/secret"), "hello world")
self.assertEqual(self.vault.read_secret("my/test/secret"), "hello world") # type: ignore
def test_overwrite_secret(self):
self.vault.write_secret("my/new/secret", "hello world")
self.vault.write_secret("my/new/secret", "hello overwritten")
self.assertEqual(self.vault.read_secret("my/new/secret"), "hello overwritten")
self.assertEqual(self.vault.read_secret("my/new/secret"), "hello overwritten") # type: ignore
VAULT_CONF_HASHICORP = os.path.join(os.path.dirname(__file__), "fixtures/vault_conf_hashicorp.yaml")
@unittest.skipIf(not os.environ.get('VAULT_ADDRESS') or not os.environ.get('VAULT_TOKEN'),
"VAULT_ADDRESS and VAULT_TOKEN env vars not set")
class TestHashicorpVault(VaultTestBase, unittest.TestCase):
def setUp(self) -> None:
config = MockAppConfig(vault_config_file=VAULT_CONF_HASHICORP)
with tempfile.NamedTemporaryFile(
mode="w", prefix="vault_hashicorp", delete=False) as tempconf, open(VAULT_CONF_HASHICORP) as f:
content = string.Template(f.read()).safe_substitute(
vault_address=os.environ.get('VAULT_ADDRESS'),
vault_token=os.environ.get('VAULT_TOKEN'))
tempconf.write(content)
self.vault_temp_conf = tempconf.name
config = MockAppConfig(vault_config_file=self.vault_temp_conf)
app = MockApp(config=config)
self.vault = VaultFactory.from_app(app)
def tearDown(self) -> None:
os.remove(self.vault_temp_conf)
VAULT_CONF_DATABASE = os.path.join(os.path.dirname(__file__), "fixtures/vault_conf_database.yaml")
VAULT_CONF_DATABASE_ROTATED = os.path.join(os.path.dirname(__file__), "fixtures/vault_conf_database_rotated.yaml")
@@ -75,12 +85,16 @@ class TestDatabaseVault(VaultTestBase, unittest.TestCase):
VAULT_CONF_CUSTOS = os.path.join(os.path.dirname(__file__), "fixtures/vault_conf_custos.yaml")
@unittest.skipIf(not os.environ.get('CUSTOS_CLIENT_ID') or not os.environ.get('CUSTOS_CLIENT_SECRET'),
"CUSTOS_CLIENT_ID and CUSTOS_CLIENT_SECRET env vars not set")
class TestCustosVault(VaultTestBase, unittest.TestCase):
def setUp(self) -> None:
with tempfile.NamedTemporaryFile(mode="w", prefix="vault_custos", delete=False) as tempconf, open(VAULT_CONF_CUSTOS) as f:
content = string.Template(f.read()).safe_substitute(custos_client_id=os.environ.get('CUSTOS_CLIENT_ID'),
custos_client_secret=os.environ.get('CUSTOS_CLIENT_SECRET'))
with tempfile.NamedTemporaryFile(
mode="w", prefix="vault_custos", delete=False) as tempconf, open(VAULT_CONF_CUSTOS) as f:
content = string.Template(f.read()).safe_substitute(
custos_client_id=os.environ.get('CUSTOS_CLIENT_ID'),
custos_client_secret=os.environ.get('CUSTOS_CLIENT_SECRET'))
tempconf.write(content)
self.vault_temp_conf = tempconf.name
config = MockAppConfig(vault_config_file=self.vault_temp_conf)