Polishing.
Upgrade to newer language constructs (try-with-resources, lambdas, diamond syntax), remove redundant throws. See gh-208.
This commit is contained in:
@@ -55,11 +55,9 @@ public class AwsSecretIntegrationTests extends IntegrationTestSupport {
|
||||
|
||||
/**
|
||||
* Initialize the aws secret backend.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
|
||||
assumeTrue(StringUtils.hasText(AWS_ACCESS_KEY)
|
||||
&& StringUtils.hasText(AWS_SECRET_KEY));
|
||||
|
||||
@@ -32,8 +32,8 @@ 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;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
/**
|
||||
* Integration tests using the aws secret backend. In case this test should fail because
|
||||
@@ -62,11 +62,9 @@ public class VaultConfigAwsTests {
|
||||
|
||||
/**
|
||||
* Initialize the aws secret backend.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
|
||||
assumeTrue(StringUtils.hasText(AWS_ACCESS_KEY)
|
||||
&& StringUtils.hasText(AWS_SECRET_KEY));
|
||||
@@ -97,7 +95,7 @@ public class VaultConfigAwsTests {
|
||||
String secretKey;
|
||||
|
||||
@Test
|
||||
public void shouldInitializeAwsProperties() throws Exception {
|
||||
public void shouldInitializeAwsProperties() {
|
||||
|
||||
assertThat(accessKey).isNotEmpty();
|
||||
assertThat(secretKey).isNotEmpty();
|
||||
|
||||
@@ -68,12 +68,10 @@ public class ConsulSecretIntegrationTests extends IntegrationTestSupport {
|
||||
private RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
/**
|
||||
* Initialize the postgresql secret backend.
|
||||
*
|
||||
* @throws Exception
|
||||
* Initialize the consul secret backend.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
|
||||
assumeTrue(CanConnect.to(new InetSocketAddress(CONSUL_HOST, CONSUL_PORT)));
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.cloud.vault.config.consul;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -41,8 +40,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.vault.core.VaultOperations;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.assertj.core.api.Java6Assertions.assertThat;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.assertj.core.api.Java6Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
/**
|
||||
* Integration tests using the consul secret backend. In case this test should fail
|
||||
@@ -72,11 +71,9 @@ public class VaultConfigConsulTests {
|
||||
|
||||
/**
|
||||
* Initialize the consul secret backend.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
|
||||
assumeTrue(CanConnect.to(new InetSocketAddress(CONSUL_HOST, CONSUL_PORT)));
|
||||
|
||||
@@ -112,7 +109,7 @@ public class VaultConfigConsulTests {
|
||||
String token;
|
||||
|
||||
@Test
|
||||
public void shouldHaveToken() throws SQLException {
|
||||
public void shouldHaveToken() {
|
||||
assertThat(token).isNotEmpty();
|
||||
}
|
||||
|
||||
|
||||
@@ -58,11 +58,9 @@ public class CassandraSecretIntegrationTests extends IntegrationTestSupport {
|
||||
|
||||
/**
|
||||
* Initialize cassandra secret backend.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
|
||||
assumeTrue(CanConnect.to(new InetSocketAddress(CASSANDRA_HOST, CASSANDRA_PORT)));
|
||||
|
||||
|
||||
@@ -56,11 +56,9 @@ public class MongoSecretIntegrationTests extends IntegrationTestSupport {
|
||||
|
||||
/**
|
||||
* Initialize the mongodb secret backend.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
|
||||
assumeTrue(CanConnect.to(new InetSocketAddress(MONGODB_HOST, MONGODB_PORT)));
|
||||
assumeTrue(prepare().getVersion().isGreaterThanOrEqualTo(Version.parse("0.6.2")));
|
||||
|
||||
@@ -58,11 +58,9 @@ public class MySqlDatabaseSecretIntegrationTests extends IntegrationTestSupport
|
||||
|
||||
/**
|
||||
* Initialize the mysql secret backend.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
|
||||
assumeTrue(CanConnect.to(new InetSocketAddress(MYSQL_HOST, MYSQL_PORT)));
|
||||
assumeTrue(prepare().getVersion().isGreaterThanOrEqualTo(Version.parse("0.7.1")));
|
||||
|
||||
@@ -56,11 +56,9 @@ public class MySqlSecretIntegrationTests extends IntegrationTestSupport {
|
||||
|
||||
/**
|
||||
* Initialize the mysql secret backend.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
|
||||
assumeTrue(CanConnect.to(new InetSocketAddress(MYSQL_HOST, MYSQL_PORT)));
|
||||
|
||||
|
||||
@@ -62,11 +62,9 @@ public class PostgreSqlSecretIntegrationTests extends IntegrationTestSupport {
|
||||
|
||||
/**
|
||||
* Initialize the postgresql secret backend.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
|
||||
assumeTrue(CanConnect.to(new InetSocketAddress(POSTGRES_HOST, POSTGRES_PORT)));
|
||||
|
||||
|
||||
@@ -15,14 +15,13 @@
|
||||
*/
|
||||
package org.springframework.cloud.vault.config.databases;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.PlainTextAuthProvider;
|
||||
import com.datastax.driver.core.Session;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -37,9 +36,8 @@ import org.springframework.cloud.vault.util.VaultRule;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.vault.core.VaultOperations;
|
||||
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.PlainTextAuthProvider;
|
||||
import com.datastax.driver.core.Session;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
/**
|
||||
* Integration tests using the cassandra secret backend. In case this test should fail
|
||||
@@ -66,11 +64,9 @@ public class VaultConfigCassandraTests {
|
||||
|
||||
/**
|
||||
* Initialize the cassandra secret backend.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
|
||||
assumeTrue(CanConnect.to(new InetSocketAddress(CASSANDRA_HOST, CASSANDRA_PORT)));
|
||||
|
||||
@@ -109,24 +105,24 @@ public class VaultConfigCassandraTests {
|
||||
Cluster cluster;
|
||||
|
||||
@Test
|
||||
public void shouldConnectUsingCluster() throws SQLException {
|
||||
public void shouldConnectUsingCluster() {
|
||||
cluster.connect().close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldUseAuthenticationSet() throws SQLException {
|
||||
public void shouldUseAuthenticationSet() {
|
||||
assertThat(cluster.getConfiguration().getProtocolOptions().getAuthProvider())
|
||||
.isInstanceOf(PlainTextAuthProvider.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldConnectUsingCassandraClient() throws SQLException {
|
||||
public void shouldConnectUsingCassandraClient() {
|
||||
|
||||
Cluster cluster = Cluster.builder().addContactPoint(CASSANDRA_HOST)
|
||||
.withAuthProvider(new PlainTextAuthProvider(username, password)).build();
|
||||
Session session = cluster.connect();
|
||||
session.close();
|
||||
cluster.close();
|
||||
try (Cluster cluster = Cluster.builder().addContactPoint(CASSANDRA_HOST)
|
||||
.withAuthProvider(new PlainTextAuthProvider(username, password)).build()) {
|
||||
Session session = cluster.connect();
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
||||
@SpringBootApplication
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.cloud.vault.config.databases;
|
||||
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -24,6 +22,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import org.bson.Document;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -40,8 +40,7 @@ import org.springframework.cloud.vault.util.Version;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.vault.core.VaultOperations;
|
||||
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
/**
|
||||
* Integration tests using the mongodb secret backend. In case this test should fail
|
||||
@@ -67,11 +66,9 @@ public class VaultConfigMongoTests {
|
||||
|
||||
/**
|
||||
* Initialize the mongo secret backend.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
|
||||
assumeTrue(CanConnect.to(new InetSocketAddress(MONGODB_HOST, MONGODB_PORT)));
|
||||
|
||||
@@ -112,7 +109,8 @@ public class VaultConfigMongoTests {
|
||||
MongoDatabase mongoDatabase = mongoClient.getDatabase("admin");
|
||||
|
||||
List<Document> collections = mongoDatabase.listCollections()
|
||||
.into(new ArrayList<Document>());
|
||||
.into(
|
||||
new ArrayList<>());
|
||||
|
||||
for (Document collection : collections) {
|
||||
if (collection.getString("name").equals("hello")) {
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.cloud.vault.util.Version;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.vault.core.VaultOperations;
|
||||
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
/**
|
||||
* Integration tests using the database secret backend. In case this test should fail
|
||||
@@ -64,11 +64,9 @@ public class VaultConfigMySqlDatabaseTests {
|
||||
|
||||
/**
|
||||
* Initialize the mysql secret backend.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
|
||||
VaultRule vaultRule = new VaultRule();
|
||||
vaultRule.before();
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.cloud.vault.config.databases;
|
||||
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
@@ -27,6 +25,7 @@ import javax.sql.DataSource;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -37,6 +36,8 @@ import org.springframework.cloud.vault.util.VaultRule;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.vault.core.VaultOperations;
|
||||
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
/**
|
||||
* Integration tests using the mysql secret backend. In case this test should fail because
|
||||
* of SSL make sure you run the test within the
|
||||
@@ -60,11 +61,9 @@ public class VaultConfigMySqlTests {
|
||||
|
||||
/**
|
||||
* Initialize the mysql secret backend.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
|
||||
assumeTrue(CanConnect.to(new InetSocketAddress(MYSQL_HOST, MYSQL_PORT)));
|
||||
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.vault.config.databases;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
@@ -30,6 +27,7 @@ import javax.sql.DataSource;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -40,6 +38,9 @@ import org.springframework.cloud.vault.util.VaultRule;
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* Integration tests using the postgresql secret backend. In case this test should fail
|
||||
* because of SSL make sure you run the test within the
|
||||
@@ -68,11 +69,9 @@ public class VaultConfigPostgreSqlTests {
|
||||
|
||||
/**
|
||||
* Initialize the postgresql secret backend.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
|
||||
assumeTrue(CanConnect.to(new InetSocketAddress(POSTGRES_HOST, POSTGRES_PORT)));
|
||||
|
||||
|
||||
@@ -60,11 +60,9 @@ public class RabbitMqSecretIntegrationTests extends IntegrationTestSupport {
|
||||
|
||||
/**
|
||||
* Initialize the rabbitmq secret backend.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
|
||||
assumeTrue(CanConnect
|
||||
.to(new InetSocketAddress(RABBITMQ_HOST, RABBITMQ_HTTP_MANAGEMENT_PORT)));
|
||||
|
||||
@@ -16,16 +16,17 @@
|
||||
|
||||
package org.springframework.cloud.vault.config.rabbitmq;
|
||||
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.rabbitmq.client.Connection;
|
||||
import com.rabbitmq.client.ConnectionFactory;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -37,9 +38,7 @@ import org.springframework.cloud.vault.util.Version;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.vault.core.VaultOperations;
|
||||
|
||||
import com.rabbitmq.client.Channel;
|
||||
import com.rabbitmq.client.Connection;
|
||||
import com.rabbitmq.client.ConnectionFactory;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
/**
|
||||
* Integration tests using the rabbitmq secret backend. In case this test should fail
|
||||
@@ -70,11 +69,9 @@ public class VaultConfigRabbitMqTests {
|
||||
|
||||
/**
|
||||
* Initialize the rabbitmq secret backend.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
|
||||
assumeTrue(CanConnect
|
||||
.to(new InetSocketAddress(RABBITMQ_HOST, RABBITMQ_HTTP_MANAGEMENT_PORT)));
|
||||
@@ -124,11 +121,10 @@ public class VaultConfigRabbitMqTests {
|
||||
factory.setPort(RABBITMQ_PORT);
|
||||
factory.setUsername(username);
|
||||
factory.setPassword(password);
|
||||
Connection connection = factory.newConnection();
|
||||
Channel channel = connection.createChannel();
|
||||
|
||||
channel.close();
|
||||
connection.close();
|
||||
try (Connection connection = factory.newConnection()) {
|
||||
connection.createChannel().close();
|
||||
}
|
||||
}
|
||||
|
||||
@SpringBootApplication
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.springframework.vault.core.env.LeaseAwareVaultPropertySource;
|
||||
import org.springframework.vault.core.lease.SecretLeaseContainer;
|
||||
import org.springframework.vault.core.lease.domain.RequestedSecret;
|
||||
import org.springframework.vault.core.lease.event.LeaseErrorListener;
|
||||
import org.springframework.vault.core.lease.event.SecretLeaseEvent;
|
||||
|
||||
/**
|
||||
* Extension to {@link LeasingVaultPropertySourceLocator} that creates
|
||||
@@ -118,13 +117,10 @@ class LeasingVaultPropertySourceLocator extends VaultPropertySourceLocatorSuppor
|
||||
|
||||
final AtomicReference<Exception> errorRef = new AtomicReference<>();
|
||||
|
||||
LeaseErrorListener errorListener = new LeaseErrorListener() {
|
||||
@Override
|
||||
public void onLeaseError(SecretLeaseEvent leaseEvent, Exception exception) {
|
||||
LeaseErrorListener errorListener = (leaseEvent, exception) -> {
|
||||
|
||||
if (leaseEvent.getSource() == secret) {
|
||||
errorRef.compareAndSet(null, exception);
|
||||
}
|
||||
if (leaseEvent.getSource() == secret) {
|
||||
errorRef.compareAndSet(null, exception);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public class VaultBootstrapPropertySourceConfiguration implements InitializingBe
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
public void afterPropertiesSet() {
|
||||
|
||||
this.vaultSecretBackendDescriptors = applicationContext.getBeansOfType(
|
||||
VaultSecretBackendDescriptor.class).values();
|
||||
|
||||
@@ -328,6 +328,6 @@ public class VaultProperties implements EnvironmentAware {
|
||||
}
|
||||
|
||||
public enum AuthenticationMethod {
|
||||
TOKEN, APPID, APPROLE, AWS_EC2, AWS_IAM, CERT, CUBBYHOLE, KUBERNETES;
|
||||
TOKEN, APPID, APPROLE, AWS_EC2, AWS_IAM, CERT, CUBBYHOLE, KUBERNETES
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.vault.config;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link GenericSecretBackendMetadata}.
|
||||
@@ -36,7 +36,7 @@ public class GenericSecretBackendMetadataUnitTests {
|
||||
public void shouldCreateDefaultContexts() {
|
||||
|
||||
List<String> contexts = GenericSecretBackendMetadata.buildContexts(properties,
|
||||
Collections.<String>emptyList());
|
||||
Collections.emptyList());
|
||||
|
||||
assertThat(contexts).hasSize(1).contains("application");
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class GenericSecretBackendMetadataUnitTests {
|
||||
properties.setApplicationName("my-app");
|
||||
|
||||
List<String> contexts = GenericSecretBackendMetadata.buildContexts(properties,
|
||||
Collections.<String>emptyList());
|
||||
Collections.emptyList());
|
||||
|
||||
assertThat(contexts).hasSize(2).containsSequence("my-app", "application");
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public class GenericSecretBackendMetadataUnitTests {
|
||||
properties.setDefaultContext("");
|
||||
|
||||
List<String> contexts = GenericSecretBackendMetadata.buildContexts(properties,
|
||||
Collections.<String>emptyList());
|
||||
Collections.emptyList());
|
||||
|
||||
assertThat(contexts).hasSize(1).containsSequence("my-app");
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public class GenericSecretBackendMetadataUnitTests {
|
||||
properties.setApplicationName("foo,bar");
|
||||
|
||||
List<String> contexts = GenericSecretBackendMetadata.buildContexts(properties,
|
||||
Collections.<String>emptyList());
|
||||
Collections.emptyList());
|
||||
|
||||
assertThat(contexts).hasSize(3).containsSequence("bar", "foo", "application");
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
public class PropertyNameTransformerUnitTests {
|
||||
|
||||
@Test
|
||||
public void shouldTranslateProperties() throws Exception {
|
||||
public void shouldTranslateProperties() {
|
||||
|
||||
PropertyNameTransformer transformer = new PropertyNameTransformer();
|
||||
transformer.addKeyTransformation("old-key", "new-key");
|
||||
@@ -44,7 +44,7 @@ public class PropertyNameTransformerUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAllowNullInput() throws Exception {
|
||||
public void shouldAllowNullInput() {
|
||||
|
||||
PropertyNameTransformer transformer = new PropertyNameTransformer();
|
||||
transformer.addKeyTransformation("old-key", "new-key");
|
||||
|
||||
@@ -50,7 +50,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
public class ReactiveVaultOperationsTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
|
||||
VaultRule vaultRule = new VaultRule();
|
||||
vaultRule.before();
|
||||
|
||||
@@ -42,7 +42,7 @@ import org.springframework.vault.authentication.ClientAuthentication;
|
||||
import org.springframework.vault.core.VaultOperations;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
@@ -56,7 +56,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class VaultConfigAppIdCustomMechanismTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
|
||||
VaultRule vaultRule = new VaultRule();
|
||||
vaultRule.before();
|
||||
@@ -84,14 +84,14 @@ public class VaultConfigAppIdCustomMechanismTests {
|
||||
vaultOperations.write("secret/" + appId,
|
||||
Collections.singletonMap("vault.value", appId));
|
||||
|
||||
Map<String, String> appIdData = new HashMap<String, String>();
|
||||
Map<String, String> appIdData = new HashMap<>();
|
||||
appIdData.put("value", "testpolicy"); // policy
|
||||
appIdData.put("display_name", "this is my test application");
|
||||
|
||||
vaultOperations.write(String.format("auth/app-id/map/app-id/%s", appId),
|
||||
appIdData);
|
||||
|
||||
Map<String, String> userIdData = new HashMap<String, String>();
|
||||
Map<String, String> userIdData = new HashMap<>();
|
||||
userIdData.put("value", appId); // name of the app-id
|
||||
userIdData.put("cidr_block", "0.0.0.0/0");
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ 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.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Integration test using config infrastructure with AppId authentication.
|
||||
@@ -53,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class VaultConfigAppIdTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
|
||||
VaultRule vaultRule = new VaultRule();
|
||||
vaultRule.before();
|
||||
@@ -82,14 +82,14 @@ public class VaultConfigAppIdTests {
|
||||
vaultOperations.write("secret/" + VaultConfigAppIdTests.class.getSimpleName(),
|
||||
Collections.singletonMap("vault.value", "foo"));
|
||||
|
||||
Map<String, String> appIdData = new HashMap<String, String>();
|
||||
Map<String, String> appIdData = new HashMap<>();
|
||||
appIdData.put("value", "testpolicy"); // policy
|
||||
appIdData.put("display_name", "this is my test application");
|
||||
|
||||
vaultOperations.write(String.format("auth/app-id/map/app-id/%s", appId),
|
||||
appIdData);
|
||||
|
||||
Map<String, String> userIdData = new HashMap<String, String>();
|
||||
Map<String, String> userIdData = new HashMap<>();
|
||||
userIdData.put("value", appId); // name of the app-id
|
||||
userIdData.put("cidr_block", "0.0.0.0/0");
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ 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.assertThat;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
/**
|
||||
* Integration test using config infrastructure with AppRole authentication.
|
||||
@@ -54,7 +54,7 @@ import static org.junit.Assume.assumeTrue;
|
||||
public class VaultConfigAppRoleTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
|
||||
VaultRule vaultRule = new VaultRule();
|
||||
vaultRule.before();
|
||||
@@ -84,7 +84,7 @@ public class VaultConfigAppRoleTests {
|
||||
vaultOperations.write("secret/" + VaultConfigAppRoleTests.class.getSimpleName(),
|
||||
Collections.singletonMap("vault.value", "foo"));
|
||||
|
||||
Map<String, String> withSecretId = new HashMap<String, String>();
|
||||
Map<String, String> withSecretId = new HashMap<>();
|
||||
withSecretId.put("policies", "testpolicy"); // policy
|
||||
withSecretId.put("bound_cidr_list", "0.0.0.0/0");
|
||||
withSecretId.put("bind_secret_id", "true");
|
||||
|
||||
@@ -31,13 +31,11 @@ import org.springframework.cloud.vault.util.Version;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.vault.core.RestOperationsCallback;
|
||||
import org.springframework.vault.core.VaultOperations;
|
||||
import org.springframework.vault.support.VaultResponse;
|
||||
import org.springframework.web.client.RestOperations;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
/**
|
||||
* Integration test using config infrastructure with Cubbyhole authentication.
|
||||
@@ -56,7 +54,7 @@ import static org.junit.Assume.assumeTrue;
|
||||
public class VaultConfigCubbyholeAuthenticationTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
|
||||
VaultRule vaultRule = new VaultRule();
|
||||
vaultRule.before();
|
||||
@@ -72,17 +70,13 @@ public class VaultConfigCubbyholeAuthenticationTests {
|
||||
VaultConfigCubbyholeAuthenticationTests.class.getSimpleName()));
|
||||
|
||||
VaultResponse vaultResponse = vaultOperations
|
||||
.doWithSession(new RestOperationsCallback<VaultResponse>() {
|
||||
@Override
|
||||
public VaultResponse doWithRestOperations(
|
||||
RestOperations restOperations) {
|
||||
.doWithSession(restOperations -> {
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("X-Vault-Wrap-TTL", "1h");
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("X-Vault-Wrap-TTL", "1h");
|
||||
|
||||
return restOperations.postForObject("/auth/token/create",
|
||||
new HttpEntity<Object>(headers), VaultResponse.class);
|
||||
}
|
||||
return restOperations.postForObject("/auth/token/create", new HttpEntity<>(
|
||||
headers), VaultResponse.class);
|
||||
});
|
||||
|
||||
String initialToken = vaultResponse.getWrapInfo().get("token");
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.vault.core.VaultTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Integration test using config infrastructure with token authentication.
|
||||
@@ -48,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class VaultConfigDisabledTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
|
||||
VaultRule vaultRule = new VaultRule();
|
||||
vaultRule.before();
|
||||
|
||||
@@ -29,7 +29,7 @@ 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.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Integration test using config infrastructure with token authentication.
|
||||
@@ -46,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class VaultConfigGenericBackendDisabledTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
|
||||
VaultRule vaultRule = new VaultRule();
|
||||
vaultRule.before();
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.vault.core.VaultTemplate;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Integration test using config infrastructure with token authentication.
|
||||
@@ -57,7 +57,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class VaultConfigTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
|
||||
VaultRule vaultRule = new VaultRule();
|
||||
vaultRule.before();
|
||||
|
||||
@@ -35,8 +35,8 @@ import org.springframework.cloud.vault.util.VaultRule;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.vault.core.VaultOperations;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.vault.util.Settings.findWorkDir;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.cloud.vault.util.Settings.*;
|
||||
|
||||
/**
|
||||
* Integration test using config infrastructure with TLS certificate authentication. In
|
||||
@@ -56,7 +56,7 @@ import static org.springframework.cloud.vault.util.Settings.findWorkDir;
|
||||
public class VaultConfigTlsCertAuthenticationTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
|
||||
VaultRule vaultRule = new VaultRule();
|
||||
vaultRule.before();
|
||||
|
||||
@@ -30,7 +30,7 @@ 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.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Integration test using config infrastructure with token authentication.
|
||||
@@ -49,7 +49,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class VaultConfigWithContextTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
|
||||
VaultRule vaultRule = new VaultRule();
|
||||
vaultRule.before();
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.vault.core.VaultOperations;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Integration test using config infrastructure with token authentication.
|
||||
@@ -48,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class VaultConfigWithVaultConfigurerTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
public static void beforeClass() {
|
||||
|
||||
VaultRule vaultRule = new VaultRule();
|
||||
vaultRule.before();
|
||||
@@ -83,13 +83,8 @@ public class VaultConfigWithVaultConfigurerTests {
|
||||
@ConditionalOnProperty("VaultConfigWithVaultConfigurerTests.custom.config")
|
||||
@Bean
|
||||
VaultConfigurer vaultConfigurer() {
|
||||
|
||||
return new VaultConfigurer() {
|
||||
@Override
|
||||
public void addSecretBackends(SecretBackendConfigurer configurer) {
|
||||
configurer.add("secret/VaultConfigWithVaultConfigurerTests");
|
||||
}
|
||||
};
|
||||
return configurer -> configurer
|
||||
.add("secret/VaultConfigWithVaultConfigurerTests");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.cloud.vault.config;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -25,6 +23,8 @@ import org.junit.Test;
|
||||
import org.springframework.cloud.vault.util.IntegrationTestSupport;
|
||||
import org.springframework.cloud.vault.util.Settings;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link VaultPropertySource}.
|
||||
*
|
||||
@@ -33,13 +33,13 @@ import org.springframework.cloud.vault.util.Settings;
|
||||
public class VaultPropertySourceIntegrationTests extends IntegrationTestSupport {
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
public void before() {
|
||||
prepare().getVaultOperations().write("secret/myapp",
|
||||
Collections.singletonMap("key", "value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReadValue() throws Exception {
|
||||
public void shouldReadValue() {
|
||||
|
||||
VaultProperties vaultProperties = Settings.createVaultProperties();
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.vault.util;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -37,8 +36,7 @@ public class CanConnect {
|
||||
*/
|
||||
public static boolean to(SocketAddress socketAddress) {
|
||||
|
||||
Socket socket = new Socket();
|
||||
try {
|
||||
try (Socket socket = new Socket()) {
|
||||
|
||||
socket.connect(socketAddress, (int) TimeUnit.SECONDS.toMillis(1));
|
||||
return true;
|
||||
@@ -46,12 +44,5 @@ public class CanConnect {
|
||||
catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
socket.close();
|
||||
}
|
||||
catch (IOException o_O) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.vault.util;
|
||||
|
||||
import org.junit.Rule;
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.vault.util;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@@ -41,7 +40,7 @@ public class TestRestTemplateFactory {
|
||||
|
||||
public static final VaultEndpoint TEST_VAULT_ENDPOINT = new VaultEndpoint();
|
||||
|
||||
private static final AtomicReference<ClientHttpRequestFactory> factoryCache = new AtomicReference<ClientHttpRequestFactory>();
|
||||
private static final AtomicReference<ClientHttpRequestFactory> factoryCache = new AtomicReference<>();
|
||||
|
||||
/**
|
||||
* Create a new {@link RestTemplate} using the {@link SslConfiguration}. The
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.cloud.vault.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
@@ -80,15 +79,10 @@ public class VaultRule extends ExternalResource {
|
||||
@Override
|
||||
public void before() {
|
||||
|
||||
Socket socket = null;
|
||||
try {
|
||||
|
||||
socket = new Socket();
|
||||
try (Socket socket = new Socket()) {
|
||||
|
||||
socket.connect(new InetSocketAddress(InetAddress.getByName("localhost"),
|
||||
vaultEndpoint.getPort()));
|
||||
socket.close();
|
||||
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(
|
||||
@@ -96,15 +90,6 @@ public class VaultRule extends ExternalResource {
|
||||
"Vault is not running on localhost:%d which is required to run a test using @Rule %s",
|
||||
vaultEndpoint.getPort(), getClass().getSimpleName()));
|
||||
}
|
||||
finally {
|
||||
if (socket != null) {
|
||||
try {
|
||||
socket.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.prepareVault.isAvailable()) {
|
||||
this.token = prepareVault.initializeVault();
|
||||
|
||||
@@ -46,8 +46,9 @@ public class Version implements Comparable<Version> {
|
||||
*/
|
||||
private Version(int... parts) {
|
||||
|
||||
Assert.notNull(parts);
|
||||
Assert.isTrue(parts.length > 0 && parts.length < 5);
|
||||
Assert.notNull(parts, "Parts must not be null!");
|
||||
Assert.isTrue(parts.length > 0 && parts.length < 5,
|
||||
"Parts must contain 1 to 5 segments!");
|
||||
|
||||
this.major = parts[0];
|
||||
this.minor = parts.length > 1 ? parts[1] : 0;
|
||||
@@ -220,7 +221,7 @@ public class Version implements Comparable<Version> {
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
List<Integer> digits = new ArrayList<Integer>();
|
||||
List<Integer> digits = new ArrayList<>();
|
||||
digits.add(major);
|
||||
digits.add(minor);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user