From 1599a3a4a77b4a636fd2a0ed1d1a9d5ec514343e Mon Sep 17 00:00:00 2001 From: Haroon Sheikh Date: Thu, 12 Sep 2024 10:51:40 +0100 Subject: [PATCH] Adds ability to specify a default secret path when loading from vault --- .../sitture/envconfig/EnvConfigKey.java | 34 +++++++ .../envconfig/EnvConfigProperties.java | 44 +++++----- .../sitture/envconfig/EnvConfigUtils.java | 15 ---- .../envconfig/EnvConfigPrecedenceTest.java | 6 +- .../envconfig/EnvConfigProfileTest.java | 10 +-- .../envconfig/EnvConfigPropertiesTest.java | 48 +++++----- .../sitture/envconfig/EnvConfigTest.java | 88 +++++++++---------- .../sitture/envconfig/EnvConfigVaultTest.java | 57 ++++++------ 8 files changed, 160 insertions(+), 142 deletions(-) create mode 100644 src/main/java/com/github/sitture/envconfig/EnvConfigKey.java diff --git a/src/main/java/com/github/sitture/envconfig/EnvConfigKey.java b/src/main/java/com/github/sitture/envconfig/EnvConfigKey.java new file mode 100644 index 0000000..fd54f2d --- /dev/null +++ b/src/main/java/com/github/sitture/envconfig/EnvConfigKey.java @@ -0,0 +1,34 @@ +package com.github.sitture.envconfig; + +enum EnvConfigKey { + + CONFIG_PATH("env.config.path"), + CONFIG_ENV("env.config.environment"), + CONFIG_PROFILE("env.config.profile"), + CONFIG_PROFILES_PATH("env.config.profiles.path"), + CONFIG_KEEPASS_ENABLED("env.config.keepass.enabled"), + CONFIG_KEEPASS_FILENAME("env.config.keepass.filename"), + CONFIG_KEEPASS_MASTERKEY("env.config.keepass.masterkey"), + CONFIG_VAULT_ENABLED("env.config.vault.enabled"), + CONFIG_VAULT_ADDRESS("env.config.vault.address"), + CONFIG_VAULT_NAMESPACE("env.config.vault.namespace"), + CONFIG_VAULT_DEFAULT_PATH("env.config.vault.default.secret.path"), + CONFIG_VAULT_SECRET_PATH("env.config.vault.secret.path"), + CONFIG_VAULT_TOKEN("env.config.vault.token"), + CONFIG_VAULT_VALIDATE_MAX_RETRIES("env.config.vault.validate.token.max.retries"); + + private final String property; + + EnvConfigKey(final String property) { + this.property = property; + } + + public String getProperty() { + return this.property; + } + + public String getEnvProperty() { + return EnvConfigUtils.getProcessedEnvKey(this.property); + } + +} diff --git a/src/main/java/com/github/sitture/envconfig/EnvConfigProperties.java b/src/main/java/com/github/sitture/envconfig/EnvConfigProperties.java index 0d013eb..4516b3c 100644 --- a/src/main/java/com/github/sitture/envconfig/EnvConfigProperties.java +++ b/src/main/java/com/github/sitture/envconfig/EnvConfigProperties.java @@ -38,13 +38,13 @@ String getCurrentEnvironment() { } String getConfigProfile() { - return getConfigurationProperty(EnvConfigUtils.CONFIG_PROFILE_KEY, ""); + return getConfigProperty(EnvConfigKey.CONFIG_PROFILE, ""); } private List getEnvList() { final List environments = new ArrayList<>(); environments.add(EnvConfigUtils.CONFIG_ENV_DEFAULT); - environments.addAll(EnvConfigUtils.getListOfValues(getConfigurationProperty(EnvConfigUtils.CONFIG_ENV_KEY, EnvConfigUtils.CONFIG_ENV_DEFAULT).toLowerCase(), EnvConfigUtils.CONFIG_DELIMITER_DEFAULT)); + environments.addAll(EnvConfigUtils.getListOfValues(getConfigProperty(EnvConfigKey.CONFIG_ENV, EnvConfigUtils.CONFIG_ENV_DEFAULT).toLowerCase(), EnvConfigUtils.CONFIG_DELIMITER_DEFAULT)); Collections.reverse(environments); return environments.stream().distinct().collect(Collectors.toList()); } @@ -54,7 +54,7 @@ Path getConfigPath(final String env) { } private Path getConfigPath() { - return getPath(Paths.get(getConfigurationProperty(EnvConfigUtils.CONFIG_PATH_KEY, EnvConfigUtils.CONFIG_PATH_DEFAULT)).toAbsolutePath()); + return getPath(Paths.get(getConfigProperty(EnvConfigKey.CONFIG_PATH, EnvConfigUtils.CONFIG_PATH_DEFAULT)).toAbsolutePath()); } Path getConfigProfilePath(final String env, final String configProfile) { @@ -62,7 +62,7 @@ Path getConfigProfilePath(final String env, final String configProfile) { } private Path getConfigProfilePath() { - return getPath(Paths.get(getConfigurationProperty(EnvConfigUtils.CONFIG_PROFILES_PATH_KEY, this.configDir.toString())).toAbsolutePath()); + return getPath(Paths.get(getConfigProperty(EnvConfigKey.CONFIG_PROFILES_PATH, this.configDir.toString())).toAbsolutePath()); } private Path getPath(final Path configPath) { @@ -74,42 +74,42 @@ private Path getPath(final Path configPath) { return configPath; } - private String getConfigurationProperty(final String key, final String defaultValue) { - return Optional.ofNullable(System.getProperty(key)) + private String getConfigProperty(final EnvConfigKey key, final String defaultValue) { + return Optional.ofNullable(System.getProperty(key.getProperty())) .orElse(Optional.ofNullable(getEnvByPropertyKey(key)) .orElse(defaultValue)); } - private String getEnvByPropertyKey(final String key) { + private String getEnvByPropertyKey(final EnvConfigKey key) { LOG.debug("Getting {} from system.env", key); - return Optional.ofNullable(System.getenv(EnvConfigUtils.getProcessedEnvKey(key))) - .orElse(System.getenv(key)); + return Optional.ofNullable(System.getenv(EnvConfigUtils.getProcessedEnvKey(key.getProperty()))) + .orElse(System.getenv(key.getProperty())); } - private String getRequiredConfigKey(final String key) { - return Optional.ofNullable(getConfigurationProperty(key, null)) - .orElseThrow(() -> new EnvConfigException(String.format("Missing required variable '%s'", key))); + private String getRequiredConfigProperty(final EnvConfigKey key) { + return Optional.ofNullable(getConfigProperty(key, null)) + .orElseThrow(() -> new EnvConfigException(String.format("Missing required variable '%s'", key.getProperty()))); } boolean isConfigKeepassEnabled() { - return Boolean.parseBoolean(getConfigurationProperty(EnvConfigUtils.CONFIG_KEEPASS_ENABLED_KEY, "false")); + return Boolean.parseBoolean(getConfigProperty(EnvConfigKey.CONFIG_KEEPASS_ENABLED, "false")); } EnvConfigKeepassProperties getKeepassProperties() { - return new EnvConfigKeepassProperties(new File(getConfigurationProperty(EnvConfigUtils.CONFIG_KEEPASS_FILENAME_KEY, getBuildDir())).getName(), - getRequiredConfigKey(EnvConfigUtils.CONFIG_KEEPASS_MASTERKEY_KEY)); + return new EnvConfigKeepassProperties(new File(getConfigProperty(EnvConfigKey.CONFIG_KEEPASS_FILENAME, getBuildDir())).getName(), + getRequiredConfigProperty(EnvConfigKey.CONFIG_KEEPASS_MASTERKEY)); } boolean isConfigVaultEnabled() { - return Boolean.parseBoolean(getConfigurationProperty(EnvConfigUtils.CONFIG_VAULT_ENABLED_KEY, "false")); + return Boolean.parseBoolean(getConfigProperty(EnvConfigKey.CONFIG_VAULT_ENABLED, "false")); } EnvConfigVaultProperties getVaultProperties() { - return new EnvConfigVaultProperties(getRequiredConfigKey(EnvConfigUtils.CONFIG_VAULT_ADDRESS_KEY), - getRequiredConfigKey(EnvConfigUtils.CONFIG_VAULT_NAMESPACE_KEY), - getRequiredConfigKey(EnvConfigUtils.CONFIG_VAULT_TOKEN_KEY), - getRequiredConfigKey(EnvConfigUtils.CONFIG_VAULT_SECRET_PATH_KEY), - getConfigurationProperty(EnvConfigUtils.CONFIG_VAULT_DEFAULT_PATH_KEY, null), - Integer.parseInt(getConfigurationProperty(EnvConfigUtils.CONFIG_VAULT_VALIDATE_MAX_RETRIES, "5"))); + return new EnvConfigVaultProperties(getRequiredConfigProperty(EnvConfigKey.CONFIG_VAULT_ADDRESS), + getRequiredConfigProperty(EnvConfigKey.CONFIG_VAULT_NAMESPACE), + getRequiredConfigProperty(EnvConfigKey.CONFIG_VAULT_TOKEN), + getRequiredConfigProperty(EnvConfigKey.CONFIG_VAULT_SECRET_PATH), + getConfigProperty(EnvConfigKey.CONFIG_VAULT_DEFAULT_PATH, null), + Integer.parseInt(getConfigProperty(EnvConfigKey.CONFIG_VAULT_VALIDATE_MAX_RETRIES, "5"))); } } diff --git a/src/main/java/com/github/sitture/envconfig/EnvConfigUtils.java b/src/main/java/com/github/sitture/envconfig/EnvConfigUtils.java index e42325e..57868dc 100644 --- a/src/main/java/com/github/sitture/envconfig/EnvConfigUtils.java +++ b/src/main/java/com/github/sitture/envconfig/EnvConfigUtils.java @@ -10,21 +10,6 @@ final class EnvConfigUtils { public static final String CONFIG_PATH_DEFAULT = "config"; public static final String CONFIG_ENV_DEFAULT = "default"; public static final String CONFIG_DELIMITER_DEFAULT = ","; - private static final String CONFIG_PREFIX = "env.config."; - public static final String CONFIG_PATH_KEY = CONFIG_PREFIX + "path"; - public static final String CONFIG_ENV_KEY = CONFIG_PREFIX + "environment"; - public static final String CONFIG_PROFILE_KEY = CONFIG_PREFIX + "profile"; - public static final String CONFIG_PROFILES_PATH_KEY = CONFIG_PREFIX + "profiles.path"; - public static final String CONFIG_KEEPASS_ENABLED_KEY = CONFIG_PREFIX + "keepass.enabled"; - public static final String CONFIG_KEEPASS_FILENAME_KEY = CONFIG_PREFIX + "keepass.filename"; - public static final String CONFIG_KEEPASS_MASTERKEY_KEY = CONFIG_PREFIX + "keepass.masterkey"; - public static final String CONFIG_VAULT_ENABLED_KEY = CONFIG_PREFIX + "vault.enabled"; - public static final String CONFIG_VAULT_ADDRESS_KEY = CONFIG_PREFIX + "vault.address"; - public static final String CONFIG_VAULT_NAMESPACE_KEY = CONFIG_PREFIX + "vault.namespace"; - public static final String CONFIG_VAULT_DEFAULT_PATH_KEY = CONFIG_PREFIX + "vault.default.secret.path"; - public static final String CONFIG_VAULT_SECRET_PATH_KEY = CONFIG_PREFIX + "vault.secret.path"; - public static final String CONFIG_VAULT_TOKEN_KEY = CONFIG_PREFIX + "vault.token"; - public static final String CONFIG_VAULT_VALIDATE_MAX_RETRIES = CONFIG_PREFIX + "vault.validate.token.max.retries"; private EnvConfigUtils() { } diff --git a/src/test/java/com/github/sitture/envconfig/EnvConfigPrecedenceTest.java b/src/test/java/com/github/sitture/envconfig/EnvConfigPrecedenceTest.java index 0ad5017..90cd876 100644 --- a/src/test/java/com/github/sitture/envconfig/EnvConfigPrecedenceTest.java +++ b/src/test/java/com/github/sitture/envconfig/EnvConfigPrecedenceTest.java @@ -192,12 +192,12 @@ void testParentEnvironmentTakesPriorityWhenEnvVarAndDefaultValueSame() { } private void setKeepassEnabled() { - systemProperties.set(EnvConfigUtils.CONFIG_KEEPASS_ENABLED_KEY, true); - systemProperties.set(EnvConfigUtils.CONFIG_KEEPASS_MASTERKEY_KEY, CONFIG_KEEPASS_MASTERKEY); + systemProperties.set(EnvConfigKey.CONFIG_KEEPASS_ENABLED.getProperty(), true); + systemProperties.set(EnvConfigKey.CONFIG_KEEPASS_MASTERKEY.getProperty(), CONFIG_KEEPASS_MASTERKEY); } private void setEnvironment(final String environment) { - systemProperties.set(EnvConfigUtils.CONFIG_ENV_KEY, environment); + systemProperties.set(EnvConfigKey.CONFIG_ENV.getProperty(), environment); } } diff --git a/src/test/java/com/github/sitture/envconfig/EnvConfigProfileTest.java b/src/test/java/com/github/sitture/envconfig/EnvConfigProfileTest.java index 198ea3e..ea109b6 100644 --- a/src/test/java/com/github/sitture/envconfig/EnvConfigProfileTest.java +++ b/src/test/java/com/github/sitture/envconfig/EnvConfigProfileTest.java @@ -22,8 +22,8 @@ void setUp() { @AfterEach void tearDown() { - System.clearProperty(EnvConfigUtils.CONFIG_PROFILE_KEY); - System.clearProperty(EnvConfigUtils.CONFIG_PROFILES_PATH_KEY); + System.clearProperty(EnvConfigKey.CONFIG_PROFILE.getProperty()); + System.clearProperty(EnvConfigKey.CONFIG_PROFILES_PATH.getProperty()); } @Test @@ -154,15 +154,15 @@ void testThrowsExceptionWhenNoPropertiesInProfile() { } private void setEnvironment(final String environment) { - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, environment); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), environment); } private void setProfile(final String profile) { - System.setProperty(EnvConfigUtils.CONFIG_PROFILE_KEY, profile); + System.setProperty(EnvConfigKey.CONFIG_PROFILE.getProperty(), profile); } private void setProfilePath(final String path) { - System.setProperty(EnvConfigUtils.CONFIG_PROFILES_PATH_KEY, path); + System.setProperty(EnvConfigKey.CONFIG_PROFILES_PATH.getProperty(), path); } } diff --git a/src/test/java/com/github/sitture/envconfig/EnvConfigPropertiesTest.java b/src/test/java/com/github/sitture/envconfig/EnvConfigPropertiesTest.java index 2413aed..0f00536 100644 --- a/src/test/java/com/github/sitture/envconfig/EnvConfigPropertiesTest.java +++ b/src/test/java/com/github/sitture/envconfig/EnvConfigPropertiesTest.java @@ -14,12 +14,12 @@ class EnvConfigPropertiesTest { @AfterEach void tearDown() { - System.clearProperty(EnvConfigUtils.CONFIG_PATH_KEY); - System.clearProperty(EnvConfigUtils.CONFIG_KEEPASS_ENABLED_KEY); - System.clearProperty(EnvConfigUtils.CONFIG_KEEPASS_FILENAME_KEY); - System.clearProperty(EnvConfigUtils.CONFIG_PROFILE_KEY); - System.clearProperty(EnvConfigUtils.CONFIG_PROFILES_PATH_KEY); - System.clearProperty(EnvConfigUtils.CONFIG_KEEPASS_MASTERKEY_KEY); + System.clearProperty(EnvConfigKey.CONFIG_PATH.getProperty()); + System.clearProperty(EnvConfigKey.CONFIG_KEEPASS_ENABLED.getProperty()); + System.clearProperty(EnvConfigKey.CONFIG_KEEPASS_FILENAME.getProperty()); + System.clearProperty(EnvConfigKey.CONFIG_PROFILE.getProperty()); + System.clearProperty(EnvConfigKey.CONFIG_PROFILES_PATH.getProperty()); + System.clearProperty(EnvConfigKey.CONFIG_KEEPASS_MASTERKEY.getProperty()); } @Test @@ -30,31 +30,31 @@ void testCanGetBuildDir() { @Test void testCanGetConfigProfile() { final EnvConfigProperties configProperties = new EnvConfigProperties(); - System.clearProperty(EnvConfigUtils.CONFIG_PROFILE_KEY); + System.clearProperty(EnvConfigKey.CONFIG_PROFILE.getProperty()); Assertions.assertEquals("", configProperties.getConfigProfile(), "invalid config-profile!"); - System.setProperty(EnvConfigUtils.CONFIG_PROFILE_KEY, "test-profile"); + System.setProperty(EnvConfigKey.CONFIG_PROFILE.getProperty(), "test-profile"); Assertions.assertEquals("test-profile", configProperties.getConfigProfile()); } @Test void testCanGetEnvironmentsList() { // when config.environment isn't specified - System.clearProperty(EnvConfigUtils.CONFIG_ENV_KEY); + System.clearProperty(EnvConfigKey.CONFIG_ENV.getProperty()); Assertions.assertEquals(List.of("default"), new EnvConfigProperties().getEnvironments()); Assertions.assertEquals("default", new EnvConfigProperties().getCurrentEnvironment()); // when a single environment is specified - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, "test "); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), "test "); Assertions.assertEquals(List.of("test", "default"), new EnvConfigProperties().getEnvironments()); Assertions.assertEquals("test", new EnvConfigProperties().getCurrentEnvironment()); // when a multiple environments are specified - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, "test , TEST2"); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), "test , TEST2"); Assertions.assertEquals(List.of("test2", "test", "default"), new EnvConfigProperties().getEnvironments()); Assertions.assertEquals("test2", new EnvConfigProperties().getCurrentEnvironment()); // when a default specified in environments - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, "DEFAULT,alpha,zen"); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), "DEFAULT,alpha,zen"); Assertions.assertEquals(List.of("zen", "alpha", "default"), new EnvConfigProperties().getEnvironments()); // when only default specified in environments - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, "default"); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), "default"); Assertions.assertEquals(List.of("default"), new EnvConfigProperties().getEnvironments()); } @@ -70,7 +70,7 @@ void testCanGetConfigAndProfilePath() { @Test void testExceptionWhenConfigPathDoesNotExist() { - System.setProperty(EnvConfigUtils.CONFIG_PATH_KEY, "/non/existing/dir"); + System.setProperty(EnvConfigKey.CONFIG_PATH.getProperty(), "/non/existing/dir"); final EnvConfigException exception = Assertions.assertThrows(EnvConfigException.class, () -> new EnvConfigProperties().getConfigPath("env")); Assertions.assertEquals("'/non/existing/dir' does not exist or not a valid config directory!", @@ -79,7 +79,7 @@ void testExceptionWhenConfigPathDoesNotExist() { @Test void testExceptionWhenConfigProfilePathDoesNotExist() { - System.setProperty(EnvConfigUtils.CONFIG_PROFILES_PATH_KEY, "/non/existing/dir"); + System.setProperty(EnvConfigKey.CONFIG_PROFILES_PATH.getProperty(), "/non/existing/dir"); final EnvConfigException exception = Assertions.assertThrows(EnvConfigException.class, () -> new EnvConfigProperties().getConfigProfilePath("env", "profile")); Assertions.assertEquals("'/non/existing/dir' does not exist or not a valid config directory!", @@ -91,7 +91,7 @@ void testCanGetConfigPathWhenRelative() throws IOException { final Path directory = Files.createTempDirectory(Paths.get("config"), "sample-dir"); directory.toFile().deleteOnExit(); // when config.dir is set to relative path - System.setProperty(EnvConfigUtils.CONFIG_PATH_KEY, directory.toString()); + System.setProperty(EnvConfigKey.CONFIG_PATH.getProperty(), directory.toString()); final EnvConfigProperties configProperties = new EnvConfigProperties(); Assertions.assertEquals(Paths.get(directory.toAbsolutePath().toString(), "foo"), configProperties.getConfigPath("foo"), "Incorrect config path"); @@ -104,7 +104,7 @@ void testCanGetConfigPathWhenAbsoluteWithin() throws IOException { final Path directory = Files.createTempDirectory(Path.of(new EnvConfigProperties().getBuildDir()), "sample-dir"); directory.toFile().deleteOnExit(); // when config.dir is set to absolute - System.setProperty(EnvConfigUtils.CONFIG_PATH_KEY, directory.toString()); + System.setProperty(EnvConfigKey.CONFIG_PATH.getProperty(), directory.toString()); final EnvConfigProperties configProperties = new EnvConfigProperties(); Assertions.assertEquals(Paths.get(directory.toString(), "foo"), configProperties.getConfigPath("foo"), "Incorrect config path"); @@ -117,7 +117,7 @@ void testCanGetConfigPathWhenAbsolute() throws IOException { final Path directory = Files.createTempDirectory("sample-dir"); directory.toFile().deleteOnExit(); // when config.dir is set to absolute - System.setProperty(EnvConfigUtils.CONFIG_PATH_KEY, directory.toString()); + System.setProperty(EnvConfigKey.CONFIG_PATH.getProperty(), directory.toString()); final EnvConfigProperties configProperties = new EnvConfigProperties(); Assertions.assertEquals(Paths.get(directory.toString(), "foo"), configProperties.getConfigPath("foo"), "Incorrect config path"); @@ -129,14 +129,14 @@ void testCanGetConfigPathWhenAbsolute() throws IOException { void testCanGetConfigKeepassEnabled() { final EnvConfigProperties configProperties = new EnvConfigProperties(); Assertions.assertFalse(configProperties.isConfigKeepassEnabled(), "Incorrect keepass.enabled"); - System.setProperty(EnvConfigUtils.CONFIG_KEEPASS_ENABLED_KEY, "true"); + System.setProperty(EnvConfigKey.CONFIG_KEEPASS_ENABLED.getProperty(), "true"); Assertions.assertTrue(configProperties.isConfigKeepassEnabled(), "Incorrect keepass.enabled"); } @Test void testCanGetConfigKeepassFileName() { final EnvConfigProperties configProperties = new EnvConfigProperties(); - System.setProperty(EnvConfigUtils.CONFIG_KEEPASS_MASTERKEY_KEY, "foo"); + System.setProperty(EnvConfigKey.CONFIG_KEEPASS_MASTERKEY.getProperty(), "foo"); Assertions.assertEquals(new File(configProperties.getBuildDir()).getName(), configProperties.getKeepassProperties().getFilename(), "Incorrect keepass.filename path"); } @@ -144,8 +144,8 @@ void testCanGetConfigKeepassFileName() { @Test void testCanGetConfigKeepassFileNameWhenRelative() { final EnvConfigProperties configProperties = new EnvConfigProperties(); - System.setProperty(EnvConfigUtils.CONFIG_KEEPASS_FILENAME_KEY, "foobar.kdbx"); - System.setProperty(EnvConfigUtils.CONFIG_KEEPASS_MASTERKEY_KEY, "foo"); + System.setProperty(EnvConfigKey.CONFIG_KEEPASS_FILENAME.getProperty(), "foobar.kdbx"); + System.setProperty(EnvConfigKey.CONFIG_KEEPASS_MASTERKEY.getProperty(), "foo"); Assertions.assertEquals("foobar.kdbx", configProperties.getKeepassProperties().getFilename(), "Incorrect keepass.filename path"); } @@ -153,8 +153,8 @@ void testCanGetConfigKeepassFileNameWhenRelative() { @Test void testCanGetConfigKeepassFileNameWhenAbsolute() { final EnvConfigProperties configProperties = new EnvConfigProperties(); - System.setProperty(EnvConfigUtils.CONFIG_KEEPASS_FILENAME_KEY, "/dir/foobar.kdbx"); - System.setProperty(EnvConfigUtils.CONFIG_KEEPASS_MASTERKEY_KEY, "foo"); + System.setProperty(EnvConfigKey.CONFIG_KEEPASS_FILENAME.getProperty(), "/dir/foobar.kdbx"); + System.setProperty(EnvConfigKey.CONFIG_KEEPASS_MASTERKEY.getProperty(), "foo"); Assertions.assertEquals("foobar.kdbx", configProperties.getKeepassProperties().getFilename(), "Incorrect keepass.filename path"); } diff --git a/src/test/java/com/github/sitture/envconfig/EnvConfigTest.java b/src/test/java/com/github/sitture/envconfig/EnvConfigTest.java index cc336c4..e6c753c 100644 --- a/src/test/java/com/github/sitture/envconfig/EnvConfigTest.java +++ b/src/test/java/com/github/sitture/envconfig/EnvConfigTest.java @@ -25,9 +25,9 @@ class EnvConfigTest { @BeforeEach void setUp() { - System.clearProperty(EnvConfigUtils.CONFIG_KEEPASS_FILENAME_KEY); - System.clearProperty(EnvConfigUtils.CONFIG_KEEPASS_ENABLED_KEY); - System.clearProperty(EnvConfigUtils.CONFIG_KEEPASS_MASTERKEY_KEY); + System.clearProperty(EnvConfigKey.CONFIG_KEEPASS_FILENAME.getProperty()); + System.clearProperty(EnvConfigKey.CONFIG_KEEPASS_ENABLED.getProperty()); + System.clearProperty(EnvConfigKey.CONFIG_KEEPASS_MASTERKEY.getProperty()); System.clearProperty(PROPERTY_KEEPASS); EnvConfig.reset(); } @@ -39,28 +39,28 @@ void testStaticAndSingleton() { @Test void testCanGetDefaultEnvironment() { - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, EnvConfigUtils.CONFIG_ENV_DEFAULT); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), EnvConfigUtils.CONFIG_ENV_DEFAULT); Assertions.assertEquals(EnvConfigUtils.CONFIG_ENV_DEFAULT, EnvConfig.getEnvironment()); // when env not set - System.clearProperty(EnvConfigUtils.CONFIG_ENV_KEY); + System.clearProperty(EnvConfigKey.CONFIG_ENV.getProperty()); Assertions.assertEquals(EnvConfigUtils.CONFIG_ENV_DEFAULT, EnvConfig.getEnvironment()); } @Test void testCanGetEnvironment() { - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, TEST_ENVIRONMENT); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), TEST_ENVIRONMENT); Assertions.assertEquals(TEST_ENVIRONMENT, EnvConfig.getEnvironment()); } @Test void testCanGetEnvironmentWhenMultiple() { - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, "default , test"); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), "default , test"); Assertions.assertEquals(TEST_ENVIRONMENT, EnvConfig.getEnvironment()); } @Test void testExceptionWhenEnvMissing() { - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, "default, non-existing "); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), "default, non-existing "); final EnvConfigException exception = Assertions.assertThrows(EnvConfigException.class, EnvConfig::getEnvironment); Assertions.assertTrue(exception.getMessage() @@ -69,14 +69,14 @@ void testExceptionWhenEnvMissing() { @Test void testCanGetEnvironmentWithASpace() { - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, TEST_ENVIRONMENT + " "); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), TEST_ENVIRONMENT + " "); Assertions.assertEquals(TEST_ENVIRONMENT, EnvConfig.getEnvironment()); } @Test void testThrowsExceptionWhenNoPropertiesInEnv() { // given env is default and empty-profile exists in env properties - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, "empty-env"); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), "empty-env"); // then an exception is thrown final EnvConfigException exception = Assertions.assertThrows(EnvConfigException.class, () -> EnvConfig.getOrThrow("non.existing")); @@ -86,13 +86,13 @@ void testThrowsExceptionWhenNoPropertiesInEnv() { @Test void testCanGetProperty() { - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, TEST_ENVIRONMENT); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), TEST_ENVIRONMENT); Assertions.assertEquals("test", EnvConfig.get("property.one")); } @Test void testCanGetPropertyUsingBothFormats() { - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, TEST_ENVIRONMENT); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), TEST_ENVIRONMENT); // when PROPERTY_SEVEN exists in test environment // then should be able to get key using both properties and env var formats @@ -102,20 +102,20 @@ void testCanGetPropertyUsingBothFormats() { @Test void testCanGetPropertyFromGetOrThrow() { - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, TEST_ENVIRONMENT); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), TEST_ENVIRONMENT); Assertions.assertEquals("test", EnvConfig.getOrThrow("property.one")); } @Test void testDoesNotGetsPropertyFromSubDirs() { - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, EnvConfigUtils.CONFIG_ENV_DEFAULT); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), EnvConfigUtils.CONFIG_ENV_DEFAULT); Assertions.assertNull(EnvConfig.get("property.sub.dir")); } @Test void testCanGetPropertyWhenMultipleEnv() { final String testEnv = "test-env"; - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, "test," + testEnv); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), "test," + testEnv); Assertions.assertEquals(testEnv, EnvConfig.getEnvironment()); // When a property.one exists in all environments, including default Assertions.assertEquals(testEnv, EnvConfig.get("property.one")); @@ -131,7 +131,7 @@ void testCanGetPropertyWhenMultipleEnv() { void testCanGetEntryWhenEnvVarAndDefaultValueDifferent() { environmentVariables.set("property.five", "env.default"); final String testEnv = "test-env"; - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, "test," + testEnv); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), "test," + testEnv); // when property.five is set as env variable // and does not exist in test-env // and exists in test env @@ -144,7 +144,7 @@ void testCanGetEntryWhenEnvVarAndDefaultValueDifferent() { void testCanGetEntryWhenEnvVarSet() { environmentVariables.set("property.six", "env.property.six"); final String testEnv = "test-env"; - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, "test," + testEnv); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), "test," + testEnv); // when property.six is set as env variable // and exists in test-env env // and exists in test env @@ -168,7 +168,7 @@ void testCanGetEntryWhenEnvVarAndPropertySet() { @Test void testCanGetEntryWhenEnvVarSetInMultiEnvs() { final String testEnv = "test-env"; - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, "test," + testEnv); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), "test," + testEnv); // when property.seven is not set in test-env // and exists in test env in environment variable format. i.e. PROPERTY_SEVEN=test // and exists in default env with different value i.e. PROPERTY_SEVEN=default @@ -178,7 +178,7 @@ void testCanGetEntryWhenEnvVarSetInMultiEnvs() { @Test void testCanGetPropertyFromEnvVars() { - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, TEST_ENVIRONMENT); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), TEST_ENVIRONMENT); environmentVariables.set("MY_ENV_PROPERTY", "my_env_value"); Assertions.assertEquals("my_env_value", EnvConfig.get("my.env.property")); Assertions.assertEquals("my_env_value", EnvConfig.get("MY_ENV_PROPERTY")); @@ -204,7 +204,7 @@ void testCanGetParsedBoolean() { @Test void testCanGetParsedList() { - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, TEST_ENVIRONMENT); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), TEST_ENVIRONMENT); Assertions.assertTrue(EnvConfig.getList(TEST_PROPERTY).isEmpty()); System.setProperty(TEST_PROPERTY, "env"); Assertions.assertEquals(1, EnvConfig.getList(TEST_PROPERTY).size()); @@ -231,7 +231,7 @@ void testCanGetParsedListWithDelimiter() { @Test void testCanGetDefaultForNonExistingProperty() { - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, TEST_ENVIRONMENT); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), TEST_ENVIRONMENT); Assertions.assertEquals("test", EnvConfig.get("non.existing", "test")); } @@ -242,7 +242,7 @@ void testCanGetEnvVarUsingPropertyKey() { @Test void testNullForNonExistingProperty() { - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, TEST_ENVIRONMENT); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), TEST_ENVIRONMENT); Assertions.assertNull(EnvConfig.get("non.existing")); } @@ -287,27 +287,27 @@ void testCanClearProperty() { @Test void testCanGetEntryFromKeepassWhenFileNameSpecified() { - System.setProperty(EnvConfigUtils.CONFIG_KEEPASS_FILENAME_KEY, "env-config.kdbx"); + System.setProperty(EnvConfigKey.CONFIG_KEEPASS_FILENAME.getProperty(), "env-config.kdbx"); setKeepassEnabled(); Assertions.assertEquals(KEEPASS_VALUE, EnvConfig.get(PROPERTY_KEEPASS)); } private void setKeepassEnabled() { - System.setProperty(EnvConfigUtils.CONFIG_KEEPASS_ENABLED_KEY, "true"); - System.setProperty(EnvConfigUtils.CONFIG_KEEPASS_MASTERKEY_KEY, CONFIG_KEEPASS_PASSWORD); - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, EnvConfigUtils.CONFIG_ENV_DEFAULT); + System.setProperty(EnvConfigKey.CONFIG_KEEPASS_ENABLED.getProperty(), "true"); + System.setProperty(EnvConfigKey.CONFIG_KEEPASS_MASTERKEY.getProperty(), CONFIG_KEEPASS_PASSWORD); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), EnvConfigUtils.CONFIG_ENV_DEFAULT); } @Test void testCanGetFromKeepassWhenFileNameWithSpace() { - System.setProperty(EnvConfigUtils.CONFIG_KEEPASS_FILENAME_KEY, "env config.kdbx"); + System.setProperty(EnvConfigKey.CONFIG_KEEPASS_FILENAME.getProperty(), "env config.kdbx"); setKeepassEnabled(); Assertions.assertEquals(KEEPASS_VALUE, EnvConfig.get(PROPERTY_KEEPASS)); } @Test void testExceptionWhenKeepassFileMissing() { - System.setProperty(EnvConfigUtils.CONFIG_KEEPASS_FILENAME_KEY, "non-existing"); + System.setProperty(EnvConfigKey.CONFIG_KEEPASS_FILENAME.getProperty(), "non-existing"); final EnvConfigException exception = Assertions.assertThrows(EnvConfigException.class, this::testCanGetEntryFromKeepassDefaultGroup); Assertions.assertEquals("Database non-existing.kdbx does not exist!", exception.getMessage()); @@ -315,7 +315,7 @@ void testExceptionWhenKeepassFileMissing() { @Test void testExceptionWhenKeepassMasterKeyMissing() { - System.setProperty(EnvConfigUtils.CONFIG_KEEPASS_ENABLED_KEY, "true"); + System.setProperty(EnvConfigKey.CONFIG_KEEPASS_ENABLED.getProperty(), "true"); final EnvConfigException exception = Assertions.assertThrows(EnvConfigException.class, () -> EnvConfig.get(PROPERTY_KEEPASS)); Assertions.assertEquals(String.format("Missing required variable '%s'", "env.config.keepass.masterkey"), @@ -333,10 +333,10 @@ void testCanGetEntryFromKeepassDefaultGroup() { @Test void testCanGetPropertyFromKeepassWhenMultipleEnv() { - environmentVariables.set(EnvConfigUtils.CONFIG_KEEPASS_ENABLED_KEY.replace(".", "_").toUpperCase(), "true"); - environmentVariables.set(EnvConfigUtils.CONFIG_KEEPASS_MASTERKEY_KEY.replace(".", "_").toUpperCase(), CONFIG_KEEPASS_PASSWORD); + environmentVariables.set(EnvConfigKey.CONFIG_KEEPASS_ENABLED.getEnvProperty(), "true"); + environmentVariables.set(EnvConfigKey.CONFIG_KEEPASS_MASTERKEY.getEnvProperty(), CONFIG_KEEPASS_PASSWORD); final String testEnv = "test-no-keepass"; - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, "keepass," + testEnv); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), "keepass," + testEnv); Assertions.assertEquals(testEnv, EnvConfig.getEnvironment()); // When property.keepass exists in Keepass 'keepass' group // And property.keepass exists in 'keepass' environment files @@ -346,9 +346,9 @@ void testCanGetPropertyFromKeepassWhenMultipleEnv() { @Test void testCanGetEntryFromKeepassDB() { - System.setProperty(EnvConfigUtils.CONFIG_KEEPASS_ENABLED_KEY, "true"); - System.setProperty(EnvConfigUtils.CONFIG_KEEPASS_MASTERKEY_KEY, CONFIG_KEEPASS_PASSWORD); - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, TEST_ENVIRONMENT); + System.setProperty(EnvConfigKey.CONFIG_KEEPASS_ENABLED.getProperty(), "true"); + System.setProperty(EnvConfigKey.CONFIG_KEEPASS_MASTERKEY.getProperty(), CONFIG_KEEPASS_PASSWORD); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), TEST_ENVIRONMENT); // when property.keepass exists in test env // and only exists in default group of keepass // then keepass takes priority @@ -358,9 +358,9 @@ void testCanGetEntryFromKeepassDB() { @Test void testCanGetEntryFromKeepassDisabled() { - System.setProperty(EnvConfigUtils.CONFIG_KEEPASS_ENABLED_KEY, "false"); - System.setProperty(EnvConfigUtils.CONFIG_KEEPASS_MASTERKEY_KEY, CONFIG_KEEPASS_PASSWORD); - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, TEST_ENVIRONMENT); + System.setProperty(EnvConfigKey.CONFIG_KEEPASS_ENABLED.getProperty(), "false"); + System.setProperty(EnvConfigKey.CONFIG_KEEPASS_MASTERKEY.getProperty(), CONFIG_KEEPASS_PASSWORD); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), TEST_ENVIRONMENT); // when property.keepass exists in test env // and only exists in default group of keepass // then keepass takes priority @@ -369,9 +369,9 @@ void testCanGetEntryFromKeepassDisabled() { @Test void testCanGetKeepassOnlyEntry() { - environmentVariables.set(EnvConfigUtils.CONFIG_KEEPASS_ENABLED_KEY.replace(".", "_").toUpperCase(), "true"); - environmentVariables.set(EnvConfigUtils.CONFIG_KEEPASS_MASTERKEY_KEY.replace(".", "_").toUpperCase(), CONFIG_KEEPASS_PASSWORD); - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, TEST_ENVIRONMENT); + environmentVariables.set(EnvConfigKey.CONFIG_KEEPASS_ENABLED.getEnvProperty(), "true"); + environmentVariables.set(EnvConfigKey.CONFIG_KEEPASS_MASTERKEY.getEnvProperty(), CONFIG_KEEPASS_PASSWORD); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), TEST_ENVIRONMENT); // when another.property does not exist in test env // and exists in test group of keepass Assertions.assertEquals("ANOTHER_PROPERTY", EnvConfig.get("another.property")); @@ -379,9 +379,9 @@ void testCanGetKeepassOnlyEntry() { @Test void testCanGetKeepassOnlyEntryWhenEntryWithTrailingSpace() { - environmentVariables.set(EnvConfigUtils.CONFIG_KEEPASS_ENABLED_KEY.replace(".", "_").toUpperCase(), "true"); - environmentVariables.set(EnvConfigUtils.CONFIG_KEEPASS_MASTERKEY_KEY.replace(".", "_").toUpperCase(), CONFIG_KEEPASS_PASSWORD); - System.setProperty(EnvConfigUtils.CONFIG_ENV_KEY, TEST_ENVIRONMENT); + environmentVariables.set(EnvConfigKey.CONFIG_KEEPASS_ENABLED.getEnvProperty(), "true"); + environmentVariables.set(EnvConfigKey.CONFIG_KEEPASS_MASTERKEY.getEnvProperty(), CONFIG_KEEPASS_PASSWORD); + System.setProperty(EnvConfigKey.CONFIG_ENV.getProperty(), TEST_ENVIRONMENT); // when another.property does not exist in test env // and exists in test group of keepass Assertions.assertEquals(KEEPASS_VALUE, EnvConfig.get("trailing.space.property")); diff --git a/src/test/java/com/github/sitture/envconfig/EnvConfigVaultTest.java b/src/test/java/com/github/sitture/envconfig/EnvConfigVaultTest.java index 4be3d23..803f3dc 100644 --- a/src/test/java/com/github/sitture/envconfig/EnvConfigVaultTest.java +++ b/src/test/java/com/github/sitture/envconfig/EnvConfigVaultTest.java @@ -47,7 +47,7 @@ void testSystemVariablesTakesPriorityOverVault() { // and property is set as environment variable environmentVariables.set(EnvConfigUtils.getProcessedEnvKey(key), SYS_ENV_VALUE); // and property is set in environment file - setEnvironment("test"); + setEnvironment(); // then value from system property and environment variable takes priority Assertions.assertEquals(SYS_PROPERTY_VALUE, EnvConfig.get(key)); Assertions.assertEquals(SYS_ENV_VALUE, EnvConfig.get(EnvConfigUtils.getProcessedEnvKey(key))); @@ -58,59 +58,58 @@ void testVaultTakesPriorityOverFiles() { final String key = "property.one"; // given property exists in default config files // when vault loading is enabled - // and default setVaultEnabled(); // setup wiremock stubs for vault stubSelfLookupSuccess(); stubGetSecretSuccess(); // then property from vault group takes priority - Assertions.assertEquals("VAULT_VALUE", EnvConfig.get(key)); - Assertions.assertEquals("VAULT_VALUE", EnvConfig.get(EnvConfigUtils.getProcessedEnvKey(key))); + Assertions.assertEquals("VAULT_PROJECT_DEFAULT", EnvConfig.get(key)); + Assertions.assertEquals("VAULT_PROJECT_DEFAULT", EnvConfig.get(EnvConfigUtils.getProcessedEnvKey(key))); } @Test - void testProjectVaultTakesPriorityOverVaultDefaultSecret() { + void testProjectVaultTakesPriorityOverVaultDefaultPath() { final String key = "property.one"; // given property exists in default config files // when vault loading is enabled setVaultEnabled(); // and default secret path is set - systemProperties.set(EnvConfigUtils.CONFIG_VAULT_DEFAULT_PATH_KEY, "path/to/common"); + systemProperties.set(EnvConfigKey.CONFIG_VAULT_DEFAULT_PATH.getProperty(), "path/to/common"); // setup wiremock stubs for vault stubSelfLookupSuccess(); stubGetSecretSuccess(); stubGetCommonSecretSuccess(); // and property exists in both secret path and default path // then property from secret path takes priority - Assertions.assertEquals("VAULT_VALUE", EnvConfig.get(key)); - Assertions.assertEquals("VAULT_VALUE", EnvConfig.get(EnvConfigUtils.getProcessedEnvKey(key))); + Assertions.assertEquals("VAULT_PROJECT_DEFAULT", EnvConfig.get(key)); + Assertions.assertEquals("VAULT_PROJECT_DEFAULT", EnvConfig.get(EnvConfigUtils.getProcessedEnvKey(key))); } @Test - void testVaultDefaultSecretTakesPriorityOverFiles() { + void testVaultDefaultPathTakesPriorityOverFiles() { final String key = "property.two"; // given property exists in default config files // when vault loading is enabled setVaultEnabled(); // and default secret path is set - systemProperties.set(EnvConfigUtils.CONFIG_VAULT_DEFAULT_PATH_KEY, "path/to/common"); + systemProperties.set(EnvConfigKey.CONFIG_VAULT_DEFAULT_PATH.getProperty(), "path/to/common"); // setup wiremock stubs for vault stubSelfLookupSuccess(); stubGetSecretSuccess(); stubGetCommonSecretSuccess(); // and property exists only in default path // then property from default path takes priority - Assertions.assertEquals("VAULT_DEFAULT_VALUE", EnvConfig.get(key)); - Assertions.assertEquals("VAULT_DEFAULT_VALUE", EnvConfig.get(EnvConfigUtils.getProcessedEnvKey(key))); + Assertions.assertEquals("VAULT_COMMON_DEFAULT", EnvConfig.get(key)); + Assertions.assertEquals("VAULT_COMMON_DEFAULT", EnvConfig.get(EnvConfigUtils.getProcessedEnvKey(key))); } @Test - void testVaultDefaultSecretTakesPriorityOverFiles2() { + void testVaultPrecedenceWhenBothPathAndDefaultPathAreSet() { setVaultEnabled(); // Given default secret path is set - systemProperties.set(EnvConfigUtils.CONFIG_VAULT_DEFAULT_PATH_KEY, "path/to/common"); + systemProperties.set(EnvConfigKey.CONFIG_VAULT_DEFAULT_PATH.getProperty(), "path/to/common"); // And environment is set to test - setEnvironment("test"); + setEnvironment(); // setup wiremock stubs for vault stubSelfLookupSuccess(); // project/default @@ -171,24 +170,24 @@ void testVaultDefaultSecretTakesPriorityOverFiles2() { } private void setVaultEnabled() { - systemProperties.set(EnvConfigUtils.CONFIG_VAULT_ENABLED_KEY, true); - systemProperties.set(EnvConfigUtils.CONFIG_VAULT_ADDRESS_KEY, "http://localhost:8999"); - systemProperties.set(EnvConfigUtils.CONFIG_VAULT_NAMESPACE_KEY, "mock"); - systemProperties.set(EnvConfigUtils.CONFIG_VAULT_SECRET_PATH_KEY, "path/to/project"); - systemProperties.set(EnvConfigUtils.CONFIG_VAULT_TOKEN_KEY, "mock"); + systemProperties.set(EnvConfigKey.CONFIG_VAULT_ENABLED.getProperty(), true); + systemProperties.set(EnvConfigKey.CONFIG_VAULT_ADDRESS.getProperty(), "http://localhost:8999"); + systemProperties.set(EnvConfigKey.CONFIG_VAULT_NAMESPACE.getProperty(), "mock"); + systemProperties.set(EnvConfigKey.CONFIG_VAULT_SECRET_PATH.getProperty(), "path/to/project"); + systemProperties.set(EnvConfigKey.CONFIG_VAULT_TOKEN.getProperty(), "mock"); } - private void setEnvironment(final String environment) { - systemProperties.set(EnvConfigUtils.CONFIG_ENV_KEY, environment); + private void setEnvironment() { + systemProperties.set(EnvConfigKey.CONFIG_ENV.getProperty(), "test"); } private void stubGetSecretSuccess() { stubFor(get("/v1/path/data/to/project/default").willReturn(okJson("{\n" + " \"data\": {\n" + " \"data\": {\n" - + " \"property.eight\": \"VAULT_VALUE\",\n" - + " \"property.one\": \"VAULT_VALUE\",\n" - + " \"PROPERTY_ONE\": \"VAULT_VALUE\"\n" + + " \"property.eight\": \"VAULT_PROJECT_DEFAULT\",\n" + + " \"property.one\": \"VAULT_PROJECT_DEFAULT\",\n" + + " \"PROPERTY_ONE\": \"VAULT_PROJECT_DEFAULT\"\n" + " }\n" + " }\n" + "}\n"))); @@ -198,10 +197,10 @@ private void stubGetCommonSecretSuccess() { stubFor(get("/v1/path/data/to/common/default").willReturn(okJson("{\n" + " \"data\": {\n" + " \"data\": {\n" - + " \"property.one\": \"VAULT_DEFAULT_VALUE\",\n" - + " \"PROPERTY_ONE\": \"VAULT_DEFAULT_VALUE\",\n" - + " \"property.two\": \"VAULT_DEFAULT_VALUE\",\n" - + " \"PROPERTY_TWO\": \"VAULT_DEFAULT_VALUE\"\n" + + " \"property.one\": \"VAULT_COMMON_DEFAULT\",\n" + + " \"PROPERTY_ONE\": \"VAULT_COMMON_DEFAULT\",\n" + + " \"property.two\": \"VAULT_COMMON_DEFAULT\",\n" + + " \"PROPERTY_TWO\": \"VAULT_COMMON_DEFAULT\"\n" + " }\n" + " }\n" + "}\n")));