From a1c18bb09d96e6bafd7cfcd34f3dbf53567a9dda Mon Sep 17 00:00:00 2001 From: Marcin Zajaczkowski Date: Fri, 7 Nov 2014 16:18:19 +0100 Subject: [PATCH] Reproduce problem with decrypting properties from @PropertySource --- .../encrypt/EnvironmentDecryptTests.java | 65 +++++++++++++++++++ .../decryptingPropertyTest.properties | 1 + ...ConfigurationWithPropertySource.properties | 1 + 3 files changed, 67 insertions(+) create mode 100644 spring-cloud-config-client/src/test/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptTests.java create mode 100644 spring-cloud-config-client/src/test/resources/decryptingPropertyTest.properties create mode 100644 spring-cloud-config-client/src/test/resources/testConfigurationWithPropertySource.properties diff --git a/spring-cloud-config-client/src/test/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptTests.java b/spring-cloud-config-client/src/test/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptTests.java new file mode 100644 index 000000000..b21ea3d26 --- /dev/null +++ b/spring-cloud-config-client/src/test/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptTests.java @@ -0,0 +1,65 @@ +package org.springframework.cloud.bootstrap.encrypt; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.cloud.autoconfigure.ConfigClientAutoConfiguration; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +import static org.junit.Assert.assertEquals; + +public class EnvironmentDecryptTests { + + private static ConfigurableApplicationContext context; + + @BeforeClass + public static void setupSpec() { + System.setProperty("encrypt.key", "eKey"); + context = new SpringApplicationBuilder(EnvironmentDecryptTestApp.class, TestConfigurationWithPropertySource.class) + .web(false) + .showBanner(false) + .properties("enc.prop:{cipher}f43b8323cd82a74aafa1fba5efdce529274b58f68145903e6cc7e460e07e0e20") + .run("--spring.config.name=decryptingPropertyTest"); + } + + @AfterClass + public static void afterSpec() { + System.getProperties().remove("encrypt.key"); + if (context != null) { + context.close(); + } + } + + @Test + public void shouldDecryptPropertiesFromApplicationPropertiesFile() { + assertEquals("enc.application.prop.value", context.getEnvironment().getProperty("enc.application.prop")); + } + + @Test + public void shouldDecryptPropertiesSetOnEnvironment() { + assertEquals("enc.prop.value", context.getEnvironment().getProperty("enc.prop")); + } + + @Ignore("Currently EnvironmentDecryptApplicationListener is run to early") + @Test + public void shouldDecryptPropertiesAddedWithPropertySourceAnnotation() { + assertEquals("enc.propertySource.prop.value", context.getEnvironment().getProperty("enc.propertySource.prop")); + } +} + +@Configuration +@EnableAutoConfiguration +@ComponentScan(basePackageClasses = ConfigClientAutoConfiguration.class) +class EnvironmentDecryptTestApp { +} + +@Configuration +@PropertySource("testConfigurationWithPropertySource.properties") +class TestConfigurationWithPropertySource { +} diff --git a/spring-cloud-config-client/src/test/resources/decryptingPropertyTest.properties b/spring-cloud-config-client/src/test/resources/decryptingPropertyTest.properties new file mode 100644 index 000000000..80e5664a0 --- /dev/null +++ b/spring-cloud-config-client/src/test/resources/decryptingPropertyTest.properties @@ -0,0 +1 @@ +enc.application.prop={cipher}411fe0940df2296c4bc01be6477c030161961d1e0d231f1365ed33eab51d5f550aff707b249380c001b058aea074d07e \ No newline at end of file diff --git a/spring-cloud-config-client/src/test/resources/testConfigurationWithPropertySource.properties b/spring-cloud-config-client/src/test/resources/testConfigurationWithPropertySource.properties new file mode 100644 index 000000000..0130267ab --- /dev/null +++ b/spring-cloud-config-client/src/test/resources/testConfigurationWithPropertySource.properties @@ -0,0 +1 @@ +enc.propertySource.prop={cipher}85f21553dcb4778ef25432df218dc672106e169c970db3c6f996567b9ff4ca3712f0d3b065aa5b44116a1ded0476c05e \ No newline at end of file