From 703c7c2bbf8111f5fb747c69e981a5552097e6fb Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Wed, 13 Feb 2019 11:33:06 -0500 Subject: [PATCH 1/4] Ignores MapPropertySources not created by boot Prior to this change, any `MapPropertySource` created by an `EnvironmentPostProcessor` would be processed by `BootstrapApplicationListener`. If that property source had a conditional property that it created itself, the 2nd run (bootstrap causes EPPs to run twice) would not have the property and that property source would end up in the main `Environment` effectively deleting a property. This change only deals with `MapPropertySource`s created by boot testing for a specific sub-type. Fixes gh-476 --- .../BootstrapApplicationListener.java | 5 +- ...ironmentPostProcessorIntegrationTests.java | 80 +++++++++++++++++++ ...ionPropertiesRebinderIntegrationTests.java | 4 +- .../test/resources/META-INF/spring.factories | 4 + 4 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/BootstrapEnvironmentPostProcessorIntegrationTests.java diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/BootstrapApplicationListener.java b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/BootstrapApplicationListener.java index e376a3a9..ce5609e2 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/BootstrapApplicationListener.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/BootstrapApplicationListener.java @@ -35,6 +35,7 @@ import org.springframework.boot.builder.ParentContextApplicationContextInitializ import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; import org.springframework.boot.context.logging.LoggingApplicationListener; +import org.springframework.boot.env.OriginTrackedMapPropertySource; import org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ApplicationListener; @@ -44,7 +45,6 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.Order; import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.core.env.EnumerablePropertySource; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; @@ -447,7 +447,8 @@ public class BootstrapApplicationListener } public void add(PropertySource source) { - if (source instanceof EnumerablePropertySource + // Only add map property sources added by boot, see gh-476 + if (source instanceof OriginTrackedMapPropertySource && !this.names.contains(source.getName())) { this.sources.addPropertySource(source); this.names.add(source.getName()); diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/BootstrapEnvironmentPostProcessorIntegrationTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/BootstrapEnvironmentPostProcessorIntegrationTests.java new file mode 100644 index 00000000..0a8c752e --- /dev/null +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/BootstrapEnvironmentPostProcessorIntegrationTests.java @@ -0,0 +1,80 @@ +/* + * Copyright 2013-2019 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bootstrap; + +import java.util.HashMap; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.SpringBootConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.env.EnvironmentPostProcessor; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +// see https://github.com/spring-cloud/spring-cloud-commons/issues/476 +@RunWith(SpringRunner.class) +@SpringBootTest +public class BootstrapEnvironmentPostProcessorIntegrationTests { + + @Autowired + private ConfigurableEnvironment env; + + @Test + public void conditionalValuesFromMapProperySourceCreatedByEPPExist() { + assertThat(this.env.containsProperty("unconditional.property")) + .as("Environment does not contain unconditional.property") + .isTrue(); + assertThat(this.env.getProperty("unconditional.property")) + .as("Environment has wrong value for unconditional.property") + .isEqualTo("unconditional.value"); + assertThat(this.env.containsProperty("conditional.property")) + .as("Environment does not contain conditional.property") + .isTrue(); + assertThat(this.env.getProperty("conditional.property")) + .as("Environment has wrong value for conditional.property") + .isEqualTo("conditional.value"); + } + + @EnableAutoConfiguration + @SpringBootConfiguration + protected static class TestConfig { + } + + public static class TestConditionalEnvironmentPostProcessor implements EnvironmentPostProcessor { + @Override + public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { + HashMap map = new HashMap<>(); + + if (!environment.containsProperty("conditional.property")) { + map.put("conditional.property", "conditional.value"); + } + map.put("unconditional.property", "unconditional.value"); + + MapPropertySource propertySource = new MapPropertySource("test-epp-map", map); + environment.getPropertySources().addFirst(propertySource); + } + } + +} diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinderIntegrationTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinderIntegrationTests.java index b5cae4eb..3a867274 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinderIntegrationTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinderIntegrationTests.java @@ -23,6 +23,7 @@ import org.junit.runner.RunWith; import org.springframework.aop.framework.ProxyFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -34,7 +35,6 @@ import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration; import org.springframework.cloud.context.properties.ConfigurationPropertiesRebinderIntegrationTests.TestConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; @@ -110,7 +110,7 @@ public class ConfigurationPropertiesRebinderIntegrationTests { @Configuration @EnableConfigurationProperties - @Import({ RefreshConfiguration.RebinderConfiguration.class, + @ImportAutoConfiguration({ RefreshConfiguration.RebinderConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) protected static class TestConfiguration { diff --git a/spring-cloud-context/src/test/resources/META-INF/spring.factories b/spring-cloud-context/src/test/resources/META-INF/spring.factories index 419787be..8c44cd81 100644 --- a/spring-cloud-context/src/test/resources/META-INF/spring.factories +++ b/spring-cloud-context/src/test/resources/META-INF/spring.factories @@ -2,3 +2,7 @@ org.springframework.cloud.bootstrap.BootstrapConfiguration=\ org.springframework.cloud.bootstrap.TestBootstrapConfiguration,\ org.springframework.cloud.bootstrap.TestHigherPriorityBootstrapConfiguration + + +org.springframework.boot.env.EnvironmentPostProcessor=\ +org.springframework.cloud.bootstrap.BootstrapEnvironmentPostProcessorIntegrationTests.TestConditionalEnvironmentPostProcessor \ No newline at end of file From 8c4fe5626e8e68b91b9755f7d768eca22591dc10 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Thu, 14 Feb 2019 17:23:19 +0000 Subject: [PATCH 2/4] Bumping versions --- README.adoc | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 135 insertions(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index 1aa7dfc3..a17b4302 100644 --- a/README.adoc +++ b/README.adoc @@ -113,6 +113,8 @@ from the `file` menu. == Contributing +:spring-cloud-build-branch: master + Spring Cloud is released under the non-restrictive Apache 2.0 license, and follows a very standard Github development process, using Github tracker for issues and merging pull requests into master. If you want @@ -156,4 +158,136 @@ added after the original pull request but before a merge. other target branch in the main project). * When writing a commit message please follow http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html[these conventions], if you are fixing an existing issue please add `Fixes gh-XXXX` at the end of the commit - message (where XXXX is the issue number). \ No newline at end of file + message (where XXXX is the issue number). + +=== Checkstyle + +Spring Cloud Build comes with a set of checkstyle rules. You can find them in the `spring-cloud-build-tools` module. The most notable files under the module are: + +.spring-cloud-build-tools/ +---- +└── src +    ├── checkstyle +    │   └── checkstyle-suppressions.xml <3> +    └── main +    └── resources +    ├── checkstyle-header.txt <2> +    └── checkstyle.xml <1> +---- +<1> Default Checkstyle rules +<2> File header setup +<3> Default suppression rules + +==== Checkstyle configuration + +Checkstyle rules are *disabled by default*. To add checkstyle to your project just define the following properties and plugins. + +.pom.xml +---- + +true <1> + true + <2> + true + <3> + + + + + <4> + io.spring.javaformat + spring-javaformat-maven-plugin + + <5> + org.apache.maven.plugins + maven-checkstyle-plugin + + + + + + <5> + org.apache.maven.plugins + maven-checkstyle-plugin + + + + +---- +<1> Fails the build upon Checkstyle errors +<2> Fails the build upon Checkstyle violations +<3> Checkstyle analyzes also the test sources +<4> Add the Spring Java Format plugin that will reformat your code to pass most of the Checkstyle formatting rules +<5> Add checkstyle plugin to your build and reporting phases + +If you need to suppress some rules (e.g. line length needs to be longer), then it's enough for you to define a file under `${project.root}/src/checkstyle/checkstyle-suppressions.xml` with your suppressions. Example: + +.projectRoot/src/checkstyle/checkstyle-suppresions.xml +---- + + + + + + +---- + +It's advisable to copy the `${spring-cloud-build.rootFolder}/.editorconfig` and `${spring-cloud-build.rootFolder}/.springformat` to your project. That way, some default formatting rules will be applied. You can do so by running this script: + +```bash +$ curl https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/.editorconfig -o .editorconfig +$ touch .springformat +``` + +=== IDE setup + +==== Intellij IDEA + +In order to setup Intellij you should import our coding conventions, inspection profiles and set up the checkstyle plugin. + +.spring-cloud-build-tools/ +---- +└── src +    ├── checkstyle +    │   └── checkstyle-suppressions.xml <3> +    └── main +    └── resources +    ├── checkstyle-header.txt <2> +    ├── checkstyle.xml <1> +    └── intellij +       ├── Intellij_Project_Defaults.xml <4> +       └── Intellij_Spring_Boot_Java_Conventions.xml <5> +---- +<1> Default Checkstyle rules +<2> File header setup +<3> Default suppression rules +<4> Project defaults for Intellij that apply most of Checkstyle rules +<5> Project style conventions for Intellij that apply most of Checkstyle rules + +.Code style + +image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-code-style.png[Code style] + +Go to `File` -> `Settings` -> `Editor` -> `Code style`. There click on the icon next to the `Scheme` section. There, click on the `Import Scheme` value and pick the `Intellij IDEA code style XML` option. Import the `spring-cloud-build-tools/src/main/resources/intellij/Intellij_Spring_Boot_Java_Conventions.xml` file. + +.Inspection profiles + +image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-inspections.png[Code style] + +Go to `File` -> `Settings` -> `Editor` -> `Inspections`. There click on the icon next to the `Profile` section. There, click on the `Import Profile` and import the `spring-cloud-build-tools/src/main/resources/intellij/Intellij_Project_Defaults.xml` file. + +.Checkstyle + +To have Intellij work with Checkstyle, you have to install the `Checkstyle` plugin. It's advisable to also install the `Assertions2Assertj` to automatically convert the JUnit assertions + +image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-checkstyle.png[Checkstyle] + +Go to `File` -> `Settings` -> `Other settings` -> `Checkstyle`. There click on the `+` icon in the `Configuration file` section. There, you'll have to define where the checkstyle rules should be picked from. In the image above, we've picked the rules from the cloned Spring Cloud Build repository. However, you can point to the Spring Cloud Build's GitHub repository (e.g. for the `checkstyle.xml` : `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle.xml`). We need to provide the following variables: + +- `checkstyle.header.file` - please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/main/resources/checkstyle/checkstyle-header.txt` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle-header.txt` URL. +- `checkstyle.suppressions.file` - default suppressions. Please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` URL. +- `checkstyle.additional.suppressions.file` - this variable corresponds to suppressions in your local project. E.g. you're working on `spring-cloud-contract`. Then point to the `project-root/src/checkstyle/checkstyle-suppressions.xml` folder. Example for `spring-cloud-contract` would be: `/home/username/spring-cloud-contract/src/checkstyle/checkstyle-suppressions.xml`. + +IMPORTANT: Remember to set the `Scan Scope` to `All sources` since we apply checkstyle rules for production and test sources. \ No newline at end of file From 5e52806440110851d549e081411f4e3ff21e8883 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Thu, 14 Feb 2019 17:09:28 -0500 Subject: [PATCH 3/4] Revert "Allow overriding encrypted properties with unencrypted properties (#459)" This reverts commit 4a66435d38777eb3ddf92f8248a24eb7213b7bed. --- .../EnvironmentDecryptApplicationInitializer.java | 5 +---- ...EnvironmentDecryptApplicationInitializerTests.java | 11 ----------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializer.java b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializer.java index 17f15aa6..45fd149a 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializer.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializer.java @@ -199,13 +199,10 @@ public class EnvironmentDecryptApplicationInitializer implements } } else if (COLLECTION_PROPERTY.matcher(key).matches()) { - // put non-encrypted properties so merging of index properties + // put non-ecrypted properties so merging of index properties // happens correctly otherCollectionProperties.put(key, value); } - else { - overrides.remove(key); - } } } // copy all indexed properties even if not encrypted diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializerTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializerTests.java index 2e2fd3d7..7e02666c 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializerTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializerTests.java @@ -78,17 +78,6 @@ public class EnvironmentDecryptApplicationInitializerTests { assertEquals("spam", context.getEnvironment().getProperty("foo")); } - @Test - public void propertySourcesOrderedCorrectlyWithUnencryptedOverrides() { - ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); - TestPropertyValues.of("foo: {cipher}bar").applyTo(context); - context.getEnvironment().getPropertySources() - .addFirst(new MapPropertySource("test_override", - Collections.singletonMap("foo", "spam"))); - this.listener.initialize(context); - assertEquals("spam", context.getEnvironment().getProperty("foo")); - } - @Test(expected = IllegalStateException.class) public void errorOnDecrypt() { this.listener = new EnvironmentDecryptApplicationInitializer( From 4413f136aab1bc0144a793502bdc284b530f16b5 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Thu, 14 Feb 2019 17:14:14 -0500 Subject: [PATCH 4/4] Revert "Only attempt to decrypt properties that are not overridden (#462)" This reverts commit 59798f52ed54766099d76f970640093954359d49. --- ...ironmentDecryptApplicationInitializer.java | 65 ++++++++----------- ...entDecryptApplicationInitializerTests.java | 21 ------ 2 files changed, 26 insertions(+), 60 deletions(-) diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializer.java b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializer.java index 45fd149a..af49fdc1 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializer.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializer.java @@ -163,25 +163,21 @@ public class EnvironmentDecryptApplicationInitializer implements sources.add(0, source); } for (PropertySource source : sources) { - collectEncryptedProperties(source, overrides); + decrypt(source, overrides); } - - doDecrypt(overrides); return overrides; } private Map decrypt(PropertySource source) { Map overrides = new LinkedHashMap<>(); - collectEncryptedProperties(source, overrides); - doDecrypt(overrides); + decrypt(source, overrides); return overrides; } private static final Pattern COLLECTION_PROPERTY = Pattern .compile("(\\S+)?\\[(\\d+)\\](\\.\\S+)?"); - private void collectEncryptedProperties(PropertySource source, - Map overrides) { + private void decrypt(PropertySource source, Map overrides) { if (source instanceof EnumerablePropertySource) { Map otherCollectionProperties = new LinkedHashMap<>(); @@ -193,6 +189,28 @@ public class EnvironmentDecryptApplicationInitializer implements if (property != null) { String value = property.toString(); if (value.startsWith("{cipher}")) { + value = value.substring("{cipher}".length()); + try { + value = this.encryptor.decrypt(value); + if (logger.isDebugEnabled()) { + logger.debug("Decrypted: key=" + key); + } + } + catch (Exception e) { + String message = "Cannot decrypt: key=" + key; + if (this.failOnError) { + throw new IllegalStateException(message, e); + } + if (logger.isDebugEnabled()) { + logger.warn(message, e); + } + else { + logger.warn(message); + } + // Set value to empty to avoid making a password out of the + // cipher text + value = ""; + } overrides.put(key, value); if (COLLECTION_PROPERTY.matcher(key).matches()) { sourceHasDecryptedCollection = true; @@ -215,42 +233,11 @@ public class EnvironmentDecryptApplicationInitializer implements for (PropertySource nested : ((CompositePropertySource) source) .getPropertySources()) { - collectEncryptedProperties(nested, overrides); + decrypt(nested, overrides); } } } - private void doDecrypt(Map overrides) { - for (String key : overrides.keySet()) { - String value = overrides.get(key).toString(); - if (value.startsWith("{cipher}")) { - value = value.substring("{cipher}".length()); - try { - value = this.encryptor.decrypt(value); - if (logger.isDebugEnabled()) { - logger.debug("Decrypted: key=" + key); - } - } - catch (Exception e) { - String message = "Cannot decrypt: key=" + key; - if (this.failOnError) { - throw new IllegalStateException(message, e); - } - if (logger.isDebugEnabled()) { - logger.warn(message, e); - } - else { - logger.warn(message); - } - // Set value to empty to avoid making a password out of the - // cipher text - value = ""; - } - overrides.put(key, value); - } - } - } - } diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializerTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializerTests.java index 7e02666c..60889642 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializerTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializerTests.java @@ -30,14 +30,11 @@ import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.security.crypto.encrypt.Encryptors; -import org.springframework.security.crypto.encrypt.TextEncryptor; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import static org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.DECRYPTED_PROPERTY_SOURCE_NAME; @@ -153,22 +150,4 @@ public class EnvironmentDecryptApplicationInitializerTests { assertEquals("value", ctx.getEnvironment().getProperty("key")); } - @Test - public void testOnlyDecryptIfNotOverridden() { - ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); - TextEncryptor encryptor = mock(TextEncryptor.class); - when(encryptor.decrypt("bar2")).thenReturn("bar2"); - EnvironmentDecryptApplicationInitializer initializer = new EnvironmentDecryptApplicationInitializer( - encryptor); - TestPropertyValues.of("foo: {cipher}bar", "foo2: {cipher}bar2").applyTo(context); - context.getEnvironment().getPropertySources() - .addFirst(new MapPropertySource("test_override", - Collections.singletonMap("foo", "spam"))); - initializer.initialize(context); - assertEquals("spam", context.getEnvironment().getProperty("foo")); - assertEquals("bar2", context.getEnvironment().getProperty("foo2")); - verify(encryptor).decrypt("bar2"); - verifyNoMoreInteractions(encryptor); - } - }