diff --git a/spring-cloud-config-server/pom.xml b/spring-cloud-config-server/pom.xml
index 525c40ee..6bd17d25 100644
--- a/spring-cloud-config-server/pom.xml
+++ b/spring-cloud-config-server/pom.xml
@@ -206,6 +206,18 @@
micrometer-tracing-bridge-brave
test
+
+ org.testcontainers
+ localstack
+ test
+
+
+
+ com.amazonaws
+ aws-java-sdk-core
+ 1.12.287
+ test
+
io.zipkin.brave
brave-tests
diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AWSParameterStoreEnvironmentRepositoryUnitTest.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AWSParameterStoreEnvironmentRepositoryUnitTest.java
new file mode 100644
index 00000000..25048425
--- /dev/null
+++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AWSParameterStoreEnvironmentRepositoryUnitTest.java
@@ -0,0 +1,205 @@
+/*
+ * Copyright 2013-2020 the original author or authors.
+ *
+ * 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
+ *
+ * https://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.
+ */
+
+package org.springframework.cloud.config.server.environment;
+
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
+import java.util.stream.Collector;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.RandomUtils;
+import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.ssm.SsmClient;
+import software.amazon.awssdk.services.ssm.model.GetParametersByPathRequest;
+import software.amazon.awssdk.services.ssm.model.GetParametersByPathResponse;
+import software.amazon.awssdk.services.ssm.model.Parameter;
+import software.amazon.awssdk.services.ssm.model.ParameterType;
+
+import org.springframework.cloud.config.environment.Environment;
+import org.springframework.cloud.config.environment.PropertySource;
+import org.springframework.cloud.config.server.config.ConfigServerProperties;
+import org.springframework.util.StringUtils;
+
+import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.springframework.cloud.config.server.environment.AwsParameterStoreEnvironmentProperties.DEFAULT_PATH_SEPARATOR;
+
+/**
+ * Unit test is must for testing paginated logic, since doing it with integration test is not that easy.
+ *
+ * @author Iulian Antohe
+ */
+public class AWSParameterStoreEnvironmentRepositoryUnitTest {
+
+ private static final Map SHARED_PROPERTIES = new HashMap() {
+ {
+ put("logging.level.root", "warn");
+ put("spring.cache.redis.time-to-live", "0");
+ }
+ };
+ private static final Map SHARED_DEFAULT_PROPERTIES = new HashMap() {
+ {
+ put("logging.level.root", "error");
+ put("spring.cache.redis.time-to-live", "1000");
+ }
+ };
+ private final SsmClient ssmClient = mock(SsmClient.class, "aws-ssm-client-mock");
+ private final ConfigServerProperties configServerProperties = new ConfigServerProperties();
+ private final AwsParameterStoreEnvironmentProperties environmentProperties = new AwsParameterStoreEnvironmentProperties();
+ private final AwsParameterStoreEnvironmentRepository repository = new AwsParameterStoreEnvironmentRepository(
+ ssmClient, configServerProperties, environmentProperties);
+
+ @Test
+ public void testFindOneWithPaginatedAwsSsmClientResponse() {
+ // Arrange
+ String application = configServerProperties.getDefaultApplicationName();
+ String profile = configServerProperties.getDefaultProfile();
+ String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
+
+ environmentProperties.setMaxResults(1);
+
+ String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/";
+ PropertySource sharedDefaultParamsPs = new PropertySource(
+ sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
+
+ String sharedParamsPsName = "aws:ssm:parameter:/config/application/";
+ PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName,
+ SHARED_PROPERTIES);
+
+ Environment expected = new Environment(application, profiles, null, null, null);
+ expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs));
+
+ setupAwsSsmClientMocks(expected, false, true);
+
+ // Act
+ Environment result = repository.findOne(application, profile, null);
+
+ // Assert
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
+ }
+
+ private void setupAwsSsmClientMocks(Environment environment,
+ boolean withSlashesForPropertyName, boolean paginatedResponse) {
+ for (PropertySource ps : environment.getPropertySources()) {
+ String path = StringUtils.delete(ps.getName(),
+ environmentProperties.getOrigin());
+
+ GetParametersByPathRequest request = GetParametersByPathRequest.builder()
+ .path(path).recursive(environmentProperties.isRecursive())
+ .withDecryption(environmentProperties.isDecryptValues())
+ .maxResults(environmentProperties.getMaxResults()).build();
+
+ Set parameters = getParameters(ps, path,
+ withSlashesForPropertyName);
+
+ GetParametersByPathResponse response = GetParametersByPathResponse.builder()
+ .parameters(parameters).build();
+
+ if (paginatedResponse
+ && environmentProperties.getMaxResults() < parameters.size()) {
+ List> chunks = splitParametersIntoChunks(parameters);
+
+ String nextToken = null;
+
+ for (int i = 0; i < chunks.size(); i++) {
+ Set chunk = chunks.get(i);
+
+ if (i == 0) {
+ nextToken = generateNextToken();
+
+ GetParametersByPathResponse responseClone = response.toBuilder()
+ .parameters(chunk).nextToken(nextToken).build();
+
+ when(ssmClient.getParametersByPath(eq(request)))
+ .thenReturn(responseClone);
+ }
+ else if (i == chunks.size() - 1) {
+ GetParametersByPathRequest requestClone = request.toBuilder()
+ .nextToken(nextToken).build();
+ GetParametersByPathResponse responseClone = response.toBuilder()
+ .parameters(chunk).build();
+
+ when(ssmClient.getParametersByPath(eq(requestClone)))
+ .thenReturn(responseClone);
+ }
+ else {
+ String newNextToken = generateNextToken();
+
+ GetParametersByPathRequest requestClone = request.toBuilder()
+ .nextToken(nextToken).build();
+
+ GetParametersByPathResponse responseClone = response.toBuilder()
+ .parameters(chunk).nextToken(newNextToken).build();
+
+ when(ssmClient.getParametersByPath(eq(requestClone)))
+ .thenReturn(responseClone);
+
+ nextToken = newNextToken;
+ }
+ }
+ }
+ else {
+ when(ssmClient.getParametersByPath(eq(request))).thenReturn(response);
+ }
+ }
+ }
+
+ private Set getParameters(PropertySource propertySource, String path,
+ boolean withSlashesForPropertyName) {
+ Function, Parameter> mapper = p -> Parameter.builder()
+ .name(path + (withSlashesForPropertyName
+ ? ((String) p.getKey()).replace(".", DEFAULT_PATH_SEPARATOR)
+ : p.getKey()))
+ .type(ParameterType.STRING).value((String) p.getValue()).version(1L)
+ .build();
+
+ return propertySource.getSource().entrySet().stream().map(mapper)
+ .collect(Collectors.toSet());
+ }
+
+ private List> splitParametersIntoChunks(Set parameters) {
+ AtomicInteger counter = new AtomicInteger();
+
+ Collector>> collector = Collectors
+ .groupingBy(
+ p -> counter.getAndIncrement()
+ / environmentProperties.getMaxResults(),
+ Collectors.toSet());
+
+ return new ArrayList<>(parameters.stream().collect(collector).values());
+ }
+
+ private String generateNextToken() {
+ String random = randomAlphabetic(RandomUtils.nextInt(3, 33));
+
+ return Base64.getEncoder()
+ .encodeToString(random.getBytes(StandardCharsets.UTF_8));
+ }
+
+}
diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java
index 8da36580..7618bd6e 100644
--- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java
+++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java
@@ -16,26 +16,31 @@
package org.springframework.cloud.config.server.environment;
-import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
-import java.util.stream.Collector;
import java.util.stream.Collectors;
import org.apache.commons.lang3.RandomUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.containers.localstack.LocalStackContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.utility.DockerImageName;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
+import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.ssm.SsmClient;
-import software.amazon.awssdk.services.ssm.model.GetParametersByPathRequest;
-import software.amazon.awssdk.services.ssm.model.GetParametersByPathResponse;
+import software.amazon.awssdk.services.ssm.model.DeleteParameterRequest;
import software.amazon.awssdk.services.ssm.model.Parameter;
import software.amazon.awssdk.services.ssm.model.ParameterType;
+import software.amazon.awssdk.services.ssm.model.PutParameterRequest;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
@@ -45,70 +50,47 @@ import org.springframework.util.StringUtils;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import static org.springframework.cloud.config.server.environment.AwsParameterStoreEnvironmentProperties.DEFAULT_PATH_SEPARATOR;
+import static org.testcontainers.containers.localstack.LocalStackContainer.Service.SSM;
/**
* @author Iulian Antohe
+ * @author Matej Nedic
*/
+@Testcontainers
+@Tag("DockerRequired")
public class AwsParameterStoreEnvironmentRepositoryTests {
- private static final Map SHARED_PROPERTIES = new HashMap() {
- {
- put("logging.level.root", "warn");
- put("spring.cache.redis.time-to-live", "0");
- }
- };
+ @Container
+ private static final LocalStackContainer localstack = new LocalStackContainer(
+ DockerImageName.parse("localstack/localstack:0.14.2")).withServices(SSM);
- private static final Map SHARED_DEFAULT_PROPERTIES = new HashMap() {
- {
- put("logging.level.root", "error");
- put("spring.cache.redis.time-to-live", "1000");
- }
- };
+ private final StaticCredentialsProvider staticCredentialsProvider = StaticCredentialsProvider
+ .create(AwsBasicCredentials.create(localstack.getAccessKey(),
+ localstack.getSecretKey()));
- private static final Map SHARED_PRODUCTION_PROPERTIES = new HashMap() {
- {
- put("logging.level.root", "fatal");
- put("spring.cache.redis.time-to-live", "5000");
- }
- };
-
- private static final Map APPLICATION_SPECIFIC_PROPERTIES = new HashMap() {
- {
- put("logging.level.com.example.service", "trace");
- put("spring.cache.redis.time-to-live", "30000");
- }
- };
-
- private static final Map APPLICATION_SPECIFIC_DEFAULT_PROPERTIES = new HashMap() {
- {
- put("logging.level.com.example.service", "debug");
- put("spring.cache.redis.time-to-live", "60000");
- }
- };
-
- private static final Map APPLICATION_SPECIFIC_PRODUCTION_PROPERTIES = new HashMap() {
- {
- put("logging.level.com.example.service", "info");
- put("spring.cache.redis.time-to-live", "300000");
- }
- };
-
- private final SsmClient awsSsmClientMock = mock(SsmClient.class, "aws-ssm-client-mock");
+ private final SsmClient ssmClient = SsmClient.builder()
+ .region(Region.of(localstack.getRegion()))
+ .credentialsProvider(staticCredentialsProvider)
+ .endpointOverride(localstack.getEndpointOverride(SSM)).build();
private final ConfigServerProperties configServerProperties = new ConfigServerProperties();
private final AwsParameterStoreEnvironmentProperties environmentProperties = new AwsParameterStoreEnvironmentProperties();
private final AwsParameterStoreEnvironmentRepository repository = new AwsParameterStoreEnvironmentRepository(
- awsSsmClientMock, configServerProperties, environmentProperties);
+ ssmClient, configServerProperties, environmentProperties);
+
+ private final List toBeRemoved = new ArrayList<>();
+
+ @AfterEach
+ public void cleanUp() {
+ toBeRemoved.forEach(value -> ssmClient
+ .deleteParameter(DeleteParameterRequest.builder().name(value).build()));
+ toBeRemoved.clear();
+ }
@Test
- @SuppressWarnings("ConstantConditions")
public void testFindOneWithNullApplicationAndNullProfile() {
// Arrange
String application = null;
@@ -118,25 +100,27 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile);
String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/";
- PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
+ PropertySource sharedDefaultParamsPs = new PropertySource(
+ sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
String sharedParamsPsName = "aws:ssm:parameter:/config/application/";
- PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES);
+ PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName,
+ SHARED_PROPERTIES);
Environment expected = new Environment(defaultApp, profiles, null, null, null);
expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs));
- setupAwsSsmClientMocks(expected);
+ putParameters(expected);
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
- @SuppressWarnings("ConstantConditions")
public void testFindOneWithNullApplicationAndDefaultProfile() {
// Arrange
String application = null;
@@ -145,25 +129,27 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/";
- PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
+ PropertySource sharedDefaultParamsPs = new PropertySource(
+ sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
String sharedParamsPsName = "aws:ssm:parameter:/config/application/";
- PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES);
+ PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName,
+ SHARED_PROPERTIES);
Environment expected = new Environment(defaultApp, profiles, null, null, null);
expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs));
- setupAwsSsmClientMocks(expected);
+ putParameters(expected);
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
- @SuppressWarnings("ConstantConditions")
public void testFindOneWithNullApplicationAndNonExistentProfile() {
// Arrange
String application = null;
@@ -177,17 +163,17 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
Environment expected = new Environment(defaultApp, profiles, null, null, null);
expected.add(ps);
- setupAwsSsmClientMocks(expected);
+ putParameters(expected);
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
- @SuppressWarnings("ConstantConditions")
public void testFindOneWithNullApplicationAndExistentProfile() {
// Arrange
String application = null;
@@ -196,25 +182,27 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String sharedProdParamsPsName = "aws:ssm:parameter:/config/application-production/";
- PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, SHARED_PRODUCTION_PROPERTIES);
+ PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName,
+ SHARED_PRODUCTION_PROPERTIES);
String sharedParamsPsName = "aws:ssm:parameter:/config/application/";
- PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES);
+ PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName,
+ SHARED_PROPERTIES);
Environment expected = new Environment(defaultApp, profiles, null, null, null);
expected.addAll(Arrays.asList(sharedProdParamsPs, sharedParamsPs));
- setupAwsSsmClientMocks(expected);
+ putParameters(expected);
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
- @SuppressWarnings("ConstantConditions")
public void testFindOneWithDefaultApplicationAndNullProfile() {
// Arrange
String application = configServerProperties.getDefaultApplicationName();
@@ -223,21 +211,24 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile);
String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/";
- PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
+ PropertySource sharedDefaultParamsPs = new PropertySource(
+ sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
String sharedParamsPsName = "aws:ssm:parameter:/config/application/";
- PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES);
+ PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName,
+ SHARED_PROPERTIES);
Environment expected = new Environment(application, profiles, null, null, null);
expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs));
- setupAwsSsmClientMocks(expected);
+ putParameters(expected);
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
@@ -248,21 +239,24 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/";
- PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
+ PropertySource sharedDefaultParamsPs = new PropertySource(
+ sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
String sharedParamsPsName = "aws:ssm:parameter:/config/application/";
- PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES);
+ PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName,
+ SHARED_PROPERTIES);
Environment expected = new Environment(application, profiles, null, null, null);
expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs));
- setupAwsSsmClientMocks(expected);
+ putParameters(expected);
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
@@ -278,13 +272,14 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
Environment expected = new Environment(application, profiles, null, null, null);
expected.add(ps);
- setupAwsSsmClientMocks(expected);
+ putParameters(expected);
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
@@ -295,25 +290,27 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String sharedProdParamsPsName = "aws:ssm:parameter:/config/application-production/";
- PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, SHARED_PRODUCTION_PROPERTIES);
+ PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName,
+ SHARED_PRODUCTION_PROPERTIES);
String sharedParamsPsName = "aws:ssm:parameter:/config/application/";
- PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES);
+ PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName,
+ SHARED_PROPERTIES);
Environment expected = new Environment(application, profiles, null, null, null);
expected.addAll(Arrays.asList(sharedProdParamsPs, sharedParamsPs));
- setupAwsSsmClientMocks(expected);
+ putParameters(expected);
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
- @SuppressWarnings("ConstantConditions")
public void testFindOneWithNonExistentApplicationAndNullProfile() {
// Arrange
String application = randomAlphabetic(RandomUtils.nextInt(3, 33));
@@ -322,21 +319,24 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile);
String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/";
- PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
+ PropertySource sharedDefaultParamsPs = new PropertySource(
+ sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
String sharedParamsPsName = "aws:ssm:parameter:/config/application/";
- PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES);
+ PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName,
+ SHARED_PROPERTIES);
Environment expected = new Environment(application, profiles, null, null, null);
expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs));
- setupAwsSsmClientMocks(expected);
+ putParameters(expected);
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
@@ -347,21 +347,24 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/";
- PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
+ PropertySource sharedDefaultParamsPs = new PropertySource(
+ sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
String sharedParamsPsName = "aws:ssm:parameter:/config/application/";
- PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES);
+ PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName,
+ SHARED_PROPERTIES);
Environment expected = new Environment(application, profiles, null, null, null);
expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs));
- setupAwsSsmClientMocks(expected);
+ putParameters(expected);
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
@@ -377,13 +380,14 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
Environment expected = new Environment(application, profiles, null, null, null);
expected.add(ps);
- setupAwsSsmClientMocks(expected);
+ putParameters(expected);
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
@@ -394,25 +398,27 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String sharedProdParamsPsName = "aws:ssm:parameter:/config/application-production/";
- PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, SHARED_PRODUCTION_PROPERTIES);
+ PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName,
+ SHARED_PRODUCTION_PROPERTIES);
String sharedParamsPsName = "aws:ssm:parameter:/config/application/";
- PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES);
+ PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName,
+ SHARED_PROPERTIES);
Environment expected = new Environment(application, profiles, null, null, null);
expected.addAll(Arrays.asList(sharedProdParamsPs, sharedParamsPs));
- setupAwsSsmClientMocks(expected);
+ putParameters(expected);
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
- @SuppressWarnings("ConstantConditions")
public void testFindOneWithExistentApplicationAndNullProfile() {
// Arrange
String application = "service";
@@ -421,31 +427,34 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile);
String appSpecificDefaultParamsPsName = "aws:ssm:parameter:/config/service-default/";
- PropertySource appSpecificDefaultParamsPs = new PropertySource(appSpecificDefaultParamsPsName,
- APPLICATION_SPECIFIC_DEFAULT_PROPERTIES);
+ PropertySource appSpecificDefaultParamsPs = new PropertySource(
+ appSpecificDefaultParamsPsName, APPLICATION_SPECIFIC_DEFAULT_PROPERTIES);
String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/";
- PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
+ PropertySource sharedDefaultParamsPs = new PropertySource(
+ sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
String appSpecificParamsPsName = "aws:ssm:parameter:/config/service/";
PropertySource appSpecificParamsPs = new PropertySource(appSpecificParamsPsName,
APPLICATION_SPECIFIC_PROPERTIES);
String sharedParamsPsName = "aws:ssm:parameter:/config/application/";
- PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES);
+ PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName,
+ SHARED_PROPERTIES);
Environment expected = new Environment(application, profiles, null, null, null);
- expected.addAll(
- Arrays.asList(appSpecificDefaultParamsPs, sharedDefaultParamsPs, appSpecificParamsPs, sharedParamsPs));
+ expected.addAll(Arrays.asList(appSpecificDefaultParamsPs, sharedDefaultParamsPs,
+ appSpecificParamsPs, sharedParamsPs));
- setupAwsSsmClientMocks(expected);
+ putParameters(expected);
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
@@ -456,31 +465,34 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String appSpecificDefaultParamsPsName = "aws:ssm:parameter:/config/service-default/";
- PropertySource appSpecificDefaultParamsPs = new PropertySource(appSpecificDefaultParamsPsName,
- APPLICATION_SPECIFIC_DEFAULT_PROPERTIES);
+ PropertySource appSpecificDefaultParamsPs = new PropertySource(
+ appSpecificDefaultParamsPsName, APPLICATION_SPECIFIC_DEFAULT_PROPERTIES);
String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/";
- PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
+ PropertySource sharedDefaultParamsPs = new PropertySource(
+ sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
String appSpecificParamsPsName = "aws:ssm:parameter:/config/service/";
PropertySource appSpecificParamsPs = new PropertySource(appSpecificParamsPsName,
APPLICATION_SPECIFIC_PROPERTIES);
String sharedParamsPsName = "aws:ssm:parameter:/config/application/";
- PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES);
+ PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName,
+ SHARED_PROPERTIES);
Environment expected = new Environment(application, profiles, null, null, null);
- expected.addAll(
- Arrays.asList(appSpecificDefaultParamsPs, sharedDefaultParamsPs, appSpecificParamsPs, sharedParamsPs));
+ expected.addAll(Arrays.asList(appSpecificDefaultParamsPs, sharedDefaultParamsPs,
+ appSpecificParamsPs, sharedParamsPs));
- setupAwsSsmClientMocks(expected);
+ putParameters(expected);
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
@@ -495,18 +507,20 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
APPLICATION_SPECIFIC_PROPERTIES);
String sharedParamsPsName = "aws:ssm:parameter:/config/application/";
- PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES);
+ PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName,
+ SHARED_PROPERTIES);
Environment expected = new Environment(application, profiles, null, null, null);
expected.addAll(Arrays.asList(appSpecificParamsPs, sharedParamsPs));
- setupAwsSsmClientMocks(expected);
+ putParameters(expected);
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
@@ -517,31 +531,34 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String appSpecificProdParamsPsName = "aws:ssm:parameter:/config/service-production/";
- PropertySource appSpecificProdParamsPs = new PropertySource(appSpecificProdParamsPsName,
- APPLICATION_SPECIFIC_PRODUCTION_PROPERTIES);
+ PropertySource appSpecificProdParamsPs = new PropertySource(
+ appSpecificProdParamsPsName, APPLICATION_SPECIFIC_PRODUCTION_PROPERTIES);
String sharedProdParamsPsName = "aws:ssm:parameter:/config/application-production/";
- PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, SHARED_PRODUCTION_PROPERTIES);
+ PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName,
+ SHARED_PRODUCTION_PROPERTIES);
String appSpecificParamsPsName = "aws:ssm:parameter:/config/service/";
PropertySource appSpecificParamsPs = new PropertySource(appSpecificParamsPsName,
APPLICATION_SPECIFIC_PROPERTIES);
String sharedParamsPsName = "aws:ssm:parameter:/config/application/";
- PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES);
+ PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName,
+ SHARED_PROPERTIES);
Environment expected = new Environment(application, profiles, null, null, null);
- expected.addAll(
- Arrays.asList(appSpecificProdParamsPs, sharedProdParamsPs, appSpecificParamsPs, sharedParamsPs));
+ expected.addAll(Arrays.asList(appSpecificProdParamsPs, sharedProdParamsPs,
+ appSpecificParamsPs, sharedParamsPs));
- setupAwsSsmClientMocks(expected);
+ putParameters(expected);
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
@@ -552,38 +569,43 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String appSpecificProdParamsPsName = "aws:ssm:parameter:/config/service-production/";
- PropertySource appSpecificProdParamsPs = new PropertySource(appSpecificProdParamsPsName,
- APPLICATION_SPECIFIC_PRODUCTION_PROPERTIES);
+ PropertySource appSpecificProdParamsPs = new PropertySource(
+ appSpecificProdParamsPsName, APPLICATION_SPECIFIC_PRODUCTION_PROPERTIES);
String sharedProdParamsPsName = "aws:ssm:parameter:/config/application-production/";
- PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, SHARED_PRODUCTION_PROPERTIES);
+ PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName,
+ SHARED_PRODUCTION_PROPERTIES);
String appSpecificDefaultParamsPsName = "aws:ssm:parameter:/config/service-default/";
- PropertySource appSpecificDefaultParamsPs = new PropertySource(appSpecificDefaultParamsPsName,
- APPLICATION_SPECIFIC_DEFAULT_PROPERTIES);
+ PropertySource appSpecificDefaultParamsPs = new PropertySource(
+ appSpecificDefaultParamsPsName, APPLICATION_SPECIFIC_DEFAULT_PROPERTIES);
String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/";
- PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
+ PropertySource sharedDefaultParamsPs = new PropertySource(
+ sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
String appSpecificParamsPsName = "aws:ssm:parameter:/config/service/";
PropertySource appSpecificParamsPs = new PropertySource(appSpecificParamsPsName,
APPLICATION_SPECIFIC_PROPERTIES);
String sharedParamsPsName = "aws:ssm:parameter:/config/application/";
- PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES);
+ PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName,
+ SHARED_PROPERTIES);
Environment expected = new Environment(application, profiles, null, null, null);
- expected.addAll(Arrays.asList(appSpecificProdParamsPs, sharedProdParamsPs, appSpecificDefaultParamsPs,
- sharedDefaultParamsPs, appSpecificParamsPs, sharedParamsPs));
+ expected.addAll(Arrays.asList(appSpecificProdParamsPs, sharedProdParamsPs,
+ appSpecificDefaultParamsPs, sharedDefaultParamsPs, appSpecificParamsPs,
+ sharedParamsPs));
- setupAwsSsmClientMocks(expected);
+ putParameters(expected);
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
@@ -606,22 +628,26 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
PropertySource overridesPs = new PropertySource("overrides", overrides);
String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/";
- PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
+ PropertySource sharedDefaultParamsPs = new PropertySource(
+ sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
String sharedParamsPsName = "aws:ssm:parameter:/config/application/";
- PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES);
+ PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName,
+ SHARED_PROPERTIES);
Environment expected = new Environment(application, profiles, null, null, null);
- expected.addAll(Arrays.asList(overridesPs, sharedDefaultParamsPs, sharedParamsPs));
+ expected.addAll(
+ Arrays.asList(overridesPs, sharedDefaultParamsPs, sharedParamsPs));
- setupAwsSsmClientMocks(expected);
+ putParameters(expected);
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
@@ -632,48 +658,24 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/";
- PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
+ PropertySource sharedDefaultParamsPs = new PropertySource(
+ sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
String sharedParamsPsName = "aws:ssm:parameter:/config/application/";
- PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES);
+ PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName,
+ SHARED_PROPERTIES);
Environment expected = new Environment(application, profiles, null, null, null);
expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs));
- setupAwsSsmClientMocks(expected, true, false);
+ putParameters(expected, true);
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
- }
-
- @Test
- public void testFindOneWithPaginatedAwsSsmClientResponse() {
- // Arrange
- String application = configServerProperties.getDefaultApplicationName();
- String profile = configServerProperties.getDefaultProfile();
- String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
-
- environmentProperties.setMaxResults(1);
-
- String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/";
- PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES);
-
- String sharedParamsPsName = "aws:ssm:parameter:/config/application/";
- PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES);
-
- Environment expected = new Environment(application, profiles, null, null, null);
- expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs));
-
- setupAwsSsmClientMocks(expected, false, true);
-
- // Act
- Environment result = repository.findOne(application, profile, null);
-
- // Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
@@ -685,14 +687,12 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
Environment expected = new Environment(application, profiles, null, null, null);
- when(awsSsmClientMock.getParametersByPath(any(GetParametersByPathRequest.class)))
- .thenReturn(GetParametersByPathResponse.builder().build());
-
// Act
Environment result = repository.findOne(application, profile, null);
// Assert
- assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
+ assertThat(result).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(expected);
}
@Test
@@ -716,89 +716,36 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
assertThat(repository).isNotNull();
}
- private void setupAwsSsmClientMocks(Environment environment) {
- setupAwsSsmClientMocks(environment, false, false);
+ private void putParameters(Environment environment) {
+ putParameters(environment, false);
}
- private void setupAwsSsmClientMocks(Environment environment, boolean withSlashesForPropertyName,
- boolean paginatedResponse) {
+ private void putParameters(Environment environment,
+ boolean withSlashesForPropertyName) {
for (PropertySource ps : environment.getPropertySources()) {
- String path = StringUtils.delete(ps.getName(), environmentProperties.getOrigin());
-
- GetParametersByPathRequest request = GetParametersByPathRequest.builder().path(path)
- .recursive(environmentProperties.isRecursive())
- .withDecryption(environmentProperties.isDecryptValues())
- .maxResults(environmentProperties.getMaxResults()).build();
-
- Set parameters = getParameters(ps, path, withSlashesForPropertyName);
-
- GetParametersByPathResponse response = GetParametersByPathResponse.builder().parameters(parameters).build();
-
- if (paginatedResponse && environmentProperties.getMaxResults() < parameters.size()) {
- List> chunks = splitParametersIntoChunks(parameters);
-
- String nextToken = null;
-
- for (int i = 0; i < chunks.size(); i++) {
- Set chunk = chunks.get(i);
-
- if (i == 0) {
- nextToken = generateNextToken();
-
- GetParametersByPathResponse responseClone = response.toBuilder().parameters(chunk)
- .nextToken(nextToken).build();
-
- when(awsSsmClientMock.getParametersByPath(eq(request))).thenReturn(responseClone);
- }
- else if (i == chunks.size() - 1) {
- GetParametersByPathRequest requestClone = request.toBuilder().nextToken(nextToken).build();
- GetParametersByPathResponse responseClone = response.toBuilder().parameters(chunk).build();
-
- when(awsSsmClientMock.getParametersByPath(eq(requestClone))).thenReturn(responseClone);
- }
- else {
- String newNextToken = generateNextToken();
-
- GetParametersByPathRequest requestClone = request.toBuilder().nextToken(nextToken).build();
-
- GetParametersByPathResponse responseClone = response.toBuilder().parameters(chunk)
- .nextToken(newNextToken).build();
-
- when(awsSsmClientMock.getParametersByPath(eq(requestClone))).thenReturn(responseClone);
-
- nextToken = newNextToken;
- }
- }
- }
- else {
- when(awsSsmClientMock.getParametersByPath(eq(request))).thenReturn(response);
- }
+ String path = StringUtils.delete(ps.getName(),
+ environmentProperties.getOrigin());
+ Set parameters = getParameters(ps, path,
+ withSlashesForPropertyName);
+ parameters.forEach(value -> {
+ ssmClient.putParameter(PutParameterRequest.builder().name(value.name())
+ .dataType("text").value(value.value()).build());
+ toBeRemoved.add(value.name());
+ });
}
}
private Set getParameters(PropertySource propertySource, String path,
boolean withSlashesForPropertyName) {
- Function, Parameter> mapper = p -> Parameter
- .builder().name(path + (withSlashesForPropertyName
- ? ((String) p.getKey()).replace(".", DEFAULT_PATH_SEPARATOR) : p.getKey()))
- .type(ParameterType.STRING).value((String) p.getValue()).version(1L).build();
+ Function, Parameter> mapper = p -> Parameter.builder()
+ .name(path + (withSlashesForPropertyName
+ ? ((String) p.getKey()).replace(".", DEFAULT_PATH_SEPARATOR)
+ : p.getKey()))
+ .type(ParameterType.STRING).value((String) p.getValue()).version(1L)
+ .build();
- return propertySource.getSource().entrySet().stream().map(mapper).collect(Collectors.toSet());
- }
-
- private List> splitParametersIntoChunks(Set parameters) {
- AtomicInteger counter = new AtomicInteger();
-
- Collector>> collector = Collectors
- .groupingBy(p -> counter.getAndIncrement() / environmentProperties.getMaxResults(), Collectors.toSet());
-
- return new ArrayList<>(parameters.stream().collect(collector).values());
- }
-
- private String generateNextToken() {
- String random = randomAlphabetic(RandomUtils.nextInt(3, 33));
-
- return Base64.getEncoder().encodeToString(random.getBytes(StandardCharsets.UTF_8));
+ return propertySource.getSource().entrySet().stream().map(mapper)
+ .collect(Collectors.toSet());
}
@Test
@@ -815,4 +762,45 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
assertThat(actualOrder).isEqualTo(expectedOrder);
}
+ private final Map SHARED_PROPERTIES = new HashMap() {
+ {
+ put("logging.level.root", "warn");
+ put("spring.cache.redis.time-to-live", "0");
+ }
+ };
+
+ private final Map SHARED_DEFAULT_PROPERTIES = new HashMap() {
+ {
+ put("logging.level.root", "error");
+ put("spring.cache.redis.time-to-live", "1000");
+ }
+ };
+
+ private final Map SHARED_PRODUCTION_PROPERTIES = new HashMap() {
+ {
+ put("logging.level.root", "fatal");
+ put("spring.cache.redis.time-to-live", "5000");
+ }
+ };
+
+ private final Map APPLICATION_SPECIFIC_PROPERTIES = new HashMap() {
+ {
+ put("logging.level.com.example.service", "trace");
+ put("spring.cache.redis.time-to-live", "30000");
+ }
+ };
+
+ private final Map APPLICATION_SPECIFIC_DEFAULT_PROPERTIES = new HashMap() {
+ {
+ put("logging.level.com.example.service", "debug");
+ put("spring.cache.redis.time-to-live", "60000");
+ }
+ };
+
+ private final Map APPLICATION_SPECIFIC_PRODUCTION_PROPERTIES = new HashMap() {
+ {
+ put("logging.level.com.example.service", "info");
+ put("spring.cache.redis.time-to-live", "300000");
+ }
+ };
}
diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java
index 4d8cbba4..a9b8c321 100644
--- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java
+++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java
@@ -17,58 +17,80 @@
package org.springframework.cloud.config.server.environment;
import java.io.UnsupportedEncodingException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Properties;
-import org.junit.Test;
-import org.mockito.ArgumentMatcher;
-import software.amazon.awssdk.core.ResponseInputStream;
-import software.amazon.awssdk.http.AbortableInputStream;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.containers.localstack.LocalStackContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.utility.DockerImageName;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
+import software.amazon.awssdk.core.sync.RequestBody;
+import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
-import software.amazon.awssdk.services.s3.model.GetObjectRequest;
-import software.amazon.awssdk.services.s3.model.GetObjectResponse;
-import software.amazon.awssdk.utils.StringInputStream;
+import software.amazon.awssdk.services.s3.model.BucketVersioningStatus;
+import software.amazon.awssdk.services.s3.model.CreateBucketRequest;
+import software.amazon.awssdk.services.s3.model.DeleteObjectRequest;
+import software.amazon.awssdk.services.s3.model.PutBucketVersioningRequest;
+import software.amazon.awssdk.services.s3.model.PutObjectRequest;
+import software.amazon.awssdk.services.s3.model.VersioningConfiguration;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
import org.springframework.cloud.config.server.config.ConfigServerProperties;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.argThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import static org.testcontainers.containers.localstack.LocalStackContainer.Service.S3;
/**
* @author Clay McCoy
+ * @author Matej Nedić
*/
+@Testcontainers
+@Tag("DockerRequired")
public class AwsS3EnvironmentRepositoryTests {
- final ConfigServerProperties server = new ConfigServerProperties();
+ @Container
+ private static final LocalStackContainer localstack = new LocalStackContainer(
+ DockerImageName.parse("localstack/localstack:0.14.2")).withServices(S3);
- final S3Client s3Client = mock(S3Client.class, "config");
+ private final ConfigServerProperties server = new ConfigServerProperties();
- final EnvironmentRepository envRepo = new AwsS3EnvironmentRepository(s3Client, "bucket1", server);
+ private final StaticCredentialsProvider staticCredentialsProvider = StaticCredentialsProvider
+ .create(AwsBasicCredentials.create(localstack.getAccessKey(),
+ localstack.getSecretKey()));
- final String propertyContent = "cloudfoundry.enabled=true\n" + "cloudfoundry.accounts[0].name=acc1\n"
- + "cloudfoundry.accounts[0].user=user1\n" + "cloudfoundry.accounts[0].password=password1\n"
- + "cloudfoundry.accounts[0].api=api.sys.acc1.cf-app.com\n" + "cloudfoundry.accounts[0].environment=test1\n"
- + "cloudfoundry.accounts[1].name=acc2\n" + "cloudfoundry.accounts[1].user=user2\n"
- + "cloudfoundry.accounts[1].password=password2\n" + "cloudfoundry.accounts[1].api=api.sys.acc2.cf-app.com\n"
- + "cloudfoundry.accounts[1].environment=test2\n";
+ private final S3Client s3Client = S3Client.builder()
+ .region(Region.of(localstack.getRegion()))
+ .credentialsProvider(staticCredentialsProvider)
+ .endpointOverride(localstack.getEndpointOverride(S3)).build();
- final String yamlContent = "cloudfoundry:\n" + " enabled: true\n" + " accounts:\n" + " - name: acc1\n"
- + " user: 'user1'\n" + " password: 'password1'\n" + " api: api.sys.acc1.cf-app.com\n"
- + " environment: test1\n" + " - name: acc2\n" + " user: 'user2'\n"
- + " password: 'password2'\n" + " api: api.sys.acc2.cf-app.com\n" + " environment: test2\n";
+ private final EnvironmentRepository envRepo = new AwsS3EnvironmentRepository(s3Client,
+ "bucket1", server);
- final String jsonContent = "{\n" + " \"cloudfoundry\": {\n" + " \"enabled\": true,\n" + " \"accounts\": [{\n"
- + " \"name\": \"acc1\",\n" + " \"user\": \"user1\",\n" + " \"password\": \"password1\",\n"
- + " \"api\": \"api.sys.acc1.cf-app.com\",\n" + " \"environment\": \"test1\"\n" + " }, {\n"
- + " \"name\": \"acc2\",\n" + " \"user\": \"user2\",\n" + " \"password\": \"password2\",\n"
- + " \"api\": \"api.sys.acc2.cf-app.com\",\n" + " \"environment\": \"test2\"\n" + " }]\n" + " }\n"
- + "}";
+ private final List toBeRemoved = new ArrayList<>();
+
+ final String yamlContent = "cloudfoundry:\n" + " enabled: true\n" + " accounts:\n"
+ + " - name: acc1\n" + " user: 'user1'\n"
+ + " password: 'password1'\n" + " api: api.sys.acc1.cf-app.com\n"
+ + " environment: test1\n" + " - name: acc2\n"
+ + " user: 'user2'\n" + " password: 'password2'\n"
+ + " api: api.sys.acc2.cf-app.com\n" + " environment: test2\n";
+
+ final String jsonContent = "{\n" + " \"cloudfoundry\": {\n" + " \"enabled\": true,\n"
+ + " \"accounts\": [{\n" + " \"name\": \"acc1\",\n"
+ + " \"user\": \"user1\",\n" + " \"password\": \"password1\",\n"
+ + " \"api\": \"api.sys.acc1.cf-app.com\",\n"
+ + " \"environment\": \"test1\"\n" + " }, {\n" + " \"name\": \"acc2\",\n"
+ + " \"user\": \"user2\",\n" + " \"password\": \"password2\",\n"
+ + " \"api\": \"api.sys.acc2.cf-app.com\",\n"
+ + " \"environment\": \"test2\"\n" + " }]\n" + " }\n" + "}";
final Properties expectedProperties = new Properties();
@@ -86,6 +108,28 @@ public class AwsS3EnvironmentRepositoryTests {
expectedProperties.put("cloudfoundry.accounts[1].environment", "test2");
}
+ @BeforeAll
+ public static void createBucket() {
+ StaticCredentialsProvider staticCredentialsProvider = StaticCredentialsProvider
+ .create(AwsBasicCredentials.create(localstack.getAccessKey(),
+ localstack.getSecretKey()));
+ S3Client s3Client = S3Client.builder().region(Region.of(localstack.getRegion()))
+ .credentialsProvider(staticCredentialsProvider)
+ .endpointOverride(localstack.getEndpointOverride(S3)).build();
+ s3Client.createBucket(CreateBucketRequest.builder().bucket("bucket1").build());
+ s3Client.putBucketVersioning(PutBucketVersioningRequest.builder()
+ .bucket("bucket1").versioningConfiguration(VersioningConfiguration
+ .builder().status(BucketVersioningStatus.ENABLED).build())
+ .build());
+ }
+
+ @AfterEach
+ public void cleanUp() {
+ toBeRemoved.forEach(value -> s3Client.deleteObject(
+ DeleteObjectRequest.builder().bucket("bucket1").key(value).build()));
+ toBeRemoved.clear();
+ }
+
@Test
public void failToFindNonexistentObject() {
Environment env = envRepo.findOne("foo", "bar", null);
@@ -94,111 +138,124 @@ public class AwsS3EnvironmentRepositoryTests {
@Test
public void findPropertiesObject() throws UnsupportedEncodingException {
- setupS3("foo-bar.properties", propertyContent);
+ String propertyContent = "cloudfoundry.enabled=true\n"
+ + "cloudfoundry.accounts[0].name=acc1\n"
+ + "cloudfoundry.accounts[0].user=user1\n"
+ + "cloudfoundry.accounts[0].password=password1\n"
+ + "cloudfoundry.accounts[0].api=api.sys.acc1.cf-app.com\n"
+ + "cloudfoundry.accounts[0].environment=test1\n"
+ + "cloudfoundry.accounts[1].name=acc2\n"
+ + "cloudfoundry.accounts[1].user=user2\n"
+ + "cloudfoundry.accounts[1].password=password2\n"
+ + "cloudfoundry.accounts[1].api=api.sys.acc2.cf-app.com\n"
+ + "cloudfoundry.accounts[1].environment=test2\n";
+ String versionId = putFiles("foo-bar.properties", propertyContent);
// Pulling content from a .properties file forces a boolean into a String
expectedProperties.put("cloudfoundry.enabled", "true");
final Environment env = envRepo.findOne("foo", "bar", null);
- assertExpectedEnvironment(env, "foo", null, null, 1, "bar");
+ assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar");
}
@Test
public void findJsonObject() throws UnsupportedEncodingException {
- setupS3("foo-bar.json", jsonContent);
+ String versionId = putFiles("foo-bar.json", jsonContent);
final Environment env = envRepo.findOne("foo", "bar", null);
- assertExpectedEnvironment(env, "foo", null, null, 1, "bar");
+ assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar");
}
@Test
public void findYamlObject() throws UnsupportedEncodingException {
- setupS3("foo-bar.yaml", yamlContent);
+ String versionId = putFiles("foo-bar.yaml", yamlContent);
final Environment env = envRepo.findOne("foo", "bar", null);
- assertExpectedEnvironment(env, "foo", null, null, 1, "bar");
+ assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar");
}
@Test
public void findYmlObject() throws UnsupportedEncodingException {
- setupS3("foo-bar.yml", yamlContent);
+ String versionId = putFiles("foo-bar.yml", yamlContent);
final Environment env = envRepo.findOne("foo", "bar", null);
- assertExpectedEnvironment(env, "foo", null, null, 1, "bar");
+ assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar");
}
@Test
public void findWithDefaultProfile() throws UnsupportedEncodingException {
- setupS3("foo.yml", yamlContent);
+ String versionId = putFiles("foo.yml", yamlContent);
final Environment env = envRepo.findOne("foo", null, null);
- assertExpectedEnvironment(env, "foo", null, null, 1, "default", null);
+ assertExpectedEnvironment(env, "foo", null, versionId, 1, "default", null);
}
@Test
public void findWithDefaultProfileUsingSuffix() throws UnsupportedEncodingException {
- setupS3("foo-default.yml", yamlContent);
+ String versionId = putFiles("foo-default.yml", yamlContent);
final Environment env = envRepo.findOne("foo", null, null);
- assertExpectedEnvironment(env, "foo", null, null, 1, "default", null);
+ assertExpectedEnvironment(env, "foo", null, versionId, 1, "default", null);
}
@Test
public void findWithMultipleProfilesAllFound() throws UnsupportedEncodingException {
- setupS3("foo-profile1.yml", yamlContent);
- setupS3("foo-profile2.yml", jsonContent);
+ putFiles("foo-profile1.yml", yamlContent);
+ String versionId = putFiles("foo-profile2.yml", jsonContent);
final Environment env = envRepo.findOne("foo", "profile1,profile2", null);
- assertExpectedEnvironment(env, "foo", null, null, 2, "profile1", "profile2");
+ assertExpectedEnvironment(env, "foo", null, versionId, 2, "profile1", "profile2");
}
@Test
public void findWithMultipleProfilesOneFound() throws UnsupportedEncodingException {
- setupS3("foo-profile2.yml", jsonContent);
+ String versionId = putFiles("foo-profile2.yml", jsonContent);
final Environment env = envRepo.findOne("foo", "profile1,profile2", null);
- assertExpectedEnvironment(env, "foo", null, null, 1, "profile1", "profile2");
+ assertExpectedEnvironment(env, "foo", null, versionId, 1, "profile1", "profile2");
}
@Test
public void findWithLabel() throws UnsupportedEncodingException {
- setupS3("label1/foo-bar.yml", yamlContent);
+ String versionId = putFiles("label1/foo-bar.yml", yamlContent);
final Environment env = envRepo.findOne("foo", "bar", "label1");
- assertExpectedEnvironment(env, "foo", "label1", null, 1, "bar");
+ assertExpectedEnvironment(env, "foo", "label1", versionId, 1, "bar");
}
@Test
public void findWithVersion() throws UnsupportedEncodingException {
- setupS3("foo-bar.yml", "v1", yamlContent);
+ String versionId = putFiles("foo-bar.yml", yamlContent);
final Environment env = envRepo.findOne("foo", "bar", null);
- assertExpectedEnvironment(env, "foo", null, "v1", 1, "bar");
+ assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar");
}
@Test
- public void findWithMultipleApplicationAllFound() throws UnsupportedEncodingException {
- setupS3("foo-profile1.yml", jsonContent);
- setupS3("bar-profile1.yml", jsonContent);
+ public void findWithMultipleApplicationAllFound()
+ throws UnsupportedEncodingException {
+ putFiles("foo-profile1.yml", jsonContent);
+ String versionId = putFiles("bar-profile1.yml", jsonContent);
final Environment env = envRepo.findOne("foo,bar", "profile1", null);
- assertExpectedEnvironment(env, "foo,bar", null, null, 2, "profile1");
+ assertExpectedEnvironment(env, "foo,bar", null, versionId, 2, "profile1");
}
@Test
public void factoryCustomizable() {
- AwsS3EnvironmentRepositoryFactory factory = new AwsS3EnvironmentRepositoryFactory(new ConfigServerProperties());
+ AwsS3EnvironmentRepositoryFactory factory = new AwsS3EnvironmentRepositoryFactory(
+ new ConfigServerProperties());
AwsS3EnvironmentProperties properties = new AwsS3EnvironmentProperties();
properties.setRegion("us-east-1");
properties.setEndpoint("https://myawsendpoint/");
@@ -206,57 +263,24 @@ public class AwsS3EnvironmentRepositoryTests {
assertThat(repository).isNotNull();
}
- private void setupS3(String fileName, String propertyContent) throws UnsupportedEncodingException {
- setupS3(fileName, null, propertyContent);
+ private String putFiles(String fileName, String propertyContent) {
+ toBeRemoved.add(fileName);
+ return s3Client.putObject(
+ PutObjectRequest.builder().bucket("bucket1").key(fileName).build(),
+ RequestBody.fromString((propertyContent))).versionId();
+
}
- private void setupS3(String fileName, String version, String propertyContent) throws UnsupportedEncodingException {
- final GetObjectRequest request = GetObjectRequest.builder().bucket("bucket1").key(fileName).build();
-
- GetObjectResponse.Builder s3Object = GetObjectResponse.builder();
-
- if (version != null) {
- final Map metadata = new HashMap<>();
- metadata.put("x-amz-version-id", version);
- s3Object.metadata(metadata);
- s3Object.versionId(version);
- }
-
- ResponseInputStream response = new ResponseInputStream(s3Object.build(),
- AbortableInputStream.create(new StringInputStream(propertyContent)));
-
- when(s3Client.getObject(argThat(new GetObjectRequestMatcher(request)))).thenReturn(response);
- }
-
- private void assertExpectedEnvironment(Environment env, String applicationName, String label, String version,
- int propertySourceCount, String... profiles) {
+ private void assertExpectedEnvironment(Environment env, String applicationName,
+ String label, String versionId, int propertySourceCount, String... profiles) {
assertThat(env.getName()).isEqualTo(applicationName);
assertThat(env.getProfiles()).isEqualTo(profiles);
assertThat(env.getLabel()).isEqualTo(label);
- assertThat(env.getVersion()).isEqualTo(version);
+ assertThat(env.getVersion()).isEqualTo(versionId);
assertThat(env.getPropertySources().size()).isEqualTo(propertySourceCount);
for (PropertySource ps : env.getPropertySources()) {
assertThat(ps.getSource()).isEqualTo(expectedProperties);
}
}
- private static class GetObjectRequestMatcher implements ArgumentMatcher {
-
- private final GetObjectRequest expected;
-
- GetObjectRequestMatcher(GetObjectRequest expected) {
- this.expected = expected;
- }
-
- @Override
- public boolean matches(GetObjectRequest actual) {
- if (actual == null) {
- return false;
- }
- return Objects.equals(actual.bucket(), expected.bucket()) && Objects.equals(actual.key(), expected.key())
- && Objects.equals(actual.versionId(), expected.versionId());
- }
-
- }
-
}
diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepositoryTests.java
index 335711c0..e1991544 100644
--- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepositoryTests.java
+++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsSecretsManagerEnvironmentRepositoryTests.java
@@ -16,8 +16,10 @@
package org.springframework.cloud.config.server.environment;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -26,10 +28,19 @@ import com.fasterxml.jackson.databind.SerializationFeature;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
+import org.testcontainers.containers.localstack.LocalStackContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.utility.DockerImageName;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
+import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
-import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest;
-import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse;
+import software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest;
+import software.amazon.awssdk.services.secretsmanager.model.DeleteSecretRequest;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
@@ -38,27 +49,51 @@ import org.springframework.util.StringUtils;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import static org.testcontainers.containers.localstack.LocalStackContainer.Service.SECRETSMANAGER;
/**
* @author Tejas Pandilwar
+ * @author Matej Nedić
*/
+@Testcontainers
+@Tag("DockerRequired")
public class AwsSecretsManagerEnvironmentRepositoryTests {
- private static final Log log = LogFactory.getLog(AwsSecretsManagerEnvironmentRepository.class);
+ @Container
+ private static final LocalStackContainer localstack = new LocalStackContainer(
+ DockerImageName.parse("localstack/localstack:0.14.2"))
+ .withServices(SECRETSMANAGER);
- private final SecretsManagerClient awsSmClientMock = mock(SecretsManagerClient.class, "aws-sm-client-mock");
+ private static final Log log = LogFactory
+ .getLog(AwsSecretsManagerEnvironmentRepository.class);
+
+ private final StaticCredentialsProvider staticCredentialsProvider = StaticCredentialsProvider
+ .create(AwsBasicCredentials.create(localstack.getAccessKey(),
+ localstack.getSecretKey()));
+
+ private final SecretsManagerClient smClient = SecretsManagerClient.builder()
+ .region(Region.of(localstack.getRegion()))
+ .credentialsProvider(staticCredentialsProvider)
+ .endpointOverride(localstack.getEndpointOverride(SECRETSMANAGER)).build();
private final ConfigServerProperties configServerProperties = new ConfigServerProperties();
private final AwsSecretsManagerEnvironmentProperties environmentProperties = new AwsSecretsManagerEnvironmentProperties();
private final AwsSecretsManagerEnvironmentRepository repository = new AwsSecretsManagerEnvironmentRepository(
- awsSmClientMock, configServerProperties, environmentProperties);
+ smClient, configServerProperties, environmentProperties);
- private final ObjectMapper objectMapper = new ObjectMapper().configure(SerializationFeature.INDENT_OUTPUT, true);
+ private final ObjectMapper objectMapper = new ObjectMapper()
+ .configure(SerializationFeature.INDENT_OUTPUT, true);
+
+ private final List toBeRemoved = new ArrayList<>();
+
+ @AfterEach
+ public void cleanUp() {
+ toBeRemoved.forEach(value -> smClient.deleteSecret(DeleteSecretRequest.builder()
+ .secretId(value).forceDeleteWithoutRecovery(true).build()));
+ toBeRemoved.clear();
+ }
@Test
public void testFindOneWithNullApplicationAndNullProfile() {
@@ -69,21 +104,24 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile);
String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
- PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
- getApplicationDefaultProperties());
+ PropertySource applicationDefaultProperties = new PropertySource(
+ applicationDefaultPropertiesName, getApplicationDefaultProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(defaultApplication, profiles, null, null, null);
- expectedEnv.addAll(Arrays.asList(applicationDefaultProperties, applicationProperties));
+ Environment environment = new Environment(defaultApplication, profiles, null,
+ null, null);
+ environment.addAll(
+ Arrays.asList(applicationDefaultProperties, applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -94,21 +132,24 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
- PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
- getApplicationDefaultProperties());
+ PropertySource applicationDefaultProperties = new PropertySource(
+ applicationDefaultPropertiesName, getApplicationDefaultProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(defaultApplication, profiles, null, null, null);
- expectedEnv.addAll(Arrays.asList(applicationDefaultProperties, applicationProperties));
+ Environment environment = new Environment(defaultApplication, profiles, null,
+ null, null);
+ environment.addAll(
+ Arrays.asList(applicationDefaultProperties, applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -119,21 +160,24 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
- PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
- getApplicationDefaultProperties());
+ PropertySource applicationDefaultProperties = new PropertySource(
+ applicationDefaultPropertiesName, getApplicationDefaultProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(defaultApplication, profiles, null, null, null);
- expectedEnv.addAll(Arrays.asList(applicationDefaultProperties, applicationProperties));
+ Environment environment = new Environment(defaultApplication, profiles, null,
+ null, null);
+ environment.addAll(
+ Arrays.asList(applicationDefaultProperties, applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -144,26 +188,28 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String applicationProdPropertiesName = "aws:secrets:/secret/application-prod/";
- PropertySource applicationProdProperties = new PropertySource(applicationProdPropertiesName,
- getApplicationProdProperties());
+ PropertySource applicationProdProperties = new PropertySource(
+ applicationProdPropertiesName, getApplicationProdProperties());
String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
- PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
- getApplicationDefaultProperties());
+ PropertySource applicationDefaultProperties = new PropertySource(
+ applicationDefaultPropertiesName, getApplicationDefaultProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(defaultApplication, profiles, null, null, null);
- expectedEnv
- .addAll(Arrays.asList(applicationProdProperties, applicationDefaultProperties, applicationProperties));
+ Environment environment = new Environment(defaultApplication, profiles, null,
+ null, null);
+ environment.addAll(Arrays.asList(applicationProdProperties,
+ applicationDefaultProperties, applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -174,21 +220,24 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile);
String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
- PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
- getApplicationDefaultProperties());
+ PropertySource applicationDefaultProperties = new PropertySource(
+ applicationDefaultPropertiesName, getApplicationDefaultProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(application, profiles, null, null, null);
- expectedEnv.addAll(Arrays.asList(applicationDefaultProperties, applicationProperties));
+ Environment environment = new Environment(application, profiles, null, null,
+ null);
+ environment.addAll(
+ Arrays.asList(applicationDefaultProperties, applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -198,21 +247,24 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
- PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
- getApplicationDefaultProperties());
+ PropertySource applicationDefaultProperties = new PropertySource(
+ applicationDefaultPropertiesName, getApplicationDefaultProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(application, profiles, null, null, null);
- expectedEnv.addAll(Arrays.asList(applicationDefaultProperties, applicationProperties));
+ Environment environment = new Environment(application, profiles, null, null,
+ null);
+ environment.addAll(
+ Arrays.asList(applicationDefaultProperties, applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -222,21 +274,24 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
- PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
- getApplicationDefaultProperties());
+ PropertySource applicationDefaultProperties = new PropertySource(
+ applicationDefaultPropertiesName, getApplicationDefaultProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(application, profiles, null, null, null);
- expectedEnv.addAll(Arrays.asList(applicationDefaultProperties, applicationProperties));
+ Environment environment = new Environment(application, profiles, null, null,
+ null);
+ environment.addAll(
+ Arrays.asList(applicationDefaultProperties, applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -246,26 +301,28 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String applicationProdPropertiesName = "aws:secrets:/secret/application-prod/";
- PropertySource applicationProdProperties = new PropertySource(applicationProdPropertiesName,
- getApplicationProdProperties());
+ PropertySource applicationProdProperties = new PropertySource(
+ applicationProdPropertiesName, getApplicationProdProperties());
String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
- PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
- getApplicationDefaultProperties());
+ PropertySource applicationDefaultProperties = new PropertySource(
+ applicationDefaultPropertiesName, getApplicationDefaultProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(application, profiles, null, null, null);
- expectedEnv
- .addAll(Arrays.asList(applicationProdProperties, applicationDefaultProperties, applicationProperties));
+ Environment environment = new Environment(application, profiles, null, null,
+ null);
+ environment.addAll(Arrays.asList(applicationProdProperties,
+ applicationDefaultProperties, applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -276,21 +333,24 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile);
String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
- PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
- getApplicationDefaultProperties());
+ PropertySource applicationDefaultProperties = new PropertySource(
+ applicationDefaultPropertiesName, getApplicationDefaultProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(application, profiles, null, null, null);
- expectedEnv.addAll(Arrays.asList(applicationDefaultProperties, applicationProperties));
+ Environment environment = new Environment(application, profiles, null, null,
+ null);
+ environment.addAll(
+ Arrays.asList(applicationDefaultProperties, applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -300,21 +360,24 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
- PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
- getApplicationDefaultProperties());
+ PropertySource applicationDefaultProperties = new PropertySource(
+ applicationDefaultPropertiesName, getApplicationDefaultProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(application, profiles, null, null, null);
- expectedEnv.addAll(Arrays.asList(applicationDefaultProperties, applicationProperties));
+ Environment environment = new Environment(application, profiles, null, null,
+ null);
+ environment.addAll(
+ Arrays.asList(applicationDefaultProperties, applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -324,21 +387,24 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
- PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
- getApplicationDefaultProperties());
+ PropertySource applicationDefaultProperties = new PropertySource(
+ applicationDefaultPropertiesName, getApplicationDefaultProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(application, profiles, null, null, null);
- expectedEnv.addAll(Arrays.asList(applicationDefaultProperties, applicationProperties));
+ Environment environment = new Environment(application, profiles, null, null,
+ null);
+ environment.addAll(
+ Arrays.asList(applicationDefaultProperties, applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -348,26 +414,28 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String applicationProdPropertiesName = "aws:secrets:/secret/application-prod/";
- PropertySource applicationProdProperties = new PropertySource(applicationProdPropertiesName,
- getApplicationProdProperties());
+ PropertySource applicationProdProperties = new PropertySource(
+ applicationProdPropertiesName, getApplicationProdProperties());
String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
- PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
- getApplicationDefaultProperties());
+ PropertySource applicationDefaultProperties = new PropertySource(
+ applicationDefaultPropertiesName, getApplicationDefaultProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(application, profiles, null, null, null);
- expectedEnv
- .addAll(Arrays.asList(applicationProdProperties, applicationDefaultProperties, applicationProperties));
+ Environment environment = new Environment(application, profiles, null, null,
+ null);
+ environment.addAll(Arrays.asList(applicationProdProperties,
+ applicationDefaultProperties, applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -378,28 +446,32 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile);
String fooPropertiesName = "aws:secrets:/secret/foo/";
- PropertySource fooProperties = new PropertySource(fooPropertiesName, getFooProperties());
+ PropertySource fooProperties = new PropertySource(fooPropertiesName,
+ getFooProperties());
String fooDefaultPropertiesName = "aws:secrets:/secret/foo-default/";
- PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName, getFooDefaultProperties());
+ PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName,
+ getFooDefaultProperties());
String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
- PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
- getApplicationDefaultProperties());
+ PropertySource applicationDefaultProperties = new PropertySource(
+ applicationDefaultPropertiesName, getApplicationDefaultProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(application, profiles, null, null, null);
- expectedEnv.addAll(Arrays.asList(fooDefaultProperties, applicationDefaultProperties, fooProperties,
- applicationProperties));
+ Environment environment = new Environment(application, profiles, null, null,
+ null);
+ environment.addAll(Arrays.asList(fooDefaultProperties,
+ applicationDefaultProperties, fooProperties, applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -409,28 +481,32 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String fooPropertiesName = "aws:secrets:/secret/foo/";
- PropertySource fooProperties = new PropertySource(fooPropertiesName, getFooProperties());
+ PropertySource fooProperties = new PropertySource(fooPropertiesName,
+ getFooProperties());
String fooDefaultPropertiesName = "aws:secrets:/secret/foo-default/";
- PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName, getFooDefaultProperties());
+ PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName,
+ getFooDefaultProperties());
String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
- PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
- getApplicationDefaultProperties());
+ PropertySource applicationDefaultProperties = new PropertySource(
+ applicationDefaultPropertiesName, getApplicationDefaultProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(application, profiles, null, null, null);
- expectedEnv.addAll(Arrays.asList(fooDefaultProperties, applicationDefaultProperties, fooProperties,
- applicationProperties));
+ Environment environment = new Environment(application, profiles, null, null,
+ null);
+ environment.addAll(Arrays.asList(fooDefaultProperties,
+ applicationDefaultProperties, fooProperties, applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -440,28 +516,32 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String fooPropertiesName = "aws:secrets:/secret/foo/";
- PropertySource fooProperties = new PropertySource(fooPropertiesName, getFooProperties());
+ PropertySource fooProperties = new PropertySource(fooPropertiesName,
+ getFooProperties());
String fooDefaultPropertiesName = "aws:secrets:/secret/foo-default/";
- PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName, getFooDefaultProperties());
+ PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName,
+ getFooDefaultProperties());
String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
- PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
- getApplicationDefaultProperties());
+ PropertySource applicationDefaultProperties = new PropertySource(
+ applicationDefaultPropertiesName, getApplicationDefaultProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(application, profiles, null, null, null);
- expectedEnv.addAll(Arrays.asList(fooDefaultProperties, applicationDefaultProperties, fooProperties,
- applicationProperties));
+ Environment environment = new Environment(application, profiles, null, null,
+ null);
+ environment.addAll(Arrays.asList(fooDefaultProperties,
+ applicationDefaultProperties, fooProperties, applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -471,20 +551,23 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String fooPropertiesName = "aws:secrets:/secret/foo/";
- PropertySource fooProperties = new PropertySource(fooPropertiesName, getFooProperties());
+ PropertySource fooProperties = new PropertySource(fooPropertiesName,
+ getFooProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(application, profiles, null, null, null);
- expectedEnv.addAll(Arrays.asList(fooProperties, applicationProperties));
+ Environment environment = new Environment(application, profiles, null, null,
+ null);
+ environment.addAll(Arrays.asList(fooProperties, applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -494,24 +577,28 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String fooPropertiesName = "aws:secrets:/secret/foo/";
- PropertySource fooProperties = new PropertySource(fooPropertiesName, getFooProperties());
+ PropertySource fooProperties = new PropertySource(fooPropertiesName,
+ getFooProperties());
String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
- PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
- getApplicationDefaultProperties());
+ PropertySource applicationDefaultProperties = new PropertySource(
+ applicationDefaultPropertiesName, getApplicationDefaultProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(application, profiles, null, null, null);
- expectedEnv.addAll(Arrays.asList(applicationDefaultProperties, fooProperties, applicationProperties));
+ Environment environment = new Environment(application, profiles, null, null,
+ null);
+ environment.addAll(Arrays.asList(applicationDefaultProperties, fooProperties,
+ applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -521,35 +608,41 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String fooProdPropertiesName = "aws:secrets:/secret/foo-prod/";
- PropertySource fooProdProperties = new PropertySource(fooProdPropertiesName, getFooProdProperties());
+ PropertySource fooProdProperties = new PropertySource(fooProdPropertiesName,
+ getFooProdProperties());
String fooPropertiesName = "aws:secrets:/secret/foo/";
- PropertySource fooProperties = new PropertySource(fooPropertiesName, getFooProperties());
+ PropertySource fooProperties = new PropertySource(fooPropertiesName,
+ getFooProperties());
String fooDefaultPropertiesName = "aws:secrets:/secret/foo-default/";
- PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName, getFooDefaultProperties());
+ PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName,
+ getFooDefaultProperties());
String applicationProdPropertiesName = "aws:secrets:/secret/application-prod/";
- PropertySource applicationProdProperties = new PropertySource(applicationProdPropertiesName,
- getApplicationProdProperties());
+ PropertySource applicationProdProperties = new PropertySource(
+ applicationProdPropertiesName, getApplicationProdProperties());
String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
- PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
- getApplicationDefaultProperties());
+ PropertySource applicationDefaultProperties = new PropertySource(
+ applicationDefaultPropertiesName, getApplicationDefaultProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(application, profiles, null, null, null);
- expectedEnv.addAll(Arrays.asList(fooProdProperties, applicationProdProperties, fooDefaultProperties,
- applicationDefaultProperties, fooProperties, applicationProperties));
+ Environment environment = new Environment(application, profiles, null, null,
+ null);
+ environment.addAll(Arrays.asList(fooProdProperties, applicationProdProperties,
+ fooDefaultProperties, applicationDefaultProperties, fooProperties,
+ applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -559,28 +652,32 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String fooProdPropertiesName = "aws:secrets:/secret/foo-prod/";
- PropertySource fooProdProperties = new PropertySource(fooProdPropertiesName, getFooProdProperties());
+ PropertySource fooProdProperties = new PropertySource(fooProdPropertiesName,
+ getFooProdProperties());
String fooPropertiesName = "aws:secrets:/secret/foo/";
- PropertySource fooProperties = new PropertySource(fooPropertiesName, getFooProperties());
+ PropertySource fooProperties = new PropertySource(fooPropertiesName,
+ getFooProperties());
String applicationProdPropertiesName = "aws:secrets:/secret/application-prod/";
- PropertySource applicationProdProperties = new PropertySource(applicationProdPropertiesName,
- getApplicationProdProperties());
+ PropertySource applicationProdProperties = new PropertySource(
+ applicationProdPropertiesName, getApplicationProdProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(application, profiles, null, null, null);
- expectedEnv.addAll(
- Arrays.asList(fooProdProperties, applicationProdProperties, fooProperties, applicationProperties));
+ Environment environment = new Environment(application, profiles, null, null,
+ null);
+ environment.addAll(Arrays.asList(fooProdProperties, applicationProdProperties,
+ fooProperties, applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -590,43 +687,49 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String fooProdPropertiesName = "aws:secrets:/secret/foo-prod/";
- PropertySource fooProdProperties = new PropertySource(fooProdPropertiesName, getFooProdProperties());
+ PropertySource fooProdProperties = new PropertySource(fooProdPropertiesName,
+ getFooProdProperties());
String fooEastPropertiesName = "aws:secrets:/secret/foo-east/";
- PropertySource fooEastProperties = new PropertySource(fooEastPropertiesName, getFooEastProperties());
+ PropertySource fooEastProperties = new PropertySource(fooEastPropertiesName,
+ getFooEastProperties());
String fooPropertiesName = "aws:secrets:/secret/foo/";
- PropertySource fooProperties = new PropertySource(fooPropertiesName, getFooProperties());
+ PropertySource fooProperties = new PropertySource(fooPropertiesName,
+ getFooProperties());
String fooDefaultPropertiesName = "aws:secrets:/secret/foo-default/";
- PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName, getFooDefaultProperties());
+ PropertySource fooDefaultProperties = new PropertySource(fooDefaultPropertiesName,
+ getFooDefaultProperties());
String applicationProdPropertiesName = "aws:secrets:/secret/application-prod/";
- PropertySource applicationProdProperties = new PropertySource(applicationProdPropertiesName,
- getApplicationProdProperties());
+ PropertySource applicationProdProperties = new PropertySource(
+ applicationProdPropertiesName, getApplicationProdProperties());
String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
- PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
- getApplicationDefaultProperties());
+ PropertySource applicationDefaultProperties = new PropertySource(
+ applicationDefaultPropertiesName, getApplicationDefaultProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
String applicationEastPropertiesName = "aws:secrets:/secret/application-east/";
- PropertySource applicationEastProperties = new PropertySource(applicationEastPropertiesName,
- getApplicationEastProperties());
+ PropertySource applicationEastProperties = new PropertySource(
+ applicationEastPropertiesName, getApplicationEastProperties());
- Environment expectedEnv = new Environment(application, profiles, null, null, null);
- expectedEnv.addAll(Arrays.asList(fooProdProperties, applicationProdProperties, fooEastProperties,
- applicationEastProperties, fooDefaultProperties, applicationDefaultProperties, fooProperties,
- applicationProperties));
+ Environment environment = new Environment(application, profiles, null, null,
+ null);
+ environment.addAll(Arrays.asList(fooProdProperties, applicationProdProperties,
+ fooEastProperties, applicationEastProperties, fooDefaultProperties,
+ applicationDefaultProperties, fooProperties, applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -636,35 +739,41 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
String fooProdPropertiesName = "aws:secrets:/secret/foo-prod/";
- PropertySource fooProdProperties = new PropertySource(fooProdPropertiesName, getFooProdProperties());
+ PropertySource fooProdProperties = new PropertySource(fooProdPropertiesName,
+ getFooProdProperties());
String fooEastPropertiesName = "aws:secrets:/secret/foo-east/";
- PropertySource fooEastProperties = new PropertySource(fooEastPropertiesName, getFooEastProperties());
+ PropertySource fooEastProperties = new PropertySource(fooEastPropertiesName,
+ getFooEastProperties());
String fooPropertiesName = "aws:secrets:/secret/foo/";
- PropertySource fooProperties = new PropertySource(fooPropertiesName, getFooProperties());
+ PropertySource fooProperties = new PropertySource(fooPropertiesName,
+ getFooProperties());
String applicationProdPropertiesName = "aws:secrets:/secret/application-prod/";
- PropertySource applicationProdProperties = new PropertySource(applicationProdPropertiesName,
- getApplicationProdProperties());
+ PropertySource applicationProdProperties = new PropertySource(
+ applicationProdPropertiesName, getApplicationProdProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
String applicationEastPropertiesName = "aws:secrets:/secret/application-east/";
- PropertySource applicationEastProperties = new PropertySource(applicationEastPropertiesName,
- getApplicationEastProperties());
+ PropertySource applicationEastProperties = new PropertySource(
+ applicationEastPropertiesName, getApplicationEastProperties());
- Environment expectedEnv = new Environment(application, profiles, null, null, null);
- expectedEnv.addAll(Arrays.asList(fooProdProperties, applicationProdProperties, fooEastProperties,
- applicationEastProperties, fooProperties, applicationProperties));
+ Environment environment = new Environment(application, profiles, null, null,
+ null);
+ environment.addAll(Arrays.asList(fooProdProperties, applicationProdProperties,
+ fooEastProperties, applicationEastProperties, fooProperties,
+ applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -684,21 +793,24 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
PropertySource overrideProperties = new PropertySource("overrides", overrides);
String applicationDefaultPropertiesName = "aws:secrets:/secret/application-default/";
- PropertySource applicationDefaultProperties = new PropertySource(applicationDefaultPropertiesName,
- getApplicationDefaultProperties());
+ PropertySource applicationDefaultProperties = new PropertySource(
+ applicationDefaultPropertiesName, getApplicationDefaultProperties());
String applicationPropertiesName = "aws:secrets:/secret/application/";
- PropertySource applicationProperties = new PropertySource(applicationPropertiesName,
- getApplicationProperties());
+ PropertySource applicationProperties = new PropertySource(
+ applicationPropertiesName, getApplicationProperties());
- Environment expectedEnv = new Environment(application, profiles, null, null, null);
- expectedEnv.addAll(Arrays.asList(overrideProperties, applicationDefaultProperties, applicationProperties));
+ Environment environment = new Environment(application, profiles, null, null,
+ null);
+ environment.addAll(Arrays.asList(overrideProperties, applicationDefaultProperties,
+ applicationProperties));
- setupAwsSmClientMocks(expectedEnv);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -707,12 +819,14 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
String profile = configServerProperties.getDefaultProfile();
String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
- Environment expectedEnv = new Environment(application, profiles, null, null, null);
- setupAwsSmClientMocks(expectedEnv);
+ Environment environment = new Environment(application, profiles, null, null,
+ null);
+ putSecrets(environment);
Environment resultEnv = repository.findOne(application, profile, null);
- assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expectedEnv);
+ assertThat(resultEnv).usingRecursiveComparison().withStrictTypeChecking()
+ .isEqualTo(environment);
}
@Test
@@ -736,15 +850,14 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
assertThat(repository).isNotNull();
}
- private void setupAwsSmClientMocks(Environment environment) {
+ private void putSecrets(Environment environment) {
for (PropertySource ps : environment.getPropertySources()) {
- String path = StringUtils.delete(ps.getName(), environmentProperties.getOrigin());
- GetSecretValueRequest request = GetSecretValueRequest.builder().secretId(path).build();
-
+ String path = StringUtils.delete(ps.getName(),
+ environmentProperties.getOrigin());
String secrets = getSecrets(ps);
- GetSecretValueResponse response = GetSecretValueResponse.builder().secretString(secrets).build();
-
- when(awsSmClientMock.getSecretValue(eq(request))).thenReturn(response);
+ smClient.createSecret(CreateSecretRequest.builder().name(path)
+ .secretString(secrets).build());
+ toBeRemoved.add(path);
}
}