Polishing.
Relocate tests using Vault as config source to config client. Move integration tests to parent package as all tests are integration tests. Enhance JavaDoc. Order travis.yml file according the execution sequence.
This commit is contained in:
22
.travis.yml
22
.travis.yml
@@ -7,13 +7,6 @@ services:
|
||||
jdk:
|
||||
- oraclejdk8
|
||||
|
||||
before_script:
|
||||
- mysql -e "CREATE USER 'spring' IDENTIFIED by 'vault';"
|
||||
- mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO 'spring'@'%' WITH GRANT OPTION;";
|
||||
- psql -U postgres -c "CREATE ROLE spring WITH LOGIN PASSWORD 'vault' CREATEROLE CREATEUSER;"
|
||||
- sleep 30 # wait until Cassandra is up
|
||||
- apache-cassandra-2.2.6/bin/cqlsh 127.0.0.1 -u cassandra -p cassandra -e "CREATE USER 'spring' WITH PASSWORD 'vault' SUPERUSER"
|
||||
|
||||
install:
|
||||
- mkdir -p download
|
||||
- test -f download/apache-cassandra-2.2.6-bin.tar.gz || wget http://www-eu.apache.org/dist/cassandra/2.2.6/apache-cassandra-2.2.6-bin.tar.gz -O download/apache-cassandra-2.2.6-bin.tar.gz
|
||||
@@ -23,11 +16,20 @@ install:
|
||||
- src/test/bash/install_vault.sh
|
||||
- src/test/bash/local_run_vault.sh &
|
||||
|
||||
after_script: pkill vault
|
||||
before_script:
|
||||
- mysql -e "CREATE USER 'spring' IDENTIFIED by 'vault';"
|
||||
- mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO 'spring'@'%' WITH GRANT OPTION;";
|
||||
- psql -U postgres -c "CREATE ROLE spring WITH LOGIN PASSWORD 'vault' CREATEROLE CREATEUSER;"
|
||||
- sleep 30 # wait until Cassandra is up
|
||||
- apache-cassandra-2.2.6/bin/cqlsh localhost -u cassandra -p cassandra -e "CREATE USER 'spring' WITH PASSWORD 'vault' SUPERUSER"
|
||||
|
||||
script: mvn clean verify
|
||||
|
||||
after_script:
|
||||
- apache-cassandra-2.2.6/bin/nodetool stopdaemon
|
||||
- pkill vault
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- '$HOME/.m2/repository'
|
||||
- '$HOME/vault/download'
|
||||
- '$HOME/download'
|
||||
- 'download'
|
||||
@@ -26,8 +26,7 @@ public interface AppIdUserIdMechanism {
|
||||
/**
|
||||
* Creates a UserId for AppId authentication.
|
||||
*
|
||||
* @return
|
||||
* @return the UserId.
|
||||
*/
|
||||
String createUserId();
|
||||
|
||||
}
|
||||
|
||||
@@ -19,9 +19,12 @@ package org.springframework.cloud.vault;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Collection of common used {@link SecureBackendAccessor accessors} to access secure
|
||||
* backends.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class SecureBackendAccessors {
|
||||
@@ -29,24 +32,30 @@ public class SecureBackendAccessors {
|
||||
/**
|
||||
* Creates a {@link SecureBackendAccessor} for the {@code generic} secure backend.
|
||||
*
|
||||
* @param vaultProperties
|
||||
* @param key
|
||||
* @return
|
||||
* @param vaultProperties must not be {@literal null}.
|
||||
* @param key must not be {@literal null} and not empty.
|
||||
* @return the {@link SecureBackendAccessor}
|
||||
*/
|
||||
public static SecureBackendAccessor generic(VaultProperties vaultProperties,
|
||||
String key) {
|
||||
|
||||
Assert.notNull(vaultProperties, "VaultProperties must not be null");
|
||||
return generic(vaultProperties.getBackend(), key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link SecureBackendAccessor} for the {@code generic} secure backend.
|
||||
*
|
||||
* @param secretBackendPath
|
||||
* @param key
|
||||
* @return
|
||||
* @param secretBackendPath must not be {@literal null} and not empty.
|
||||
* @param key must not be {@literal null} and not empty.
|
||||
* @return the {@link SecureBackendAccessor}
|
||||
*/
|
||||
public static SecureBackendAccessor generic(final String secretBackendPath,
|
||||
final String key) {
|
||||
|
||||
Assert.hasText(secretBackendPath, "Secret Backend Path must not be empty");
|
||||
Assert.hasText(key, "Key must not be empty");
|
||||
|
||||
return new SecureBackendAccessor() {
|
||||
|
||||
@Override
|
||||
@@ -65,19 +74,25 @@ public class SecureBackendAccessors {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link SecureBackendAccessor} for a secure backend using {@link org.springframework.cloud.vault.VaultProperties.DatabaseSecretProperties}. This
|
||||
* accessor transforms Vault's username/password property names to names provided with
|
||||
* {@link VaultProperties.DatabaseSecretProperties#getUsernameProperty()} and
|
||||
* Creates a {@link SecureBackendAccessor} for a secure backend using
|
||||
* {@link org.springframework.cloud.vault.VaultProperties.DatabaseSecretProperties}.
|
||||
* This accessor transforms Vault's username/password property names to names provided
|
||||
* with {@link VaultProperties.DatabaseSecretProperties#getUsernameProperty()} and
|
||||
* {@link VaultProperties.DatabaseSecretProperties#getUsernameProperty()}.
|
||||
*
|
||||
* @param properties
|
||||
* @return
|
||||
* @param properties must not be {@literal null}.
|
||||
* @return the {@link SecureBackendAccessor}
|
||||
*/
|
||||
public static SecureBackendAccessor database(final VaultProperties.DatabaseSecretProperties properties) {
|
||||
public static SecureBackendAccessor database(
|
||||
final VaultProperties.DatabaseSecretProperties properties) {
|
||||
|
||||
Assert.notNull(properties, "DatabaseSecretProperties must not be null");
|
||||
|
||||
return new SecureBackendAccessor() {
|
||||
|
||||
@Override
|
||||
public Map<String, String> variables() {
|
||||
|
||||
Map<String, String> variables = new HashMap<>();
|
||||
variables.put("backend", properties.getBackend());
|
||||
variables.put("key", String.format("creds/%s", properties.getRole()));
|
||||
@@ -95,5 +110,4 @@ public class SecureBackendAccessors {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.security.crypto.codec.Hex;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Utility to generate SHA 256 checksums.
|
||||
* Utility to generate a SHA 256 checksum.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@@ -33,28 +33,31 @@ class Sha256 {
|
||||
/**
|
||||
* Generates a hex-encoded SHA256 checksum from the supplied {@code content}.
|
||||
*
|
||||
* @param content
|
||||
* @return
|
||||
* @param content must not be {@literal null} and not empty.
|
||||
* @return hex-encoded SHA256 checksum
|
||||
*/
|
||||
public static String toSha256(String content) {
|
||||
|
||||
Assert.hasText(content, "Content must not be empty!");
|
||||
Assert.hasText(content, "Content must not be empty");
|
||||
|
||||
MessageDigest messageDigest = getMessageDigest("SHA-256");
|
||||
byte[] digest = messageDigest.digest(content.getBytes(StandardCharsets.US_ASCII));
|
||||
return new String(Hex.encode(digest));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a MessageDigest instance for the given algorithm. Throws an IllegalArgumentException if <i>algorithm</i> is
|
||||
* unknown
|
||||
* Get a MessageDigest instance for the given algorithm. Throws an
|
||||
* IllegalArgumentException if <i>algorithm</i> is unknown
|
||||
*
|
||||
* @return MessageDigest instance
|
||||
* @throws IllegalArgumentException if NoSuchAlgorithmException is thrown
|
||||
*/
|
||||
private static MessageDigest getMessageDigest(String algorithm) throws IllegalArgumentException {
|
||||
private static MessageDigest getMessageDigest(String algorithm)
|
||||
throws IllegalArgumentException {
|
||||
try {
|
||||
return MessageDigest.getInstance(algorithm);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
}
|
||||
catch (NoSuchAlgorithmException e) {
|
||||
throw new IllegalArgumentException("No such algorithm [" + algorithm + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.cloud.vault;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
@@ -25,6 +26,7 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
@@ -40,9 +42,11 @@ public class VaultBootstrapConfiguration {
|
||||
|
||||
VaultClient vaultClient = new VaultClient(vaultProperties());
|
||||
|
||||
Map<String, AppIdUserIdMechanism> appIdUserIdMechanisms = applicationContext.getBeansOfType(AppIdUserIdMechanism.class);
|
||||
if(!appIdUserIdMechanisms.isEmpty()){
|
||||
vaultClient.setAppIdUserIdMechanism(appIdUserIdMechanisms.values().iterator().next());
|
||||
Map<String, AppIdUserIdMechanism> appIdUserIdMechanisms = applicationContext
|
||||
.getBeansOfType(AppIdUserIdMechanism.class);
|
||||
if (!appIdUserIdMechanisms.isEmpty()) {
|
||||
vaultClient.setAppIdUserIdMechanism(
|
||||
appIdUserIdMechanisms.values().iterator().next());
|
||||
}
|
||||
|
||||
return vaultClient;
|
||||
@@ -59,20 +63,30 @@ public class VaultBootstrapConfiguration {
|
||||
public AppIdUserIdMechanism appIdUserIdMechanism(VaultProperties vaultProperties) {
|
||||
|
||||
String userId = vaultProperties.getAppId().getUserId();
|
||||
Assert.hasText(userId, "UserId (spring.cloud.vault.app-id.user-id) must not be empty.");
|
||||
Assert.hasText(userId,
|
||||
"UserId (spring.cloud.vault.app-id.user-id) must not be empty.");
|
||||
|
||||
switch (userId.toUpperCase()) {
|
||||
try {
|
||||
Class<?> userIdClass = ClassUtils.forName(userId, null);
|
||||
return (AppIdUserIdMechanism) BeanUtils.instantiateClass(userIdClass);
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
|
||||
switch (userId.toUpperCase()) {
|
||||
case VaultProperties.AppIdProperties.IP_ADDRESS:
|
||||
return new IpAddressUserId();
|
||||
case VaultProperties.AppIdProperties.MAC_ADDRESS:
|
||||
case VaultProperties.AppIdProperties.MAC_ADDRESS:
|
||||
return new MacAddressUserId(vaultProperties);
|
||||
default:
|
||||
return new StaticUserId(vaultProperties);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public VaultPropertySourceLocator vaultPropertySourceLocator(ApplicationContext applicationContext) {
|
||||
return new VaultPropertySourceLocator(vaultClient(applicationContext), vaultProperties());
|
||||
public VaultPropertySourceLocator vaultPropertySourceLocator(
|
||||
ApplicationContext applicationContext) {
|
||||
return new VaultPropertySourceLocator(vaultClient(applicationContext),
|
||||
vaultProperties());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ public class VaultClient {
|
||||
}
|
||||
|
||||
private HttpHeaders createHeaders(VaultToken vaultToken) {
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add(VAULT_TOKEN, vaultToken.getToken());
|
||||
return headers;
|
||||
@@ -91,7 +92,7 @@ public class VaultClient {
|
||||
/**
|
||||
* Creates a token using a configured authentication mechanism.
|
||||
*
|
||||
* @return
|
||||
* @return the {@link VaultToken}.
|
||||
*/
|
||||
public VaultToken createToken() {
|
||||
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.springframework.cloud.vault;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
import org.hibernate.validator.constraints.Range;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @author Mark Paluch
|
||||
@@ -77,11 +77,11 @@ public class VaultProperties {
|
||||
|
||||
private AppIdProperties appId = new AppIdProperties();
|
||||
|
||||
private final MySql mysql = new MySql();
|
||||
private MySql mysql = new MySql();
|
||||
|
||||
private final PostgreSql postgresql = new PostgreSql();
|
||||
private PostgreSql postgresql = new PostgreSql();
|
||||
|
||||
private final Cassandra cassandra = new Cassandra();
|
||||
private Cassandra cassandra = new Cassandra();
|
||||
|
||||
/**
|
||||
* Application name for AppId authentication.
|
||||
@@ -117,7 +117,8 @@ public class VaultProperties {
|
||||
private String networkInterface = null;
|
||||
|
||||
/**
|
||||
* UserId mechanism. Can be either "MAC_ADDRESS", "IP_ADDRESS". Any other values are passed as UserId.
|
||||
* UserId mechanism. Can be either "MAC_ADDRESS", "IP_ADDRESS", a string or a
|
||||
* class name.
|
||||
*/
|
||||
@NotEmpty
|
||||
private String userId = MAC_ADDRESS;
|
||||
@@ -220,21 +221,21 @@ public class VaultProperties {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration properties for database secrets.
|
||||
* Configuration properties interface for database secrets.
|
||||
*/
|
||||
public interface DatabaseSecretProperties {
|
||||
|
||||
/**
|
||||
* Role name.
|
||||
*
|
||||
* @return
|
||||
* @return the role name
|
||||
*/
|
||||
String getRole();
|
||||
|
||||
/**
|
||||
* Backend path.
|
||||
*
|
||||
* @return
|
||||
* @return the backend path.
|
||||
*/
|
||||
String getBackend();
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
|
||||
/**
|
||||
* {@link PropertySourceLocator} using {@link VaultClient}.
|
||||
*
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class VaultPropertySourceLocator implements PropertySourceLocator {
|
||||
|
||||
@@ -23,16 +23,21 @@ import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* Value object to bind HTTP API responses.
|
||||
*
|
||||
* @author Spencer Gibb
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Data
|
||||
public class VaultResponse {
|
||||
|
||||
private Map<String, Object> auth;
|
||||
private Map<String, String> data;
|
||||
private Map<String, String> metadata;
|
||||
|
||||
@JsonProperty("lease_duration")
|
||||
private long leaseDuration;
|
||||
|
||||
@JsonProperty("lease_id")
|
||||
private String leaseId;
|
||||
private boolean renewable;
|
||||
|
||||
@@ -16,26 +16,40 @@
|
||||
|
||||
package org.springframework.cloud.vault;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Value;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Value object for a Vault token.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Value
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class VaultToken {
|
||||
|
||||
private String token;
|
||||
private long leaseDuration;
|
||||
|
||||
/**
|
||||
* Creates a new {@link VaultToken}.
|
||||
* @param token must not be {@literal null}.
|
||||
* @return the created {@link VaultToken}
|
||||
*/
|
||||
public static VaultToken of(String token) {
|
||||
return of(token, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link VaultToken} with a {@code leaseDuration}.
|
||||
* @param token must not be {@literal null}.
|
||||
* @return the created {@link VaultToken}
|
||||
*/
|
||||
public static VaultToken of(String token, long leaseDuration) {
|
||||
|
||||
Assert.hasText(token, "Token must not be empty");
|
||||
return new VaultToken(token, leaseDuration);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.vault.integration;
|
||||
package org.springframework.cloud.vault;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.springframework.cloud.vault.util.PrepareVault;
|
||||
@@ -14,15 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.vault.integration;
|
||||
package org.springframework.cloud.vault;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.springframework.cloud.vault.IpAddressUserId;
|
||||
import org.springframework.cloud.vault.VaultClient;
|
||||
import org.springframework.cloud.vault.VaultProperties;
|
||||
import org.springframework.cloud.vault.VaultProperties.AppIdProperties;
|
||||
import org.springframework.cloud.vault.VaultProperties.AuthenticationMethod;
|
||||
import org.springframework.cloud.vault.VaultToken;
|
||||
import org.springframework.cloud.vault.util.Settings;
|
||||
|
||||
/**
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.vault.integration;
|
||||
package org.springframework.cloud.vault;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.springframework.cloud.vault.*;
|
||||
import org.springframework.cloud.vault.VaultProperties.AppIdProperties;
|
||||
import org.springframework.cloud.vault.VaultProperties.AuthenticationMethod;
|
||||
import org.springframework.cloud.vault.util.Settings;
|
||||
@@ -58,7 +57,8 @@ public class AppIdAuthenticationMethodsIntegrationTests extends AbstractIntegrat
|
||||
@Test
|
||||
public void loginUsingStaticUserIdShouldCreateAToken() throws Exception {
|
||||
|
||||
VaultProperties vaultProperties = prepareAppIdAuthenticationMethod("my-user-id", "myapp");
|
||||
VaultProperties vaultProperties = prepareAppIdAuthenticationMethod("my-user-id",
|
||||
"myapp");
|
||||
VaultClient vaultClient = new VaultClient(vaultProperties);
|
||||
vaultClient.setAppIdUserIdMechanism(new StaticUserId(vaultProperties));
|
||||
assertThat(vaultClient.createToken()).isNotNull();
|
||||
@@ -67,11 +67,11 @@ public class AppIdAuthenticationMethodsIntegrationTests extends AbstractIntegrat
|
||||
@Test
|
||||
public void loginUsingMacAddressShouldCreateAToken() throws Exception {
|
||||
|
||||
VaultProperties vaultProperties = prepareAppIdAuthenticationMethod(AppIdProperties.MAC_ADDRESS, "myapp");
|
||||
VaultProperties vaultProperties = prepareAppIdAuthenticationMethod(
|
||||
AppIdProperties.MAC_ADDRESS, "myapp");
|
||||
VaultClient vaultClient = new VaultClient(vaultProperties);
|
||||
|
||||
vaultClient.setAppIdUserIdMechanism(
|
||||
new MacAddressUserId(vaultProperties));
|
||||
vaultClient.setAppIdUserIdMechanism(new MacAddressUserId(vaultProperties));
|
||||
assertThat(vaultClient.createToken()).isNotNull();
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.vault.integration;
|
||||
package org.springframework.cloud.vault;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.springframework.cloud.vault.SecureBackendAccessors.*;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -26,10 +26,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.vault.VaultClient;
|
||||
import org.springframework.cloud.vault.VaultProperties;
|
||||
import org.springframework.cloud.vault.util.CanConnect;
|
||||
import org.springframework.cloud.vault.util.Settings;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
@@ -14,20 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.vault.integration;
|
||||
package org.springframework.cloud.vault;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.cloud.vault.SecureBackendAccessors.generic;
|
||||
import static org.springframework.cloud.vault.SecureBackendAccessors.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.vault.SecureBackendAccessors;
|
||||
import org.springframework.cloud.vault.VaultClient;
|
||||
import org.springframework.cloud.vault.VaultProperties;
|
||||
import org.springframework.cloud.vault.VaultToken;
|
||||
import org.springframework.cloud.vault.util.Settings;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@@ -50,8 +46,8 @@ public class GenericSecretIntegrationTests extends AbstractIntegrationTests {
|
||||
@Test
|
||||
public void shouldReturnSecretsCorrectly() throws Exception {
|
||||
|
||||
Map<String, String> secretProperties = vaultClient.read(generic(vaultProperties, "app-name"),
|
||||
createToken());
|
||||
Map<String, String> secretProperties = vaultClient
|
||||
.read(generic(vaultProperties, "app-name"), createToken());
|
||||
|
||||
assertThat(secretProperties).containsAllEntriesOf(createExpectedMap());
|
||||
}
|
||||
@@ -59,7 +55,8 @@ public class GenericSecretIntegrationTests extends AbstractIntegrationTests {
|
||||
@Test
|
||||
public void shouldReturnNullIfNotFound() throws Exception {
|
||||
|
||||
Map<String, String> secretProperties = vaultClient.read(generic(vaultProperties, "missing"), createToken());
|
||||
Map<String, String> secretProperties = vaultClient
|
||||
.read(generic(vaultProperties, "missing"), createToken());
|
||||
|
||||
assertThat(secretProperties).isNull();
|
||||
}
|
||||
@@ -14,11 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.vault.integration;
|
||||
package org.springframework.cloud.vault;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.springframework.cloud.vault.SecureBackendAccessors.database;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.springframework.cloud.vault.SecureBackendAccessors.*;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collections;
|
||||
@@ -26,8 +26,6 @@ import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.vault.VaultClient;
|
||||
import org.springframework.cloud.vault.VaultProperties;
|
||||
import org.springframework.cloud.vault.util.CanConnect;
|
||||
import org.springframework.cloud.vault.util.Settings;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.vault.integration;
|
||||
package org.springframework.cloud.vault;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
@@ -26,8 +26,6 @@ import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.vault.VaultClient;
|
||||
import org.springframework.cloud.vault.VaultProperties;
|
||||
import org.springframework.cloud.vault.util.CanConnect;
|
||||
import org.springframework.cloud.vault.util.Settings;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.vault.integration;
|
||||
package org.springframework.cloud.vault;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
@@ -40,8 +40,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = {BootstrapConfiguration.class, VaultAppIdCustomMechanismTests.TestApplication.class})
|
||||
@IntegrationTest({ "spring.cloud.vault.authentication=appid", "use.custom.config=true", "spring.application.name=VaultAppIdCustomMechanismTests"})
|
||||
@SpringApplicationConfiguration(classes = { BootstrapConfiguration.class,
|
||||
VaultAppIdCustomMechanismTests.TestApplication.class })
|
||||
@IntegrationTest({ "spring.cloud.vault.authentication=appid", "use.custom.config=true",
|
||||
"spring.application.name=VaultAppIdCustomMechanismTests" })
|
||||
public class VaultAppIdCustomMechanismTests {
|
||||
|
||||
@BeforeClass
|
||||
@@ -50,7 +52,9 @@ public class VaultAppIdCustomMechanismTests {
|
||||
VaultRule vaultRule = new VaultRule();
|
||||
vaultRule.before();
|
||||
|
||||
vaultRule.prepare().writeSecret(VaultAppIdCustomMechanismTests.class.getSimpleName(), Collections.singletonMap("vault.value", "foo"));
|
||||
vaultRule.prepare().writeSecret(
|
||||
VaultAppIdCustomMechanismTests.class.getSimpleName(),
|
||||
Collections.singletonMap("vault.value", "foo"));
|
||||
|
||||
VaultProperties vaultProperties = Settings.createVaultProperties();
|
||||
vaultProperties.setAuthentication(VaultProperties.AuthenticationMethod.APPID);
|
||||
@@ -59,12 +63,16 @@ public class VaultAppIdCustomMechanismTests {
|
||||
vaultRule.prepare().mountAuth(vaultProperties.getAppId().getAppIdPath());
|
||||
}
|
||||
|
||||
vaultRule.prepare().mapAppId(VaultAppIdCustomMechanismTests.class.getSimpleName());
|
||||
vaultRule.prepare().mapUserId(VaultAppIdCustomMechanismTests.class.getSimpleName(), new StaticUserIdMechanism().createUserId());
|
||||
vaultRule.prepare()
|
||||
.mapAppId(VaultAppIdCustomMechanismTests.class.getSimpleName());
|
||||
vaultRule.prepare().mapUserId(
|
||||
VaultAppIdCustomMechanismTests.class.getSimpleName(),
|
||||
new StaticUserIdMechanism().createUserId());
|
||||
|
||||
}
|
||||
|
||||
@Value("${vault.value}") String configValue;
|
||||
@Value("${vault.value}")
|
||||
String configValue;
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.vault;
|
||||
package org.springframework.cloud.vault.configclient;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
@@ -28,6 +28,8 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.vault.IpAddressUserId;
|
||||
import org.springframework.cloud.vault.VaultProperties;
|
||||
import org.springframework.cloud.vault.util.Settings;
|
||||
import org.springframework.cloud.vault.util.VaultRule;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -37,7 +39,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = VaultAppIdTests.TestApplication.class)
|
||||
@IntegrationTest({"spring.cloud.vault.authentication=appid", "spring.cloud.vault.app-id.user-id=IP_ADDRESS", "spring.application.name=VaultAppIdTests"})
|
||||
@IntegrationTest({ "spring.cloud.vault.authentication=appid",
|
||||
"spring.cloud.vault.app-id.user-id=IP_ADDRESS",
|
||||
"spring.application.name=VaultAppIdTests" })
|
||||
public class VaultAppIdTests {
|
||||
|
||||
@BeforeClass
|
||||
@@ -46,7 +50,8 @@ public class VaultAppIdTests {
|
||||
VaultRule vaultRule = new VaultRule();
|
||||
vaultRule.before();
|
||||
|
||||
vaultRule.prepare().writeSecret(VaultAppIdTests.class.getSimpleName(), Collections.singletonMap("vault.value", "foo"));
|
||||
vaultRule.prepare().writeSecret(VaultAppIdTests.class.getSimpleName(),
|
||||
Collections.singletonMap("vault.value", "foo"));
|
||||
|
||||
VaultProperties vaultProperties = Settings.createVaultProperties();
|
||||
vaultProperties.setAuthentication(VaultProperties.AuthenticationMethod.APPID);
|
||||
@@ -57,7 +62,8 @@ public class VaultAppIdTests {
|
||||
}
|
||||
|
||||
vaultRule.prepare().mapAppId(VaultAppIdTests.class.getSimpleName());
|
||||
vaultRule.prepare().mapUserId(VaultAppIdTests.class.getSimpleName(), new IpAddressUserId().createUserId());
|
||||
vaultRule.prepare().mapUserId(VaultAppIdTests.class.getSimpleName(),
|
||||
new IpAddressUserId().createUserId());
|
||||
}
|
||||
|
||||
@Value("${vault.value}")
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.vault;
|
||||
package org.springframework.cloud.vault.configclient;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assume.*;
|
||||
@@ -26,7 +26,6 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -14,7 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.vault;
|
||||
package org.springframework.cloud.vault.configclient;
|
||||
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
@@ -29,7 +31,6 @@ import javax.sql.DataSource;
|
||||
|
||||
import com.mysql.jdbc.MySQLConnection;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -42,8 +43,6 @@ import org.springframework.cloud.vault.util.CanConnect;
|
||||
import org.springframework.cloud.vault.util.VaultRule;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
/**
|
||||
* Integration tests using the mysql secret backend.
|
||||
*/
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.vault;
|
||||
package org.springframework.cloud.vault.configclient;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assume.*;
|
||||
@@ -1,11 +1,25 @@
|
||||
package org.springframework.cloud.vault;
|
||||
/*
|
||||
* Copyright 2016 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
package org.springframework.cloud.vault.configclient;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -13,8 +27,6 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.cloud.vault.util.PrepareVault;
|
||||
import org.springframework.cloud.vault.util.VaultRule;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -22,14 +34,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@SpringApplicationConfiguration(classes = VaultTests.TestApplication.class)
|
||||
public class VaultTests {
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
|
||||
VaultRule vaultRule = new VaultRule();
|
||||
vaultRule.before();
|
||||
|
||||
vaultRule.prepare().writeSecret("testVaultApp", Collections.singletonMap("vault.value", "foo"));
|
||||
vaultRule.prepare().writeSecret("testVaultApp",
|
||||
Collections.singletonMap("vault.value", "foo"));
|
||||
}
|
||||
|
||||
@Value("${vault.value}")
|
||||
Reference in New Issue
Block a user