Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
[#83] New module for properties management
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Zajaczkowski committed Nov 10, 2014
1 parent 6da3a6d commit 12b853d
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ext {
spockVersion = '0.7-groovy-2.0'
springBootVersion = '1.1.8.RELEASE'
springTestVersion = '4.1.1.RELEASE'
logbackVersion = '1.1.2'
}

task addHashFile << {
Expand Down
25 changes: 25 additions & 0 deletions micro-infra-spring-property/build.gradle
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"
}
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()
}
}
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 {
}
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 {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enc.application.prop={cipher}411fe0940df2296c4bc01be6477c030161961d1e0d231f1365ed33eab51d5f550aff707b249380c001b058aea074d07e
2 changes: 2 additions & 0 deletions micro-infra-spring-property/src/test/resources/foo.properties
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 micro-infra-spring-property/src/test/resources/logback-test.groovy
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)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enc.propertySource.prop={cipher}85f21553dcb4778ef25432df218dc672106e169c970db3c6f996567b9ff4ca3712f0d3b065aa5b44116a1ded0476c05e
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ include 'micro-infra-camel'
include ':swagger:micro-infra-spring-swagger'
include ':swagger:micro-infra-spring-swagger-ui'
include 'micro-infra-spring'
include 'micro-infra-spring-property'

rootProject.name = 'micro-infra-spring-root'

0 comments on commit 12b853d

Please sign in to comment.