Polishing
Reformat code using new formatter Settings. See gh-482.
This commit is contained in:
@@ -39,9 +39,8 @@ import org.springframework.vault.core.util.PropertyTransformer;
|
||||
* @author Sebastien Nahelou
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableConfigurationProperties({ VaultMySqlProperties.class,
|
||||
VaultPostgreSqlProperties.class, VaultCassandraProperties.class,
|
||||
VaultMongoProperties.class, VaultElasticsearchProperties.class,
|
||||
@EnableConfigurationProperties({ VaultMySqlProperties.class, VaultPostgreSqlProperties.class,
|
||||
VaultCassandraProperties.class, VaultMongoProperties.class, VaultElasticsearchProperties.class,
|
||||
VaultDatabaseProperties.class })
|
||||
public class VaultConfigDatabaseBootstrapConfiguration {
|
||||
|
||||
@@ -67,32 +66,26 @@ public class VaultConfigDatabaseBootstrapConfiguration {
|
||||
* @param properties must not be {@literal null}.
|
||||
* @return the {@link SecretBackendMetadata}
|
||||
*/
|
||||
static SecretBackendMetadata forDatabase(
|
||||
final DatabaseSecretProperties properties) {
|
||||
static SecretBackendMetadata forDatabase(final DatabaseSecretProperties properties) {
|
||||
|
||||
Assert.notNull(properties, "DatabaseSecretProperties must not be null");
|
||||
|
||||
PropertyNameTransformer transformer = new PropertyNameTransformer();
|
||||
transformer.addKeyTransformation("username",
|
||||
properties.getUsernameProperty());
|
||||
transformer.addKeyTransformation("password",
|
||||
properties.getPasswordProperty());
|
||||
transformer.addKeyTransformation("username", properties.getUsernameProperty());
|
||||
transformer.addKeyTransformation("password", properties.getPasswordProperty());
|
||||
|
||||
return new SecretBackendMetadata() {
|
||||
|
||||
private final String credPath = properties.isStaticRole() ? "static-creds"
|
||||
: "creds";
|
||||
private final String credPath = properties.isStaticRole() ? "static-creds" : "creds";
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return String.format("%s with Role %s", properties.getBackend(),
|
||||
properties.getRole());
|
||||
return String.format("%s with Role %s", properties.getBackend(), properties.getRole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return String.format("%s/%s/%s", properties.getBackend(),
|
||||
this.credPath, properties.getRole());
|
||||
return String.format("%s/%s/%s", properties.getBackend(), this.credPath, properties.getRole());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,16 +98,14 @@ public class VaultConfigDatabaseBootstrapConfiguration {
|
||||
|
||||
Map<String, String> variables = new HashMap<>();
|
||||
variables.put("backend", properties.getBackend());
|
||||
variables.put("key",
|
||||
String.format("%s/%s", this.credPath, properties.getRole()));
|
||||
variables.put("key", String.format("%s/%s", this.credPath, properties.getRole()));
|
||||
return variables;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public SecretBackendMetadata createMetadata(
|
||||
DatabaseSecretProperties backendDescriptor) {
|
||||
public SecretBackendMetadata createMetadata(DatabaseSecretProperties backendDescriptor) {
|
||||
return forDatabase(backendDescriptor);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
@ConfigurationProperties("spring.cloud.vault.mysql")
|
||||
@Validated
|
||||
@Deprecated
|
||||
public class VaultMySqlProperties
|
||||
implements DatabaseSecretProperties, VaultSecretBackendDescriptor {
|
||||
public class VaultMySqlProperties implements DatabaseSecretProperties, VaultSecretBackendDescriptor {
|
||||
|
||||
/**
|
||||
* Enable mysql backend usage.
|
||||
|
||||
@@ -84,30 +84,25 @@ public class CassandraSecretIntegrationTests extends IntegrationTestSupport {
|
||||
connection.put("password", CASSANDRA_PASSWORD);
|
||||
connection.put("protocol_version", 3);
|
||||
|
||||
vaultOperations.write(
|
||||
String.format("%s/config/connection", this.cassandra.getBackend()),
|
||||
connection);
|
||||
vaultOperations.write(String.format("%s/config/connection", this.cassandra.getBackend()), connection);
|
||||
|
||||
Map<String, String> role = new HashMap<>();
|
||||
|
||||
role.put("creation_cql", CREATE_USER_AND_GRANT_CQL);
|
||||
role.put("consistency", "All");
|
||||
|
||||
vaultOperations.write(String.format("%s/roles/%s", this.cassandra.getBackend(),
|
||||
this.cassandra.getRole()), role);
|
||||
vaultOperations.write(String.format("%s/roles/%s", this.cassandra.getBackend(), this.cassandra.getRole()),
|
||||
role);
|
||||
|
||||
this.configOperations = new VaultConfigTemplate(vaultOperations,
|
||||
this.vaultProperties);
|
||||
this.configOperations = new VaultConfigTemplate(vaultOperations, this.vaultProperties);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateCredentialsCorrectly() {
|
||||
|
||||
Map<String, Object> secretProperties = this.configOperations
|
||||
.read(forDatabase(this.cassandra)).getData();
|
||||
Map<String, Object> secretProperties = this.configOperations.read(forDatabase(this.cassandra)).getData();
|
||||
|
||||
assertThat(secretProperties).containsKeys("spring.data.cassandra.username",
|
||||
"spring.data.cassandra.password");
|
||||
assertThat(secretProperties).containsKeys("spring.data.cassandra.username", "spring.data.cassandra.password");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,8 +63,7 @@ public class ElasticsearchSecretIntegrationTests extends IntegrationTestSupport
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
assumeTrue(CanConnect
|
||||
.to(new InetSocketAddress(ELASTICSEARCH_HOST, ELASTICSEARCH_PORT)));
|
||||
assumeTrue(CanConnect.to(new InetSocketAddress(ELASTICSEARCH_HOST, ELASTICSEARCH_PORT)));
|
||||
assumeTrue(prepare().getVersion().isGreaterThanOrEqualTo(Version.parse("1.3.0")));
|
||||
|
||||
this.elasticsearch.setEnabled(true);
|
||||
@@ -82,16 +81,13 @@ public class ElasticsearchSecretIntegrationTests extends IntegrationTestSupport
|
||||
config.put("allowed_roles", "readonly");
|
||||
config.put("username", "elastic");
|
||||
config.put("password", "elastic");
|
||||
config.put("url",
|
||||
String.format("http://%s:%d", ELASTICSEARCH_HOST, ELASTICSEARCH_PORT));
|
||||
config.put("url", String.format("http://%s:%d", ELASTICSEARCH_HOST, ELASTICSEARCH_PORT));
|
||||
|
||||
config.put("ca_cert", String.format("%s/elastic-stack-ca.crt", ES_HOME));
|
||||
config.put("client_cert", String.format("%s/elastic-certificates.crt", ES_HOME));
|
||||
config.put("client_key", String.format("%s/elastic-certificates.key", ES_HOME));
|
||||
|
||||
vaultOperations.write(
|
||||
String.format("%s/config/%s", this.elasticsearch.getBackend(), database),
|
||||
config);
|
||||
vaultOperations.write(String.format("%s/config/%s", this.elasticsearch.getBackend(), database), config);
|
||||
|
||||
Map<String, Object> role = new LinkedHashMap<>();
|
||||
role.put("db_name", database);
|
||||
@@ -99,18 +95,15 @@ public class ElasticsearchSecretIntegrationTests extends IntegrationTestSupport
|
||||
"{\"elasticsearch_role_definition\": {\"indices\": [{\"names\":[\"*\"], \"privileges\":[\"read\"]}]}}");
|
||||
role.put("default_ttl", "1h");
|
||||
|
||||
vaultOperations.write(this.elasticsearch.getBackend() + "/roles/"
|
||||
+ this.elasticsearch.getRole(), role);
|
||||
vaultOperations.write(this.elasticsearch.getBackend() + "/roles/" + this.elasticsearch.getRole(), role);
|
||||
|
||||
this.configOperations = new VaultConfigTemplate(vaultOperations,
|
||||
this.vaultProperties);
|
||||
this.configOperations = new VaultConfigTemplate(vaultOperations, this.vaultProperties);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateCredentialsCorrectly() {
|
||||
|
||||
Map<String, Object> secretProperties = this.configOperations
|
||||
.read(forDatabase(this.elasticsearch)).getData();
|
||||
Map<String, Object> secretProperties = this.configOperations.read(forDatabase(this.elasticsearch)).getData();
|
||||
|
||||
assertThat(secretProperties).containsKeys("spring.elasticsearch.rest.username",
|
||||
"spring.elasticsearch.rest.password");
|
||||
|
||||
@@ -49,9 +49,8 @@ public class MongoSecretIntegrationTests extends IntegrationTestSupport {
|
||||
|
||||
private static final String MONGODB_HOST = "localhost";
|
||||
|
||||
private static final String ROOT_CREDENTIALS = String.format(
|
||||
"mongodb://springvault:springvault@%s:%d/admin?ssl=false", MONGODB_HOST,
|
||||
MONGODB_PORT);
|
||||
private static final String ROOT_CREDENTIALS = String
|
||||
.format("mongodb://springvault:springvault@%s:%d/admin?ssl=false", MONGODB_HOST, MONGODB_PORT);
|
||||
|
||||
private static final String ROLES = "[ \"readWrite\", { \"role\": \"read\", \"db\": \"admin\" } ]";
|
||||
|
||||
@@ -79,29 +78,24 @@ public class MongoSecretIntegrationTests extends IntegrationTestSupport {
|
||||
|
||||
VaultOperations vaultOperations = this.vaultRule.prepare().getVaultOperations();
|
||||
|
||||
vaultOperations.write(
|
||||
String.format("%s/config/connection", this.mongodb.getBackend()),
|
||||
vaultOperations.write(String.format("%s/config/connection", this.mongodb.getBackend()),
|
||||
Collections.singletonMap("uri", ROOT_CREDENTIALS));
|
||||
|
||||
Map<String, String> role = new HashMap<>();
|
||||
role.put("db", "admin");
|
||||
role.put("roles", ROLES);
|
||||
|
||||
vaultOperations.write(String.format("%s/roles/%s", this.mongodb.getBackend(),
|
||||
this.mongodb.getRole()), role);
|
||||
vaultOperations.write(String.format("%s/roles/%s", this.mongodb.getBackend(), this.mongodb.getRole()), role);
|
||||
|
||||
this.configOperations = new VaultConfigTemplate(vaultOperations,
|
||||
this.vaultProperties);
|
||||
this.configOperations = new VaultConfigTemplate(vaultOperations, this.vaultProperties);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateCredentialsCorrectly() {
|
||||
|
||||
Map<String, Object> secretProperties = this.configOperations
|
||||
.read(forDatabase(this.mongodb)).getData();
|
||||
Map<String, Object> secretProperties = this.configOperations.read(forDatabase(this.mongodb)).getData();
|
||||
|
||||
assertThat(secretProperties).containsKeys("spring.data.mongodb.username",
|
||||
"spring.data.mongodb.password");
|
||||
assertThat(secretProperties).containsKeys("spring.data.mongodb.username", "spring.data.mongodb.password");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ public class MySqlDatabaseSecretIntegrationTests extends IntegrationTestSupport
|
||||
|
||||
private static final String MYSQL_HOST = "localhost";
|
||||
|
||||
private static final String ROOT_CREDENTIALS = String
|
||||
.format("springvault:springvault@tcp(%s:%d)/", MYSQL_HOST, MYSQL_PORT);
|
||||
private static final String ROOT_CREDENTIALS = String.format("springvault:springvault@tcp(%s:%d)/", MYSQL_HOST,
|
||||
MYSQL_PORT);
|
||||
|
||||
private static final String CREATE_USER_AND_GRANT_SQL = "CREATE USER '{{name}}'@'%' IDENTIFIED BY '{{password}}';"
|
||||
+ "GRANT SELECT ON *.* TO '{{name}}'@'%';";
|
||||
@@ -86,28 +86,23 @@ public class MySqlDatabaseSecretIntegrationTests extends IntegrationTestSupport
|
||||
config.put("connection_url", ROOT_CREDENTIALS);
|
||||
config.put("allowed_roles", "readonly");
|
||||
|
||||
vaultOperations.write(String.format("%s/config/mysql", this.mySql.getBackend()),
|
||||
config);
|
||||
vaultOperations.write(String.format("%s/config/mysql", this.mySql.getBackend()), config);
|
||||
|
||||
Map<String, String> body = new HashMap<>();
|
||||
body.put("db_name", "mysql");
|
||||
body.put("creation_statements", CREATE_USER_AND_GRANT_SQL);
|
||||
|
||||
vaultOperations.write(String.format("%s/roles/%s", this.mySql.getBackend(),
|
||||
this.mySql.getRole()), body);
|
||||
vaultOperations.write(String.format("%s/roles/%s", this.mySql.getBackend(), this.mySql.getRole()), body);
|
||||
|
||||
this.configOperations = new VaultConfigTemplate(vaultOperations,
|
||||
this.vaultProperties);
|
||||
this.configOperations = new VaultConfigTemplate(vaultOperations, this.vaultProperties);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateCredentialsCorrectly() {
|
||||
|
||||
Map<String, Object> secretProperties = this.configOperations
|
||||
.read(forDatabase(this.mySql)).getData();
|
||||
Map<String, Object> secretProperties = this.configOperations.read(forDatabase(this.mySql)).getData();
|
||||
|
||||
assertThat(secretProperties).containsKeys("spring.datasource.username",
|
||||
"spring.datasource.password");
|
||||
assertThat(secretProperties).containsKeys("spring.datasource.username", "spring.datasource.password");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,8 +47,8 @@ public class MySqlSecretIntegrationTests extends IntegrationTestSupport {
|
||||
|
||||
private static final String MYSQL_HOST = "localhost";
|
||||
|
||||
private static final String ROOT_CREDENTIALS = String
|
||||
.format("springvault:springvault@tcp(%s:%d)/", MYSQL_HOST, MYSQL_PORT);
|
||||
private static final String ROOT_CREDENTIALS = String.format("springvault:springvault@tcp(%s:%d)/", MYSQL_HOST,
|
||||
MYSQL_PORT);
|
||||
|
||||
private static final String CREATE_USER_AND_GRANT_SQL = "CREATE USER '{{name}}'@'%' IDENTIFIED BY '{{password}}';"
|
||||
+ "GRANT SELECT ON *.* TO '{{name}}'@'%';";
|
||||
@@ -77,27 +77,21 @@ public class MySqlSecretIntegrationTests extends IntegrationTestSupport {
|
||||
|
||||
VaultOperations vaultOperations = this.vaultRule.prepare().getVaultOperations();
|
||||
|
||||
vaultOperations.write(
|
||||
String.format("%s/config/connection", this.mySql.getBackend()),
|
||||
vaultOperations.write(String.format("%s/config/connection", this.mySql.getBackend()),
|
||||
Collections.singletonMap("connection_url", ROOT_CREDENTIALS));
|
||||
|
||||
vaultOperations.write(
|
||||
String.format("%s/roles/%s", this.mySql.getBackend(),
|
||||
this.mySql.getRole()),
|
||||
vaultOperations.write(String.format("%s/roles/%s", this.mySql.getBackend(), this.mySql.getRole()),
|
||||
Collections.singletonMap("sql", CREATE_USER_AND_GRANT_SQL));
|
||||
|
||||
this.configOperations = new VaultConfigTemplate(vaultOperations,
|
||||
this.vaultProperties);
|
||||
this.configOperations = new VaultConfigTemplate(vaultOperations, this.vaultProperties);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateCredentialsCorrectly() {
|
||||
|
||||
Map<String, Object> secretProperties = this.configOperations
|
||||
.read(forDatabase(this.mySql)).getData();
|
||||
Map<String, Object> secretProperties = this.configOperations.read(forDatabase(this.mySql)).getData();
|
||||
|
||||
assertThat(secretProperties).containsKeys("spring.datasource.username",
|
||||
"spring.datasource.password");
|
||||
assertThat(secretProperties).containsKeys("spring.datasource.username", "spring.datasource.password");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,8 +50,7 @@ public class PostgreSqlSecretIntegrationTests extends IntegrationTestSupport {
|
||||
private static final int POSTGRES_PORT = 5432;
|
||||
|
||||
private static final String CONNECTION_URL = String.format(
|
||||
"postgresql://springvault:springvault@%s:%d/postgres?sslmode=disable",
|
||||
POSTGRES_HOST, POSTGRES_PORT);
|
||||
"postgresql://springvault:springvault@%s:%d/postgres?sslmode=disable", POSTGRES_HOST, POSTGRES_PORT);
|
||||
|
||||
private static final String CREATE_USER_AND_GRANT_SQL = "CREATE ROLE \"{{name}}\" WITH "
|
||||
+ "LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}';\n"
|
||||
@@ -81,28 +80,22 @@ public class PostgreSqlSecretIntegrationTests extends IntegrationTestSupport {
|
||||
|
||||
VaultOperations vaultOperations = this.vaultRule.prepare().getVaultOperations();
|
||||
|
||||
vaultOperations.write(
|
||||
String.format("%s/config/connection", this.postgreSql.getBackend()),
|
||||
vaultOperations.write(String.format("%s/config/connection", this.postgreSql.getBackend()),
|
||||
Collections.singletonMap("connection_url", CONNECTION_URL));
|
||||
|
||||
vaultOperations.write(
|
||||
String.format("%s/roles/%s", this.postgreSql.getBackend(),
|
||||
this.postgreSql.getRole()),
|
||||
vaultOperations.write(String.format("%s/roles/%s", this.postgreSql.getBackend(), this.postgreSql.getRole()),
|
||||
Collections.singletonMap("sql", CREATE_USER_AND_GRANT_SQL));
|
||||
|
||||
this.configOperations = new VaultConfigTemplate(vaultOperations,
|
||||
this.vaultProperties);
|
||||
this.configOperations = new VaultConfigTemplate(vaultOperations, this.vaultProperties);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateCredentialsCorrectly() {
|
||||
|
||||
Map<String, Object> secretProperties = this.configOperations
|
||||
.read(forDatabase(this.postgreSql)).getData();
|
||||
Map<String, Object> secretProperties = this.configOperations.read(forDatabase(this.postgreSql)).getData();
|
||||
|
||||
assertThat(secretProperties).containsKeys("spring.datasource.username",
|
||||
"spring.datasource.password");
|
||||
assertThat(secretProperties).containsKeys("spring.datasource.username", "spring.datasource.password");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -48,8 +48,7 @@ import static org.junit.Assume.assumeTrue;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = VaultConfigCassandraTests.TestApplication.class,
|
||||
properties = { "spring.cloud.vault.cassandra.enabled=true",
|
||||
"spring.cloud.vault.cassandra.role=readonly",
|
||||
properties = { "spring.cloud.vault.cassandra.enabled=true", "spring.cloud.vault.cassandra.role=readonly",
|
||||
"spring.data.cassandra.jmx-enabled=false" })
|
||||
public class VaultConfigCassandraTests {
|
||||
|
||||
@@ -96,8 +95,7 @@ public class VaultConfigCassandraTests {
|
||||
connection.put("password", CASSANDRA_PASSWORD);
|
||||
connection.put("protocol_version", 3);
|
||||
|
||||
vaultOperations.write(String.format("%s/config/connection", "cassandra"),
|
||||
connection);
|
||||
vaultOperations.write(String.format("%s/config/connection", "cassandra"), connection);
|
||||
|
||||
Map<String, String> role = new HashMap<>();
|
||||
|
||||
|
||||
@@ -39,11 +39,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = CustomBootstrapConfiguration.class, properties = {
|
||||
"VaultConfigDatabaseBootstrapConfigurationTests.custom.config=true",
|
||||
"spring.cloud.vault.mysql.role=foo", "spring.cloud.vault.mysql.enabled=true" })
|
||||
public class VaultConfigDatabaseBootstrapConfigurationTests
|
||||
extends IntegrationTestSupport {
|
||||
@SpringBootTest(classes = CustomBootstrapConfiguration.class,
|
||||
properties = { "VaultConfigDatabaseBootstrapConfigurationTests.custom.config=true",
|
||||
"spring.cloud.vault.mysql.role=foo", "spring.cloud.vault.mysql.enabled=true" })
|
||||
public class VaultConfigDatabaseBootstrapConfigurationTests extends IntegrationTestSupport {
|
||||
|
||||
@Autowired
|
||||
DatabaseSecretBackendMetadataFactory factory;
|
||||
@@ -70,10 +69,8 @@ public class VaultConfigDatabaseBootstrapConfigurationTests
|
||||
|
||||
return new DatabaseSecretBackendMetadataFactory() {
|
||||
@Override
|
||||
public SecretBackendMetadata createMetadata(
|
||||
DatabaseSecretProperties backendDescriptor) {
|
||||
return KeyValueSecretBackendMetadata
|
||||
.create(backendDescriptor.getRole());
|
||||
public SecretBackendMetadata createMetadata(DatabaseSecretProperties backendDescriptor) {
|
||||
return KeyValueSecretBackendMetadata.create(backendDescriptor.getRole());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -53,19 +53,16 @@ import static org.junit.Assume.assumeTrue;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = VaultConfigMongoTests.TestApplication.class,
|
||||
properties = { "spring.cloud.vault.mongodb.enabled=true",
|
||||
"spring.cloud.vault.mongodb.role=readonly",
|
||||
"spring.data.mongodb.url=mongodb://localhost",
|
||||
"spring.data.mongodb.database=admin" })
|
||||
properties = { "spring.cloud.vault.mongodb.enabled=true", "spring.cloud.vault.mongodb.role=readonly",
|
||||
"spring.data.mongodb.url=mongodb://localhost", "spring.data.mongodb.database=admin" })
|
||||
public class VaultConfigMongoTests {
|
||||
|
||||
private static final int MONGODB_PORT = 27017;
|
||||
|
||||
private static final String MONGODB_HOST = "localhost";
|
||||
|
||||
private static final String ROOT_CREDENTIALS = String.format(
|
||||
"mongodb://springvault:springvault@%s:%d/admin?ssl=false", MONGODB_HOST,
|
||||
MONGODB_PORT);
|
||||
private static final String ROOT_CREDENTIALS = String
|
||||
.format("mongodb://springvault:springvault@%s:%d/admin?ssl=false", MONGODB_HOST, MONGODB_PORT);
|
||||
|
||||
private static final String ROLES = "[ \"readWrite\", { \"role\": \"read\", \"db\": \"admin\" } ]";
|
||||
|
||||
@@ -89,8 +86,7 @@ public class VaultConfigMongoTests {
|
||||
VaultRule vaultRule = new VaultRule();
|
||||
vaultRule.before();
|
||||
|
||||
assumeTrue(vaultRule.prepare().getVersion()
|
||||
.isGreaterThanOrEqualTo(Version.parse("0.6.2")));
|
||||
assumeTrue(vaultRule.prepare().getVersion().isGreaterThanOrEqualTo(Version.parse("0.6.2")));
|
||||
|
||||
if (!vaultRule.prepare().hasSecretBackend("mongodb")) {
|
||||
vaultRule.prepare().mountSecret("mongodb");
|
||||
@@ -98,8 +94,7 @@ public class VaultConfigMongoTests {
|
||||
|
||||
VaultOperations vaultOperations = vaultRule.prepare().getVaultOperations();
|
||||
|
||||
vaultOperations.write("mongodb/config/connection",
|
||||
Collections.singletonMap("uri", ROOT_CREDENTIALS));
|
||||
vaultOperations.write("mongodb/config/connection", Collections.singletonMap("uri", ROOT_CREDENTIALS));
|
||||
|
||||
Map<String, String> role = new HashMap<>();
|
||||
role.put("db", "admin");
|
||||
@@ -113,8 +108,7 @@ public class VaultConfigMongoTests {
|
||||
|
||||
MongoDatabase mongoDatabase = this.mongoClient.getDatabase("admin");
|
||||
|
||||
List<Document> collections = mongoDatabase.listCollections()
|
||||
.into(new ArrayList<>());
|
||||
List<Document> collections = mongoDatabase.listCollections().into(new ArrayList<>());
|
||||
|
||||
for (Document collection : collections) {
|
||||
if (collection.getString("name").equals("hello")) {
|
||||
|
||||
@@ -51,8 +51,7 @@ import static org.junit.Assume.assumeTrue;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = VaultConfigMySqlDatabaseTests.TestApplication.class,
|
||||
properties = { "spring.cloud.vault.database.enabled=true",
|
||||
"spring.cloud.vault.database.role=readonly",
|
||||
properties = { "spring.cloud.vault.database.enabled=true", "spring.cloud.vault.database.role=readonly",
|
||||
"spring.datasource.url=jdbc:mysql://localhost:3306/mysql?useSSL=false&serverTimezone=UTC",
|
||||
"spring.main.allow-bean-definition-overriding=true" })
|
||||
public class VaultConfigMySqlDatabaseTests {
|
||||
@@ -61,8 +60,8 @@ public class VaultConfigMySqlDatabaseTests {
|
||||
|
||||
private static final String MYSQL_HOST = "localhost";
|
||||
|
||||
private static final String ROOT_CREDENTIALS = String
|
||||
.format("springvault:springvault@tcp(%s:%d)/", MYSQL_HOST, MYSQL_PORT);
|
||||
private static final String ROOT_CREDENTIALS = String.format("springvault:springvault@tcp(%s:%d)/", MYSQL_HOST,
|
||||
MYSQL_PORT);
|
||||
|
||||
private static final String CREATE_USER_AND_GRANT_SQL = "CREATE USER '{{name}}'@'%' IDENTIFIED BY '{{password}}';"
|
||||
+ "GRANT SELECT ON *.* TO '{{name}}'@'%';";
|
||||
@@ -86,8 +85,7 @@ public class VaultConfigMySqlDatabaseTests {
|
||||
vaultRule.before();
|
||||
|
||||
assumeTrue(CanConnect.to(new InetSocketAddress(MYSQL_HOST, MYSQL_PORT)));
|
||||
assumeTrue(vaultRule.prepare().getVersion()
|
||||
.isGreaterThanOrEqualTo(Version.parse("0.7.1")));
|
||||
assumeTrue(vaultRule.prepare().getVersion().isGreaterThanOrEqualTo(Version.parse("0.7.1")));
|
||||
|
||||
if (!vaultRule.prepare().hasSecretBackend("database")) {
|
||||
vaultRule.prepare().mountSecret("database");
|
||||
@@ -118,8 +116,7 @@ public class VaultConfigMySqlDatabaseTests {
|
||||
@Test
|
||||
public void shouldConnectUsingJdbcUrlConnection() throws SQLException {
|
||||
|
||||
String url = String.format("jdbc:mysql://%s?useSSL=false&serverTimezone=UTC",
|
||||
MYSQL_HOST);
|
||||
String url = String.format("jdbc:mysql://%s?useSSL=false&serverTimezone=UTC", MYSQL_HOST);
|
||||
DriverManager.getConnection(url, this.username, this.password).close();
|
||||
}
|
||||
|
||||
|
||||
@@ -48,18 +48,18 @@ import static org.junit.Assume.assumeTrue;
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = VaultConfigMySqlTests.TestApplication.class, properties = {
|
||||
"spring.cloud.vault.mysql.enabled=true", "spring.cloud.vault.mysql.role=readonly",
|
||||
"spring.datasource.url=jdbc:mysql://localhost:3306/mysql?useSSL=false&serverTimezone=UTC",
|
||||
"spring.main.allow-bean-definition-overriding=true" })
|
||||
@SpringBootTest(classes = VaultConfigMySqlTests.TestApplication.class,
|
||||
properties = { "spring.cloud.vault.mysql.enabled=true", "spring.cloud.vault.mysql.role=readonly",
|
||||
"spring.datasource.url=jdbc:mysql://localhost:3306/mysql?useSSL=false&serverTimezone=UTC",
|
||||
"spring.main.allow-bean-definition-overriding=true" })
|
||||
public class VaultConfigMySqlTests {
|
||||
|
||||
private static final int MYSQL_PORT = 3306;
|
||||
|
||||
private static final String MYSQL_HOST = "localhost";
|
||||
|
||||
private static final String ROOT_CREDENTIALS = String
|
||||
.format("springvault:springvault@tcp(%s:%d)/", MYSQL_HOST, MYSQL_PORT);
|
||||
private static final String ROOT_CREDENTIALS = String.format("springvault:springvault@tcp(%s:%d)/", MYSQL_HOST,
|
||||
MYSQL_PORT);
|
||||
|
||||
private static final String CREATE_USER_AND_GRANT_SQL = "CREATE USER '{{name}}'@'%' IDENTIFIED BY '{{password}}';"
|
||||
+ "GRANT SELECT ON *.* TO '{{name}}'@'%';";
|
||||
@@ -90,11 +90,9 @@ public class VaultConfigMySqlTests {
|
||||
|
||||
VaultOperations vaultOperations = vaultRule.prepare().getVaultOperations();
|
||||
|
||||
vaultOperations.write("mysql/config/connection",
|
||||
Collections.singletonMap("connection_url", ROOT_CREDENTIALS));
|
||||
vaultOperations.write("mysql/config/connection", Collections.singletonMap("connection_url", ROOT_CREDENTIALS));
|
||||
|
||||
vaultOperations.write("mysql/roles/readonly",
|
||||
Collections.singletonMap("sql", CREATE_USER_AND_GRANT_SQL));
|
||||
vaultOperations.write("mysql/roles/readonly", Collections.singletonMap("sql", CREATE_USER_AND_GRANT_SQL));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,8 +104,7 @@ public class VaultConfigMySqlTests {
|
||||
@Test
|
||||
public void shouldConnectUsingJdbcUrlConnection() throws SQLException {
|
||||
|
||||
String url = String.format("jdbc:mysql://%s?useSSL=false&serverTimezone=UTC",
|
||||
MYSQL_HOST);
|
||||
String url = String.format("jdbc:mysql://%s?useSSL=false&serverTimezone=UTC", MYSQL_HOST);
|
||||
DriverManager.getConnection(url, this.username, this.password).close();
|
||||
}
|
||||
|
||||
|
||||
@@ -50,11 +50,10 @@ import static org.junit.Assume.assumeTrue;
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = VaultConfigPostgreSqlTests.TestApplication.class, properties = {
|
||||
"spring.cloud.vault.postgresql.enabled=true",
|
||||
"spring.cloud.vault.postgresql.role=readonly",
|
||||
"spring.datasource.url=jdbc:postgresql://localhost:5432/postgres?ssl=false",
|
||||
"spring.main.allow-bean-definition-overriding=true" })
|
||||
@SpringBootTest(classes = VaultConfigPostgreSqlTests.TestApplication.class,
|
||||
properties = { "spring.cloud.vault.postgresql.enabled=true", "spring.cloud.vault.postgresql.role=readonly",
|
||||
"spring.datasource.url=jdbc:postgresql://localhost:5432/postgres?ssl=false",
|
||||
"spring.main.allow-bean-definition-overriding=true" })
|
||||
public class VaultConfigPostgreSqlTests {
|
||||
|
||||
private static final String POSTGRES_HOST = "localhost";
|
||||
@@ -62,8 +61,7 @@ public class VaultConfigPostgreSqlTests {
|
||||
private static final int POSTGRES_PORT = 5432;
|
||||
|
||||
private static final String CONNECTION_URL = String.format(
|
||||
"postgresql://springvault:springvault@%s:%d/postgres?sslmode=disable",
|
||||
POSTGRES_HOST, POSTGRES_PORT);
|
||||
"postgresql://springvault:springvault@%s:%d/postgres?sslmode=disable", POSTGRES_HOST, POSTGRES_PORT);
|
||||
|
||||
private static final String CREATE_USER_AND_GRANT_SQL = "CREATE ROLE \"{{name}}\" WITH "
|
||||
+ "LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}';\n"
|
||||
@@ -98,8 +96,7 @@ public class VaultConfigPostgreSqlTests {
|
||||
vaultOperations.write("postgresql/config/connection",
|
||||
Collections.singletonMap("connection_url", CONNECTION_URL));
|
||||
|
||||
vaultOperations.write("postgresql/roles/readonly",
|
||||
Collections.singletonMap("sql", CREATE_USER_AND_GRANT_SQL));
|
||||
vaultOperations.write("postgresql/roles/readonly", Collections.singletonMap("sql", CREATE_USER_AND_GRANT_SQL));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,8 +111,7 @@ public class VaultConfigPostgreSqlTests {
|
||||
@Test
|
||||
public void shouldConnectUsingJdbcUrlConnection() throws SQLException {
|
||||
|
||||
String url = String.format("jdbc:postgresql://%s:%d/postgres?ssl=false",
|
||||
POSTGRES_HOST, POSTGRES_PORT);
|
||||
String url = String.format("jdbc:postgresql://%s:%d/postgres?ssl=false", POSTGRES_HOST, POSTGRES_PORT);
|
||||
DriverManager.getConnection(url, this.username, this.password).close();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user