Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reproduce problem with decrypting properties from @PropertySource #29

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enc.application.prop={cipher}411fe0940df2296c4bc01be6477c030161961d1e0d231f1365ed33eab51d5f550aff707b249380c001b058aea074d07e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enc.propertySource.prop={cipher}85f21553dcb4778ef25432df218dc672106e169c970db3c6f996567b9ff4ca3712f0d3b065aa5b44116a1ded0476c05e