Decrypt after config data refresh

Fixes gh-962
Fixes gh-955
This commit is contained in:
Roberto Paolillo
2021-05-19 13:28:22 +02:00
committed by spencergibb
parent fd079e4ec9
commit 938fb861d0
2 changed files with 27 additions and 0 deletions

View File

@@ -23,8 +23,12 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.security.crypto.encrypt.TextEncryptor;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.BDDAssertions.then;
@@ -118,6 +122,24 @@ public class EncryptionIntegrationTests {
then(context.getBean(PasswordProperties.class).getPassword()).isEqualTo("test");
}
@Test
public void decryptAfterRefresh() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestAutoConfiguration.class)
.web(WebApplicationType.NONE)
.properties("encrypt.key:pie",
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95",
"spring.cloud.refresh.enabled:true")
.run();
TextEncryptor encryptor = context.getBean(TextEncryptor.class);
ContextRefresher refresher = context.getBean(ContextRefresher.class);
ConfigurableEnvironment env = context.getBean(ConfigurableEnvironment.class);
then(env.getProperty("foo.password")).isEqualTo("test");
TestPropertyValues.of("foo.password={cipher}" + encryptor.encrypt("newValue")).applyTo(env);
refresher.refresh();
then(env.getProperty("foo.password")).isEqualTo("newValue");
context.close();
}
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(PasswordProperties.class)
protected static class TestConfiguration {