Polishing.

This commit is contained in:
Mark Paluch
2017-05-15 17:25:14 +02:00
parent 1b946d3fa2
commit c2cee8572e
15 changed files with 72 additions and 65 deletions

View File

@@ -15,9 +15,6 @@
*/
package org.springframework.cloud.vault.config.aws;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -25,6 +22,7 @@ import java.util.Map;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -34,11 +32,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.StringUtils;
import org.springframework.vault.core.VaultOperations;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assume.assumeTrue;
/**
* Integration tests using the aws secret backend. In case this test should fail because
* of SSL make sure you run the test within the
* spring-cloud-vault-config/spring-cloud-vault-config directory as the keystore is
* referenced with {@code ../work/keystore.jks}.
*
* <p>
* This test requires AWS credentials and a region, see {@link #AWS_ACCESS_KEY},
* {@link #AWS_SECRET_KEY} and the {@link SpringBootTest} properties to be provided

View File

@@ -91,7 +91,7 @@ class LeasingVaultPropertySourceLocator extends VaultPropertySourceLocatorSuppor
/**
* Decorated {@link PropertySource} creation to catch and throw the first error that
* occurred durin initial secret retrieval.
* occurred during initial secret retrieval.
*
* @param secret
* @param accessor

View File

@@ -25,14 +25,15 @@ import org.springframework.vault.core.util.PropertyTransformer;
/**
* {@link PropertyTransformer} to transform a {@link Map} of properties by applying key
* name translation.
*
* <p>
* Existing keys will be transformed to a target key name while retaining the original
* value. Key name translation will leave other, not specified key names untouched.
*
* @author Mark Paluch
*/
public class PropertyNameTransformer extends PropertyTransformerSupport implements
PropertyTransformer {
public class PropertyNameTransformer extends PropertyTransformerSupport
implements PropertyTransformer {
private final Map<String, String> nameMapping = new HashMap<>();

View File

@@ -24,25 +24,26 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.vault.core.VaultOperations;
/**
* @author Stuart Ingram
* @author Mark Paluch
*/
@Configuration
@ConditionalOnBean(VaultBootstrapConfiguration.class)
@ConditionalOnProperty(name = "spring.cloud.vault.enabled", matchIfMissing = true)
@ConditionalOnExpression("${health.vault.enabled:true}")
@AutoConfigureBefore({ EndpointAutoConfiguration.class })
@AutoConfigureAfter({ VaultBootstrapConfiguration.class, HealthIndicatorAutoConfiguration.class })
@AutoConfigureAfter({ VaultBootstrapConfiguration.class,
HealthIndicatorAutoConfiguration.class })
public class VaultBootstrapHealthIndicatorConfiguration {
@Bean
@ConditionalOnMissingBean(name = "vaultHealthIndicator")
public HealthIndicator vaultHealthIndicator() {
return new VaultHealthIndicator();
public HealthIndicator vaultHealthIndicator(VaultOperations vaultOperations) {
return new VaultHealthIndicator(vaultOperations);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,7 +15,6 @@
*/
package org.springframework.cloud.vault.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.vault.core.VaultOperations;
@@ -23,11 +22,15 @@ import org.springframework.vault.support.VaultHealth;
/**
* @author Stuart Ingram
* @author Mark Paluch
*/
public class VaultHealthIndicator implements HealthIndicator {
@Autowired
private VaultOperations vaultOperations;
private final VaultOperations vaultOperations;
public VaultHealthIndicator(VaultOperations vaultOperations) {
this.vaultOperations = vaultOperations;
}
@Override
public Health health() {

View File

@@ -19,6 +19,10 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -29,19 +33,16 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.vault.authentication.IpAddressUserId;
import org.springframework.vault.core.VaultOperations;
import static org.assertj.core.api.Assertions.*;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration test using config infrastructure with AppId authentication.
*
* <p>
* In case this test should fail because of SSL make sure you run the test within the
* spring-cloud-vault-config/spring-cloud-vault-config directory as the keystore is
* referenced with {@code ../work/keystore.jks}.
*
*
* @author Mark Paluch
*/
@RunWith(SpringJUnit4ClassRunner.class)

View File

@@ -19,6 +19,10 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -29,20 +33,17 @@ import org.springframework.cloud.vault.util.Version;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.vault.core.VaultOperations;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assume.assumeTrue;
/**
* Integration test using config infrastructure with AppRole authentication.
*
* <p>
* In case this test should fail because of SSL make sure you run the test within the
* spring-cloud-vault-config/spring-cloud-vault-config directory as the keystore is
* referenced with {@code ../work/keystore.jks}.
*
*
* @author Mark Paluch
*/
@RunWith(SpringJUnit4ClassRunner.class)

View File

@@ -41,6 +41,7 @@ import static org.junit.Assume.assumeTrue;
/**
* Integration test using config infrastructure with Cubbyhole authentication.
*
* <p>
* In case this test should fail because of SSL make sure you run the test within the
* spring-cloud-vault-config/spring-cloud-vault-config directory as the keystore is

View File

@@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration test using config infrastructure with token authentication.
*
* <p>
* In case this test should fail because of SSL make sure you run the test within the
* spring-cloud-vault-config/spring-cloud-vault-config directory as the keystore is
@@ -52,11 +53,8 @@ public class VaultConfigDisabledTests {
VaultRule vaultRule = new VaultRule();
vaultRule.before();
vaultRule
.prepare()
.getVaultOperations()
.write("secret/testVaultApp",
Collections.singletonMap("vault.value", "foo"));
vaultRule.prepare().getVaultOperations().write("secret/testVaultApp",
Collections.singletonMap("vault.value", "foo"));
}
@Autowired

View File

@@ -17,6 +17,10 @@ package org.springframework.cloud.vault.config;
import java.util.Collections;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -25,19 +29,16 @@ import org.springframework.cloud.vault.util.VaultRule;
import org.springframework.core.env.Environment;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.assertj.core.api.Assertions.*;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration test using config infrastructure with token authentication.
*
* <p>
* In case this test should fail because of SSL make sure you run the test within the
* spring-cloud-vault-config/spring-cloud-vault-config directory as the keystore is
* referenced with {@code ../work/keystore.jks}.
*
*
* @author Mark Paluch
*/
@RunWith(SpringJUnit4ClassRunner.class)
@@ -50,11 +51,8 @@ public class VaultConfigGenericBackendDisabledTests {
VaultRule vaultRule = new VaultRule();
vaultRule.before();
vaultRule
.prepare()
.getVaultOperations()
.write("secret/testVaultApp",
Collections.singletonMap("vault.value", "foo"));
vaultRule.prepare().getVaultOperations().write("secret/testVaultApp",
Collections.singletonMap("vault.value", "foo"));
}
@Autowired

View File

@@ -40,6 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration test using config infrastructure with token authentication.
*
* <p>
* In case this test should fail because of SSL make sure you run the test within the
* spring-cloud-vault-config/spring-cloud-vault-config directory as the keystore is

View File

@@ -17,6 +17,10 @@ package org.springframework.cloud.vault.config;
import java.util.Collections;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -26,19 +30,16 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.vault.core.VaultOperations;
import static org.assertj.core.api.Assertions.*;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration test using config infrastructure with token authentication.
*
* <p>
* In case this test should fail because of SSL make sure you run the test within the
* spring-cloud-vault-config/spring-cloud-vault-config directory as the keystore is
* referenced with {@code ../work/keystore.jks}.
*
*
* @author Mark Paluch
*/
@RunWith(SpringJUnit4ClassRunner.class)

View File

@@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration test using config infrastructure with token authentication.
*
* <p>
* In case this test should fail because of SSL make sure you run the test within the
* spring-cloud-vault-config/spring-cloud-vault-config directory as the keystore is

View File

@@ -15,21 +15,21 @@
*/
package org.springframework.cloud.vault.config;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import org.springframework.vault.core.VaultOperations;
import org.springframework.vault.core.VaultSysOperations;
import org.springframework.vault.support.VaultHealth;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.when;
/**
* Unit tests for {@link VaultHealthIndicator}.
@@ -39,9 +39,6 @@ import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class VaultHealthIndicatorUnitTests {
@InjectMocks
VaultHealthIndicator healthIndicator = new VaultHealthIndicator();
@Mock
VaultOperations vaultOperations;
@@ -51,9 +48,13 @@ public class VaultHealthIndicatorUnitTests {
@Mock
VaultHealth healthResponse;
VaultHealthIndicator healthIndicator;
@Before
public void before() throws Exception {
healthIndicator = new VaultHealthIndicator(vaultOperations);
when(vaultOperations.opsForSys()).thenReturn(vaultSysOperations);
when(vaultSysOperations.health()).thenReturn(healthResponse);
}

View File

@@ -46,9 +46,6 @@ public class VaultPropertySourceLocatorUnitTests {
@Mock
private ConfigurableEnvironment configurableEnvironment;
@Mock
private VaultPropertySource vaultPropertySource;
@Before
public void before() {
propertySourceLocator = new VaultPropertySourceLocator(operations,