Only attempt to decrypt properties that are not overridden (#462)
This commit is contained in:
committed by
Ryan Baxter
parent
4a66435d38
commit
59798f52ed
@@ -30,11 +30,14 @@ 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;
|
||||
|
||||
@@ -161,4 +164,22 @@ 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.<String, Object>singletonMap("foo", "spam")));
|
||||
initializer.initialize(context);
|
||||
assertEquals("spam", context.getEnvironment().getProperty("foo"));
|
||||
assertEquals("bar2", context.getEnvironment().getProperty("foo2"));
|
||||
verify(encryptor).decrypt("bar2");
|
||||
verifyNoMoreInteractions(encryptor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user