diff --git a/micro-infra-spring-property/build.gradle b/micro-infra-spring-property/build.gradle index dd661d8f..1ab62335 100644 --- a/micro-infra-spring-property/build.gradle +++ b/micro-infra-spring-property/build.gradle @@ -12,7 +12,7 @@ dependencies { compile("org.springframework.cloud:spring-cloud-config-server:$springCloudVersion") { exclude group: 'ch.qos.logback', module: 'logback-classic' } - compile "org.springframework.security:spring-security-rsa:1.0.0.M2" + compile "org.springframework.security:spring-security-rsa:1.0.0.M2" //Not needed when AES is used? compile "org.eclipse.jgit:org.eclipse.jgit:2.3.1.201302201838-r" compile "org.codehaus.groovy:groovy-all:$groovyVersion" compile "org.aspectj:aspectjrt:1.8.3" diff --git a/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/DecryptingPropertyExtendedTest.groovy b/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/DecryptingPropertyExtendedTest.groovy deleted file mode 100644 index 339f6ad3..00000000 --- a/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/DecryptingPropertyExtendedTest.groovy +++ /dev/null @@ -1,36 +0,0 @@ -package com.ofg.infrastructure.property - -import org.springframework.boot.builder.SpringApplicationBuilder -import spock.lang.Ignore - -class DecryptingPropertyExtendedTest extends AbstractIntegrationTest { - - def "should fail when encryption key is not provided and there are encrypted passwords"() { - given: - System.setProperty("encrypt.key", "wrongKey") - when: - def context = new SpringApplicationBuilder(DecryptingPropertyTestApp) - .web(false) - .showBanner(false) - .properties("enc:{cipher}bb3336c80dffc7a6d13faea47cf1920cf391a03319249d8a6e38c289d1de7232") - .run() - then: - thrown(IllegalStateException) - cleanup: - context?.close() - } - - @Ignore("Currently fails with NoSuchBeanDefinitionException: TextEncryptor") - def "should not fail when encryption key is not provided and there are no encrypted passwords"() { - when: - def context = new SpringApplicationBuilder(DecryptingPropertyTestApp) - .web(false) - .showBanner(false) - .properties("normal.prop=normal.prop.value") - .run() - then: - context.environment.getProperty("normal.prop") == "normal.prop.value" - cleanup: - context?.close() - } -} diff --git a/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/DecryptingPropertyTest.groovy b/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/DecryptingPropertyTest.groovy deleted file mode 100644 index de4f0707..00000000 --- a/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/DecryptingPropertyTest.groovy +++ /dev/null @@ -1,49 +0,0 @@ -package com.ofg.infrastructure.property - -import org.springframework.boot.builder.SpringApplicationBuilder -import org.springframework.context.ConfigurableApplicationContext -import org.springframework.context.annotation.Configuration -import org.springframework.context.annotation.PropertySource -import spock.lang.Ignore -import spock.lang.Shared - -class DecryptingPropertyTest extends AbstractIntegrationTest { - - @Shared - private ConfigurableApplicationContext context - - def setupSpec() { - System.setProperty("encrypt.key", "eKey") //To simulate setting environment variable - context = new SpringApplicationBuilder(DecryptingPropertyTestApp, TestConfigurationWithPropertySource) - .web(false) - .showBanner(false) - .properties("enc.prop:{cipher}f43b8323cd82a74aafa1fba5efdce529274b58f68145903e6cc7e460e07e0e20") - .run("--spring.config.name=decryptingPropertyTest") - } - - def cleanupSpec() { - System.properties.remove("encrypt.key") //TODO: Replace with @RestoreSystemProperties from Spock 1.0, when available... - context?.close() - } - - def "should decrypt properties from application.properties"() { - expect: - context.environment.getProperty("enc.application.prop") == "enc.application.prop.value" - } - - def "should decrypt properties from set properties"() { - expect: - context.environment.getProperty("enc.prop") == "enc.prop.value" - } - - @Ignore("Currently EnvironmentDecryptApplicationListener is run too early") - def "should decrypt properties added with @PropertySource"() { - expect: - context.environment.getProperty("enc.propertySource.prop") == "enc.propertySource.prop.value" - } -} - -@Configuration -@PropertySource("testConfigurationWithPropertySource.properties") -class TestConfigurationWithPropertySource { -} diff --git a/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/DecryptingPropertyTestApp.groovy b/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/DecryptingPropertyTestApp.groovy index d94170e9..c9affe12 100644 --- a/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/DecryptingPropertyTestApp.groovy +++ b/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/DecryptingPropertyTestApp.groovy @@ -1,11 +1,10 @@ package com.ofg.infrastructure.property -import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.cloud.autoconfigure.ConfigClientAutoConfiguration import org.springframework.context.annotation.ComponentScan import org.springframework.context.annotation.Configuration @Configuration -@EnableAutoConfiguration -@ComponentScan(basePackages = ['org.springframework.cloud.autoconfigure']) +@ComponentScan(basePackageClasses = [ConfigClientAutoConfiguration.class]) class DecryptingPropertyTestApp { } diff --git a/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/LoadingFromFileSystemTest.groovy b/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/LoadingFromFileSystemTest.groovy index 94df57ca..54d33175 100644 --- a/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/LoadingFromFileSystemTest.groovy +++ b/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/LoadingFromFileSystemTest.groovy @@ -3,6 +3,7 @@ package com.ofg.infrastructure.property import org.springframework.beans.factory.annotation.Value 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.Bean import org.springframework.context.annotation.ComponentScan @@ -75,7 +76,7 @@ class LoadingFromFileSystemTest extends AbstractIntegrationTest { @Configuration @EnableAutoConfiguration -@ComponentScan(basePackages = ['org.springframework.cloud.autoconfigure']) +@ComponentScan(basePackageClasses = [ConfigClientAutoConfiguration.class]) class BasicApp { @Bean diff --git a/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/decrypt/DecryptingPropertyTest.groovy b/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/decrypt/DecryptingPropertyTest.groovy index 6579e9c6..7c25e145 100644 --- a/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/decrypt/DecryptingPropertyTest.groovy +++ b/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/decrypt/DecryptingPropertyTest.groovy @@ -2,10 +2,14 @@ package com.ofg.infrastructure.property.decrypt import com.ofg.infrastructure.property.AbstractIntegrationTest 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 org.springframework.context.annotation.PropertySource +import org.springframework.stereotype.Component import spock.lang.Ignore +import spock.lang.Issue import spock.lang.Shared class DecryptingPropertyTest extends AbstractIntegrationTest { @@ -15,7 +19,7 @@ class DecryptingPropertyTest extends AbstractIntegrationTest { def setupSpec() { System.setProperty("encrypt.key", "eKey") //To simulate setting environment variable - context = new SpringApplicationBuilder(DecryptingPropertyTestApp, TestConfigurationWithPropertySource) + context = new SpringApplicationBuilder(DecryptingPropertyTestApp, TestConfigurationWithPropertySource, ConfigurationPropertiesSettings) .web(false) .showBanner(false) .properties("enc.prop:{cipher}f43b8323cd82a74aafa1fba5efdce529274b58f68145903e6cc7e460e07e0e20") @@ -38,13 +42,27 @@ class DecryptingPropertyTest extends AbstractIntegrationTest { } @Ignore("Currently EnvironmentDecryptApplicationListener is run too early") + @Issue("https://github.com/spring-cloud/spring-cloud-config/issues/30") def "should decrypt properties added with @PropertySource"() { expect: context.environment.getProperty("enc.propertySource.prop") == "enc.propertySource.prop.value" } + + @Ignore("Not supported") + def "should decrypt properties added with @ConfigurationProperties"() { + expect: + context.getBean(ConfigurationPropertiesSettings)?.configurationProperties == "enc.propertySource.prop.value" + } } @Configuration -@PropertySource("testConfigurationWithPropertySource.properties") +@PropertySource("classpath:testConfigurationWithPropertySource.properties") +@EnableConfigurationProperties class TestConfigurationWithPropertySource { } + +@Component +@ConfigurationProperties(locations = "classpath:testConfigurationWithConfigurationProperties.properties", prefix = "enc") +class ConfigurationPropertiesSettings { + String configurationProperties +} diff --git a/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/decrypt/DecryptingPropertyTestApp.groovy b/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/decrypt/DecryptingPropertyTestApp.groovy index 34a8c3ad..da9c2024 100644 --- a/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/decrypt/DecryptingPropertyTestApp.groovy +++ b/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/decrypt/DecryptingPropertyTestApp.groovy @@ -1,11 +1,10 @@ package com.ofg.infrastructure.property.decrypt -import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.cloud.autoconfigure.ConfigClientAutoConfiguration import org.springframework.context.annotation.ComponentScan import org.springframework.context.annotation.Configuration @Configuration -@EnableAutoConfiguration -@ComponentScan(basePackages = ['org.springframework.cloud.autoconfigure']) +@ComponentScan(basePackageClasses = [ConfigClientAutoConfiguration.class]) class DecryptingPropertyTestApp { } diff --git a/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/decrypt/EncryptorTestUtil.groovy b/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/decrypt/EncryptorTestUtil.groovy new file mode 100644 index 00000000..50be6fe5 --- /dev/null +++ b/micro-infra-spring-property/src/test/groovy/com/ofg/infrastructure/property/decrypt/EncryptorTestUtil.groovy @@ -0,0 +1,16 @@ +package com.ofg.infrastructure.property.decrypt + +import org.springframework.boot.builder.SpringApplicationBuilder +import org.springframework.security.crypto.encrypt.TextEncryptor + +class EncryptorTestUtil { + + static void main(String[] args) { + System.setProperty("encrypt.key", "eKey") + System.setProperty("APP_ENV", "prod") + System.setProperty("countryCode", "pl") + def context = new SpringApplicationBuilder(DecryptingPropertyTestApp).web(false).run() + def encryptor = context.getBean(TextEncryptor) + println "Encrypted: ${encryptor.encrypt("value to encrypt")}" + } +} diff --git a/micro-infra-spring-property/src/test/resources/foo.properties b/micro-infra-spring-property/src/test/resources/foo.properties deleted file mode 100644 index ba2a7ce8..00000000 --- a/micro-infra-spring-property/src/test/resources/foo.properties +++ /dev/null @@ -1,2 +0,0 @@ -foo=bar -encKey={cipher}ala \ No newline at end of file diff --git a/micro-infra-spring-property/src/test/resources/testConfigurationWithConfigurationProperties.properties b/micro-infra-spring-property/src/test/resources/testConfigurationWithConfigurationProperties.properties new file mode 100644 index 00000000..48b0f102 --- /dev/null +++ b/micro-infra-spring-property/src/test/resources/testConfigurationWithConfigurationProperties.properties @@ -0,0 +1 @@ +enc.configurationProperties={cipher}7b11e6e32bf28eb1820553c042d9a7302065229c6aa0c159cacd5e47d4f45f15817313409fd2945e628e1c55094cddd45b56a60f60a1f16a1d1f8b7e3ed2b1e9 \ No newline at end of file