Add failing test for decrypting and rebinding

See gh-269
This commit is contained in:
Dave Syer
2017-10-31 08:51:16 +00:00
parent 8f9dfd38e3
commit fb36b67913
4 changed files with 76 additions and 20 deletions

View File

@@ -12,6 +12,16 @@ import static org.junit.Assert.assertEquals;
public class EncryptionBootstrapConfigurationTests {
@Test
public void symmetric() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(
EncryptionBootstrapConfiguration.class).web(WebApplicationType.NONE)
.properties("encrypt.key:pie").run();
TextEncryptor encryptor = context.getBean(TextEncryptor.class);
assertEquals("foo", encryptor.decrypt(encryptor.encrypt("foo")));
context.close();
}
@Test
public void rsaKeyStore() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(
@@ -52,8 +62,8 @@ public class EncryptionBootstrapConfigurationTests {
"encrypt.key-store.alias:mytestkey",
"encrypt.key-store.secret:changeme")
.run();
assertThat(false)
.as("Should not create an application context with invalid keystore location")
assertThat(false).as(
"Should not create an application context with invalid keystore location")
.isTrue();
}
catch (Exception e) {

View File

@@ -0,0 +1,54 @@
package org.springframework.cloud.bootstrap.encrypt;
import org.junit.Test;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import static org.junit.Assert.assertEquals;
public class EncryptionIntegrationTests {
@Test
public void symmetricPropertyValues() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(
TestConfiguration.class).web(WebApplicationType.NONE).properties(
"encrypt.key:pie",
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
.run();
assertEquals("test", context.getEnvironment().getProperty("foo.password"));
}
@Test
public void symmetricConfigurationProperties() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(
TestConfiguration.class).web(WebApplicationType.NONE).properties(
"encrypt.key:pie",
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
.run();
assertEquals("test", context.getBean(PasswordProperties.class).getPassword());
}
@Configuration
@EnableConfigurationProperties(PasswordProperties.class)
protected static class TestConfiguration {
}
@ConfigurationProperties("foo")
protected static class PasswordProperties {
private String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
}