This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#83] New module for properties management
- Loading branch information
Marcin Zajaczkowski
committed
Nov 10, 2014
1 parent
6da3a6d
commit 12b853d
Showing
10 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
description = 'Microservice Spring infrastructure for properties management' | ||
|
||
ext { | ||
//TODO: Switch to 1.0.0.M3 when available | ||
springCloudVersion = "1.0.0.BUILD-SNAPSHOT" | ||
} | ||
|
||
dependencies { | ||
compile("org.springframework.cloud:spring-cloud-config-client:$springCloudVersion") { | ||
exclude group: 'ch.qos.logback', module: 'logback-classic' | ||
} | ||
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.eclipse.jgit:org.eclipse.jgit:2.3.1.201302201838-r" | ||
compile "org.codehaus.groovy:groovy-all:$groovyVersion" | ||
|
||
testCompile("org.spockframework:spock-core:$spockVersion") { | ||
exclude group: 'org.codehaus.groovy', module: 'groovy-all' | ||
} | ||
testRuntime "org.springframework:spring-test:$springTestVersion" | ||
testRuntime "org.spockframework:spock-spring:$spockVersion" | ||
testRuntime "ch.qos.logback:logback-classic:$logbackVersion" | ||
} |
37 changes: 37 additions & 0 deletions
37
...rty/src/test/groovy/com/ofg/infrastructure/property/DecryptingPropertyExtendedTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.ofg.infrastructure.property | ||
|
||
import org.springframework.boot.builder.SpringApplicationBuilder | ||
import spock.lang.Ignore | ||
import spock.lang.Specification | ||
|
||
class DecryptingPropertyExtendedTest extends Specification { | ||
|
||
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() | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...ng-property/src/test/groovy/com/ofg/infrastructure/property/DecryptingPropertyTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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 | ||
import spock.lang.Specification | ||
|
||
class DecryptingPropertyTest extends Specification { | ||
|
||
@Shared | ||
private ConfigurableApplicationContext context | ||
|
||
void 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") | ||
} | ||
|
||
void afterSpec() { | ||
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 { | ||
} |
11 changes: 11 additions & 0 deletions
11
...property/src/test/groovy/com/ofg/infrastructure/property/DecryptingPropertyTestApp.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.ofg.infrastructure.property | ||
|
||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration | ||
import org.springframework.context.annotation.ComponentScan | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
@EnableAutoConfiguration | ||
@ComponentScan(basePackages = ['org.springframework.cloud.autoconfigure']) | ||
class DecryptingPropertyTestApp { | ||
} |
1 change: 1 addition & 0 deletions
1
micro-infra-spring-property/src/test/resources/decryptingPropertyTest.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
enc.application.prop={cipher}411fe0940df2296c4bc01be6477c030161961d1e0d231f1365ed33eab51d5f550aff707b249380c001b058aea074d07e |
2 changes: 2 additions & 0 deletions
2
micro-infra-spring-property/src/test/resources/foo.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
foo=bar | ||
encKey={cipher}ala |
14 changes: 14 additions & 0 deletions
14
micro-infra-spring-property/src/test/resources/logback-test.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import ch.qos.logback.classic.encoder.PatternLayoutEncoder | ||
import ch.qos.logback.core.ConsoleAppender | ||
|
||
appender("CONSOLE", ConsoleAppender) { | ||
encoder(PatternLayoutEncoder) { | ||
pattern = "%d{HH:mm:ss.SSSZ} | %-5level | %X{correlationId} | %thread | %logger{1} | %m%n" | ||
} | ||
} | ||
|
||
//TODO: Fix console pollution during tests (it should be only logged to a test log file, but also available in Gradle test reports) | ||
root(INFO, ["CONSOLE"]) | ||
|
||
logger("com.ofg", DEBUG) | ||
logger("org.springframework.cloud.config.client", DEBUG) |
1 change: 1 addition & 0 deletions
1
...o-infra-spring-property/src/test/resources/testConfigurationWithPropertySource.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
enc.propertySource.prop={cipher}85f21553dcb4778ef25432df218dc672106e169c970db3c6f996567b9ff4ca3712f0d3b065aa5b44116a1ded0476c05e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters