diff --git a/spring-cloud-vault-config-aws/src/test/java/org/springframework/cloud/vault/config/aws/VaultConfigAwsBootstrapConfigurationUnitTests.java b/spring-cloud-vault-config-aws/src/test/java/org/springframework/cloud/vault/config/aws/VaultConfigAwsBootstrapConfigurationUnitTests.java index e52c38036..670e3a2a2 100644 --- a/spring-cloud-vault-config-aws/src/test/java/org/springframework/cloud/vault/config/aws/VaultConfigAwsBootstrapConfigurationUnitTests.java +++ b/spring-cloud-vault-config-aws/src/test/java/org/springframework/cloud/vault/config/aws/VaultConfigAwsBootstrapConfigurationUnitTests.java @@ -39,7 +39,7 @@ void shouldCreateIamTokenSecretBackendMetadataFactory() { properties.setRole("readonly"); SecretBackendMetadataFactory factory = new VaultConfigAwsBootstrapConfiguration() - .awsSecretBackendMetadataFactory(); + .awsSecretBackendMetadataFactory(); SecretBackendMetadata metadata = factory.createMetadata(properties); @@ -55,7 +55,7 @@ void shouldCreateStsTokenSecretBackendMetadataFactory() { properties.setRole("readonly"); SecretBackendMetadataFactory factory = new VaultConfigAwsBootstrapConfiguration() - .awsSecretBackendMetadataFactory(); + .awsSecretBackendMetadataFactory(); SecretBackendMetadata metadata = factory.createMetadata(properties); @@ -73,7 +73,7 @@ void shouldCreateStsTokenSecretBackendMetadataFactoryWithTtlAndRoleArn() { properties.setRole("readonly"); SecretBackendMetadataFactory factory = new VaultConfigAwsBootstrapConfiguration() - .awsSecretBackendMetadataFactory(); + .awsSecretBackendMetadataFactory(); SecretBackendMetadata metadata = factory.createMetadata(properties); diff --git a/spring-cloud-vault-config-consul/src/test/java/org/springframework/cloud/vault/config/consul/VaultConfigConsulConfigDataTests.java b/spring-cloud-vault-config-consul/src/test/java/org/springframework/cloud/vault/config/consul/VaultConfigConsulConfigDataTests.java index 04d4144fe..2d1629e96 100644 --- a/spring-cloud-vault-config-consul/src/test/java/org/springframework/cloud/vault/config/consul/VaultConfigConsulConfigDataTests.java +++ b/spring-cloud-vault-config-consul/src/test/java/org/springframework/cloud/vault/config/consul/VaultConfigConsulConfigDataTests.java @@ -70,8 +70,9 @@ public void before() { role.put("max_ttl", "3s"); vaultOperations.write(String.format("%s/roles/%s", "consul", "short-readonly"), role); - this.vaultRule.prepare().getVaultOperations().write("secret/VaultConfigConsulConfigDataTests", - Collections.singletonMap("default-key", "default")); + this.vaultRule.prepare() + .getVaultOperations() + .write("secret/VaultConfigConsulConfigDataTests", Collections.singletonMap("default-key", "default")); SpringApplication application = new SpringApplication(VaultConfigConsulConfigDataTests.Config.class); application.setWebApplicationType(WebApplicationType.NONE); diff --git a/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/CouchbaseSecretIntegrationTests.java b/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/CouchbaseSecretIntegrationTests.java index a06a45955..46a9eefb3 100644 --- a/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/CouchbaseSecretIntegrationTests.java +++ b/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/CouchbaseSecretIntegrationTests.java @@ -94,7 +94,7 @@ public void setUp() { public void shouldCreateCredentialsCorrectly() { Map secretProperties = this.configOperations.read(forDatabase(this.couchbaseProperties)) - .getData(); + .getData(); assertThat(secretProperties).containsKeys("spring.couchbase.username", "spring.couchbase.password"); } diff --git a/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/MongoSecretIntegrationTests.java b/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/MongoSecretIntegrationTests.java index 5dccc277a..43cdab19e 100644 --- a/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/MongoSecretIntegrationTests.java +++ b/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/MongoSecretIntegrationTests.java @@ -50,7 +50,7 @@ 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); + .format("mongodb://springvault:springvault@%s:%d/admin?ssl=false", MONGODB_HOST, MONGODB_PORT); private static final String ROLES = "[ \"readWrite\", { \"role\": \"read\", \"db\": \"admin\" } ]"; diff --git a/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/PostgreSqlSecretIntegrationTests.java b/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/PostgreSqlSecretIntegrationTests.java index c2c6b379a..66f720291 100644 --- a/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/PostgreSqlSecretIntegrationTests.java +++ b/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/PostgreSqlSecretIntegrationTests.java @@ -49,8 +49,8 @@ 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); + private static final String CONNECTION_URL = String + .format("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" diff --git a/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/VaultConfigCassandraTests.java b/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/VaultConfigCassandraTests.java index 1b6960ece..173453d2b 100644 --- a/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/VaultConfigCassandraTests.java +++ b/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/VaultConfigCassandraTests.java @@ -113,9 +113,11 @@ public void shouldUseAuthenticatedSession() { @Test public void shouldConnectUsingCassandraClient() { - try (CqlSession session = CqlSession.builder().withLocalDatacenter("dc1") - .addContactPoint(new InetSocketAddress(CASSANDRA_HOST, CASSANDRA_PORT)) - .withAuthCredentials(this.username, this.password).build()) { + try (CqlSession session = CqlSession.builder() + .withLocalDatacenter("dc1") + .addContactPoint(new InetSocketAddress(CASSANDRA_HOST, CASSANDRA_PORT)) + .withAuthCredentials(this.username, this.password) + .build()) { assertThat(session.getMetadata().getKeyspace("system")).isNotEmpty(); } } diff --git a/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/VaultConfigDatabaseBootstrapConfigurationUnitTests.java b/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/VaultConfigDatabaseBootstrapConfigurationUnitTests.java index 6379cd0b4..c2185254b 100644 --- a/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/VaultConfigDatabaseBootstrapConfigurationUnitTests.java +++ b/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/VaultConfigDatabaseBootstrapConfigurationUnitTests.java @@ -33,7 +33,7 @@ public class VaultConfigDatabaseBootstrapConfigurationUnitTests { public void shouldConsiderCredentialPath() { VaultConfigDatabaseBootstrapConfiguration.DatabaseSecretBackendMetadataFactory factory = new VaultConfigDatabaseBootstrapConfiguration() - .databaseSecretBackendMetadataFactory(); + .databaseSecretBackendMetadataFactory(); VaultDatabaseProperties properties = new VaultDatabaseProperties(); properties.setStaticRole(true); diff --git a/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/VaultConfigMongoTests.java b/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/VaultConfigMongoTests.java index 78e36f4b7..bc0652b34 100644 --- a/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/VaultConfigMongoTests.java +++ b/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/VaultConfigMongoTests.java @@ -63,7 +63,7 @@ public class VaultConfigMongoTests { 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); + .format("mongodb://springvault:springvault@%s:%d/admin?ssl=false", MONGODB_HOST, MONGODB_PORT); private static final String ROLES = "[ \"readWrite\", { \"role\": \"read\", \"db\": \"admin\" } ]"; diff --git a/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/VaultConfigPostgreSqlTests.java b/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/VaultConfigPostgreSqlTests.java index 9bd00e0f7..278b50b7d 100644 --- a/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/VaultConfigPostgreSqlTests.java +++ b/spring-cloud-vault-config-databases/src/test/java/org/springframework/cloud/vault/config/databases/VaultConfigPostgreSqlTests.java @@ -60,8 +60,8 @@ 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); + private static final String CONNECTION_URL = String + .format("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" diff --git a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/ClientAuthenticationFactory.java b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/ClientAuthenticationFactory.java index 15078f85f..930d320eb 100644 --- a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/ClientAuthenticationFactory.java +++ b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/ClientAuthenticationFactory.java @@ -90,7 +90,7 @@ class ClientAuthenticationFactory { ClientAuthenticationFactory.class.getClassLoader()); private static final boolean googleCredentialsPresent = ClassUtils - .isPresent("com.google.auth.oauth2.GoogleCredentials", ClientAuthenticationFactory.class.getClassLoader()); + .isPresent("com.google.auth.oauth2.GoogleCredentials", ClientAuthenticationFactory.class.getClassLoader()); private final VaultProperties vaultProperties; @@ -159,9 +159,10 @@ private ClientAuthentication appIdAuthentication(VaultProperties vaultProperties Assert.hasText(appId.getUserId(), "UserId (spring.cloud.vault.app-id.user-id) must not be empty"); AppIdAuthenticationOptions authenticationOptions = AppIdAuthenticationOptions.builder() - .appId(vaultProperties.getApplicationName()) // - .path(appId.getAppIdPath()) // - .userIdMechanism(getAppIdMechanism(appId)).build(); + .appId(vaultProperties.getApplicationName()) // + .path(appId.getAppIdPath()) // + .userIdMechanism(getAppIdMechanism(appId)) + .build(); return new AppIdAuthentication(authenticationOptions, this.restOperations); } @@ -209,7 +210,7 @@ static AppRoleAuthenticationOptions getAppRoleAuthenticationOptions(VaultPropert AppRoleProperties appRole = vaultProperties.getAppRole(); AppRoleAuthenticationOptionsBuilder builder = AppRoleAuthenticationOptions.builder() - .path(appRole.getAppRolePath()); + .path(appRole.getAppRolePath()); if (StringUtils.hasText(appRole.getRole())) { builder.appRole(appRole.getRole()); @@ -265,11 +266,12 @@ private ClientAuthentication awsEc2Authentication(VaultProperties vaultPropertie Nonce nonce = StringUtils.hasText(awsEc2.getNonce()) ? Nonce.provided(awsEc2.getNonce().toCharArray()) : Nonce.generated(); - AwsEc2AuthenticationOptions authenticationOptions = AwsEc2AuthenticationOptions.builder().role(awsEc2.getRole()) // - .path(awsEc2.getAwsEc2Path()) // - .nonce(nonce) // - .identityDocumentUri(awsEc2.getIdentityDocument()) // - .build(); + AwsEc2AuthenticationOptions authenticationOptions = AwsEc2AuthenticationOptions.builder() + .role(awsEc2.getRole()) // + .path(awsEc2.getAwsEc2Path()) // + .nonce(nonce) // + .identityDocumentUri(awsEc2.getIdentityDocument()) // + .build(); return new AwsEc2Authentication(authenticationOptions, this.restOperations, this.externalRestOperations); } @@ -298,7 +300,7 @@ ClientAuthentication awsIamAuthentication(VaultProperties vaultProperties) { } builder.path(awsIam.getAwsPath()) // - .credentialsProvider(credentialsProvider); + .credentialsProvider(credentialsProvider); AwsIamAuthenticationOptions options = builder.credentialsProvider(credentialsProvider).build(); @@ -312,10 +314,11 @@ private ClientAuthentication azureMsiAuthentication(VaultProperties vaultPropert Assert.hasText(azureMsi.getRole(), "Azure role (spring.cloud.vault.azure-msi.role) must not be empty"); AzureMsiAuthenticationOptions options = AzureMsiAuthenticationOptions.builder() // - .role(azureMsi.getRole()).path(azureMsi.getAzurePath()) // - .instanceMetadataUri(azureMsi.getMetadataService()) // - .identityTokenServiceUri(azureMsi.getIdentityTokenService()) // - .build(); + .role(azureMsi.getRole()) + .path(azureMsi.getAzurePath()) // + .instanceMetadataUri(azureMsi.getMetadataService()) // + .identityTokenServiceUri(azureMsi.getIdentityTokenService()) // + .build(); return new AzureMsiAuthentication(options, this.restOperations, this.externalRestOperations); } @@ -326,9 +329,9 @@ private ClientAuthentication cubbyholeAuthentication() { "Initial Token (spring.cloud.vault.token) for Cubbyhole authentication must not be empty"); CubbyholeAuthenticationOptions options = CubbyholeAuthenticationOptions.builder() // - .wrapped() // - .initialToken(VaultToken.of(this.vaultProperties.getToken())) // - .build(); + .wrapped() // + .initialToken(VaultToken.of(this.vaultProperties.getToken())) // + .build(); return new CubbyholeAuthentication(options, this.restOperations); } @@ -340,7 +343,8 @@ private ClientAuthentication gcpGceAuthentication(VaultProperties vaultPropertie Assert.hasText(gcp.getRole(), "Role (spring.cloud.vault.gcp-gce.role) must not be empty"); GcpComputeAuthenticationOptionsBuilder builder = GcpComputeAuthenticationOptions.builder() - .path(gcp.getGcpPath()).role(gcp.getRole()); + .path(gcp.getGcpPath()) + .role(gcp.getRole()); if (StringUtils.hasText(gcp.getServiceAccount())) { builder.serviceAccount(gcp.getServiceAccount()); @@ -372,8 +376,10 @@ private ClientAuthentication kubernetesAuthentication(VaultProperties vaultPrope "Service account token file (spring.cloud.vault.kubernetes.service-account-token-file) must not be empty"); KubernetesAuthenticationOptions options = KubernetesAuthenticationOptions.builder() - .path(kubernetes.getKubernetesPath()).role(kubernetes.getRole()) - .jwtSupplier(new KubernetesServiceAccountTokenFile(kubernetes.getServiceAccountTokenFile())).build(); + .path(kubernetes.getKubernetesPath()) + .role(kubernetes.getRole()) + .jwtSupplier(new KubernetesServiceAccountTokenFile(kubernetes.getServiceAccountTokenFile())) + .build(); return new KubernetesAuthentication(options, this.restOperations); } @@ -387,7 +393,8 @@ private ClientAuthentication pcfAuthentication(VaultProperties vaultProperties) Assert.hasText(pcfProperties.getRole(), "Role (spring.cloud.vault.pcf.role) must not be empty"); PcfAuthenticationOptions.PcfAuthenticationOptionsBuilder builder = PcfAuthenticationOptions.builder() - .role(pcfProperties.getRole()).path(pcfProperties.getPcfPath()); + .role(pcfProperties.getRole()) + .path(pcfProperties.getPcfPath()); if (pcfProperties.getInstanceCertificate() != null) { builder.instanceCertificate(new ResourceCredentialSupplier(pcfProperties.getInstanceCertificate())); @@ -403,7 +410,8 @@ private ClientAuthentication pcfAuthentication(VaultProperties vaultProperties) private ClientAuthentication certificateAuthentication(VaultProperties vaultProperties) { ClientCertificateAuthenticationOptions options = ClientCertificateAuthenticationOptions.builder() - .path(vaultProperties.getSsl().getCertAuthPath()).build(); + .path(vaultProperties.getSsl().getCertAuthPath()) + .build(); return new ClientCertificateAuthentication(options, this.restOperations); } diff --git a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/GcpIamAuthenticationFactory.java b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/GcpIamAuthenticationFactory.java index 609c8b437..18e8d954f 100644 --- a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/GcpIamAuthenticationFactory.java +++ b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/GcpIamAuthenticationFactory.java @@ -49,8 +49,10 @@ static ClientAuthentication create(VaultProperties vaultProperties, RestOperatio Assert.hasText(gcp.getRole(), "Role (spring.cloud.vault.gcp-iam.role) must not be empty"); - GcpIamAuthenticationOptionsBuilder builder = GcpIamAuthenticationOptions.builder().path(gcp.getGcpPath()) - .role(gcp.getRole()).jwtValidity(gcp.getJwtValidity()); + GcpIamAuthenticationOptionsBuilder builder = GcpIamAuthenticationOptions.builder() + .path(gcp.getGcpPath()) + .role(gcp.getRole()) + .jwtValidity(gcp.getJwtValidity()); if (StringUtils.hasText(gcp.getProjectId())) { builder.projectId(gcp.getProjectId()); @@ -76,8 +78,8 @@ private static GoogleCredential getGoogleCredential(GcpIamProperties gcp) throws } if (StringUtils.hasText(credentialProperties.getEncodedKey())) { - return GoogleCredential.fromStream( - new ByteArrayInputStream(Base64.getDecoder().decode(credentialProperties.getEncodedKey()))); + return GoogleCredential + .fromStream(new ByteArrayInputStream(Base64.getDecoder().decode(credentialProperties.getEncodedKey()))); } return GoogleCredential.getApplicationDefault(); diff --git a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/GcpIamCredentialsAuthenticationFactory.java b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/GcpIamCredentialsAuthenticationFactory.java index 98b4cd96a..be35a3468 100644 --- a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/GcpIamCredentialsAuthenticationFactory.java +++ b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/GcpIamCredentialsAuthenticationFactory.java @@ -51,7 +51,9 @@ static ClientAuthentication create(VaultProperties vaultProperties, RestOperatio Assert.hasText(gcp.getRole(), "Role (spring.cloud.vault.gcp-iam.role) must not be empty"); GcpIamCredentialsAuthenticationOptionsBuilder builder = GcpIamCredentialsAuthenticationOptions.builder() - .path(gcp.getGcpPath()).role(gcp.getRole()).jwtValidity(gcp.getJwtValidity()); + .path(gcp.getGcpPath()) + .role(gcp.getRole()) + .jwtValidity(gcp.getJwtValidity()); if (StringUtils.hasText(gcp.getServiceAccountId())) { builder.serviceAccountId(gcp.getServiceAccountId()); @@ -73,8 +75,8 @@ private static GoogleCredentials getGoogleCredential(GcpIamProperties gcp) throw } if (StringUtils.hasText(credentialProperties.getEncodedKey())) { - return GoogleCredentials.fromStream( - new ByteArrayInputStream(Base64.getDecoder().decode(credentialProperties.getEncodedKey()))); + return GoogleCredentials + .fromStream(new ByteArrayInputStream(Base64.getDecoder().decode(credentialProperties.getEncodedKey()))); } return GoogleCredentials.getApplicationDefault(); diff --git a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/PropertySourceLocatorConfigurationFactory.java b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/PropertySourceLocatorConfigurationFactory.java index 74204486b..f20a8ea73 100644 --- a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/PropertySourceLocatorConfigurationFactory.java +++ b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/PropertySourceLocatorConfigurationFactory.java @@ -53,7 +53,7 @@ PropertySourceLocatorConfiguration getPropertySourceConfiguration( if (this.configurers.isEmpty()) { secretBackendConfigurer.registerDefaultKeyValueSecretBackends(true) - .registerDefaultDiscoveredSecretBackends(true); + .registerDefaultDiscoveredSecretBackends(true); } else { @@ -75,12 +75,12 @@ PropertySourceLocatorConfiguration getPropertySourceConfiguration( for (String context : contexts) { secretBackendConfigurer - .add(KeyValueSecretBackendMetadata.create(keyValueBackend.getBackend(), context)); + .add(KeyValueSecretBackendMetadata.create(keyValueBackend.getBackend(), context)); } } Collection backendAccessors = SecretBackendFactories - .createSecretBackendMetadata(this.vaultSecretBackendDescriptors, this.factories); + .createSecretBackendMetadata(this.vaultSecretBackendDescriptors, this.factories); backendAccessors.forEach(secretBackendConfigurer::add); } @@ -88,7 +88,7 @@ PropertySourceLocatorConfiguration getPropertySourceConfiguration( if (secretBackendConfigurer.isRegisterDefaultDiscoveredSecretBackends()) { Collection backendAccessors = SecretBackendFactories - .createSecretBackendMetadata(this.vaultSecretBackendDescriptors, this.factories); + .createSecretBackendMetadata(this.vaultSecretBackendDescriptors, this.factories); backendAccessors.forEach(secretBackendConfigurer::add); } diff --git a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultBootstrapPropertySourceConfiguration.java b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultBootstrapPropertySourceConfiguration.java index ef985dc5f..f1e25bdd5 100644 --- a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultBootstrapPropertySourceConfiguration.java +++ b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultBootstrapPropertySourceConfiguration.java @@ -81,13 +81,14 @@ public VaultBootstrapPropertySourceConfiguration(VaultProperties vaultProperties public void afterPropertiesSet() { this.vaultSecretBackendDescriptors = this.applicationContext.getBeansOfType(VaultSecretBackendDescriptor.class) - .values(); + .values(); this.vaultSecretBackendDescriptorFactories = this.applicationContext - .getBeansOfType(VaultSecretBackendDescriptorFactory.class).values(); + .getBeansOfType(VaultSecretBackendDescriptorFactory.class) + .values(); this.factories = (Collection) this.applicationContext.getBeansOfType(SecretBackendMetadataFactory.class) - .values(); + .values(); } @Bean @@ -101,7 +102,7 @@ public PropertySourceLocator vaultPropertySourceLocator(VaultOperations operatio VaultConfigTemplate vaultConfigTemplate = new VaultConfigTemplate(operations, vaultProperties); Collection vaultConfigurers = this.applicationContext.getBeansOfType(VaultConfigurer.class) - .values(); + .values(); List descriptors = new ArrayList<>(this.vaultSecretBackendDescriptors); this.vaultSecretBackendDescriptorFactories.forEach(it -> descriptors.addAll(it.create())); diff --git a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultConfigDataLoader.java b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultConfigDataLoader.java index 7e4cb5e84..643a340d4 100644 --- a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultConfigDataLoader.java +++ b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultConfigDataLoader.java @@ -150,7 +150,7 @@ private ConfigData loadConfigData(VaultConfigLocation location, ConfigurableBoot bootstrap.addCloseListener(event -> { ((ApplicationEventPublisherAware) location.getSecretBackendMetadata()) - .setApplicationEventPublisher(event.getApplicationContext()); + .setApplicationEventPublisher(event.getApplicationContext()); }); } @@ -502,7 +502,7 @@ void registerClientAuthentication() { registerIfAbsent(this.bootstrap, "clientAuthentication", ClientAuthentication.class, ctx -> { ClientHttpRequestFactory factory = this.bootstrap.get(ClientFactoryWrapper.class) - .getClientHttpRequestFactory(); + .getClientHttpRequestFactory(); RestTemplate externalRestTemplate = new RestTemplate(factory); @@ -546,7 +546,7 @@ static class ReactiveInfrastructure { this.bootstrap = bootstrap; this.configuration = new VaultReactiveConfiguration(vaultProperties); this.endpointProvider = SimpleVaultEndpointProvider - .of(new VaultConfiguration(vaultProperties).createVaultEndpoint()); + .of(new VaultConfiguration(vaultProperties).createVaultEndpoint()); this.logFactory = logFactory; } @@ -601,7 +601,7 @@ void registerReactiveSessionManager() { void registerSessionManager() { registerIfAbsent(this.bootstrap, "vaultSessionManager", SessionManager.class, ctx -> { SessionManager sessionManager = this.configuration - .createSessionManager(ctx.get(ReactiveSessionManager.class)); + .createSessionManager(ctx.get(ReactiveSessionManager.class)); reconfigureLogger(sessionManager, this.logFactory); return sessionManager; }); diff --git a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultConfigDataLocationResolver.java b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultConfigDataLocationResolver.java index c24d5894e..b125ebcc6 100644 --- a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultConfigDataLocationResolver.java +++ b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultConfigDataLocationResolver.java @@ -109,8 +109,9 @@ public List resolveProfileSpecific(ConfigDataLocationResolv if (location.getValue().equals(VaultConfigLocation.VAULT_PREFIX) || location.getValue().equals(VaultConfigLocation.VAULT_PREFIX + "//")) { List sorted = getSecretBackends(context, profiles); - return sorted.stream().map(it -> new VaultConfigLocation(it, location.isOptional())) - .collect(Collectors.toList()); + return sorted.stream() + .map(it -> new VaultConfigLocation(it, location.isOptional())) + .collect(Collectors.toList()); } String contextPath = location.getValue().substring(VaultConfigLocation.VAULT_PREFIX.length()); @@ -139,11 +140,12 @@ private static void registerVaultProperties(ConfigDataLocationResolverContext co context.getBootstrapContext().registerIfAbsent(VaultProperties.class, ignore -> { - VaultProperties vaultProperties = context.getBinder().bindOrCreate(VaultProperties.PREFIX, - VaultProperties.class); + VaultProperties vaultProperties = context.getBinder() + .bindOrCreate(VaultProperties.PREFIX, VaultProperties.class); - vaultProperties.setApplicationName(context.getBinder().bind("spring.application.name", String.class) - .orElse(vaultProperties.getApplicationName())); + vaultProperties.setApplicationName(context.getBinder() + .bind("spring.application.name", String.class) + .orElse(vaultProperties.getApplicationName())); return vaultProperties; }); @@ -187,15 +189,15 @@ private static VaultKeyValueBackendProperties getKeyValueProperties(ConfigDataLo Profiles profiles) { VaultKeyValueBackendProperties kvProperties = context.getBinder() - .bindOrCreate(VaultKeyValueBackendProperties.PREFIX, VaultKeyValueBackendProperties.class); + .bindOrCreate(VaultKeyValueBackendProperties.PREFIX, VaultKeyValueBackendProperties.class); Binder binder = context.getBinder(); kvProperties.setApplicationName(binder.bind("spring.cloud.vault.kv.application-name", String.class) - .orElseGet(() -> binder.bind("spring.cloud.vault.application-name", String.class) - .orElseGet(() -> binder.bind("spring.application.name", String.class).orElse("")))); + .orElseGet(() -> binder.bind("spring.cloud.vault.application-name", String.class) + .orElseGet(() -> binder.bind("spring.application.name", String.class).orElse("")))); kvProperties.setProfiles(binder.bind("spring.cloud.vault.kv.profiles", Bindable.listOf(String.class)) - .orElseGet(profiles::getActive)); + .orElseGet(profiles::getActive)); return kvProperties; } diff --git a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultConfiguration.java b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultConfiguration.java index 7f40390b0..e7fa91f26 100644 --- a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultConfiguration.java +++ b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultConfiguration.java @@ -156,8 +156,9 @@ VaultEndpoint createVaultEndpoint(ServiceInstance server) { RestTemplateBuilder createRestTemplateBuilder(ClientHttpRequestFactory requestFactory, VaultEndpointProvider endpointProvider, List customizers, List> requestCustomizers) { - RestTemplateBuilder builder = RestTemplateBuilder.builder().requestFactory(requestFactory) - .endpointProvider(endpointProvider); + RestTemplateBuilder builder = RestTemplateBuilder.builder() + .requestFactory(requestFactory) + .endpointProvider(endpointProvider); customizers.forEach(builder::customizers); requestCustomizers.forEach(builder::requestCustomizers); diff --git a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultObservationAutoConfiguration.java b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultObservationAutoConfiguration.java index 138750464..fe2fc6910 100644 --- a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultObservationAutoConfiguration.java +++ b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultObservationAutoConfiguration.java @@ -44,7 +44,8 @@ public class VaultObservationAutoConfiguration { @ConditionalOnSingleCandidate(ObservationRegistry.class) public RestTemplateCustomizer observationVaultRestTemplateCustomizer(ObservationRegistry observationRegistry) { return restTemplate -> new ObservationRestTemplateCustomizer(observationRegistry, - new DefaultClientRequestObservationConvention()).customize(restTemplate); + new DefaultClientRequestObservationConvention()) + .customize(restTemplate); } } diff --git a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultReactiveAutoConfiguration.java b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultReactiveAutoConfiguration.java index 99ed128a3..97d1ae8a1 100644 --- a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultReactiveAutoConfiguration.java +++ b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultReactiveAutoConfiguration.java @@ -124,7 +124,7 @@ public VaultReactiveAutoConfiguration(@Nullable ConfigurableApplicationContext a if (this.reactiveEndpointProvider == null) { this.endpointProvider = endpointProvider.getIfAvailable(() -> SimpleVaultEndpointProvider - .of(new VaultConfiguration(vaultProperties).createVaultEndpoint())); + .of(new VaultConfiguration(vaultProperties).createVaultEndpoint())); } else { this.endpointProvider = null; diff --git a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultReactiveConfiguration.java b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultReactiveConfiguration.java index aaf01481a..057ade9b6 100644 --- a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultReactiveConfiguration.java +++ b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultReactiveConfiguration.java @@ -79,8 +79,9 @@ ClientHttpConnector createClientHttpConnector() { WebClientBuilder createWebClientBuilder(ClientHttpConnector connector, ReactiveVaultEndpointProvider endpointProvider, List customizers) { - WebClientBuilder builder = WebClientBuilder.builder().httpConnector(connector) - .endpointProvider(endpointProvider); + WebClientBuilder builder = WebClientBuilder.builder() + .httpConnector(connector) + .endpointProvider(endpointProvider); return applyCustomizer(customizers, builder); } @@ -88,8 +89,9 @@ WebClientBuilder createWebClientBuilder(ClientHttpConnector connector, WebClientBuilder createWebClientBuilder(ClientHttpConnector connector, VaultEndpointProvider endpointProvider, List customizers) { - WebClientBuilder builder = WebClientBuilder.builder().httpConnector(connector) - .endpointProvider(endpointProvider); + WebClientBuilder builder = WebClientBuilder.builder() + .httpConnector(connector) + .endpointProvider(endpointProvider); return applyCustomizer(customizers, builder); } diff --git a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultReactiveHealthIndicator.java b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultReactiveHealthIndicator.java index 646c2e381..5ccb1065b 100644 --- a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultReactiveHealthIndicator.java +++ b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultReactiveHealthIndicator.java @@ -72,10 +72,10 @@ private static Health getHealth(Builder builder, VaultHealthImpl vaultHealthResp protected Mono doHealthCheck(Builder builder) { return this.vaultOperations - .doWithVault((it) -> it.get().uri("sys/health").header(VaultHttpHeaders.VAULT_NAMESPACE, "").exchange()) - .flatMap((it) -> it.bodyToMono(VaultHealthImpl.class)) - .onErrorResume(WebClientResponseException.class, VaultReactiveHealthIndicator::deserializeError) - .map((vaultHealthResponse) -> getHealth(builder, vaultHealthResponse)); + .doWithVault((it) -> it.get().uri("sys/health").header(VaultHttpHeaders.VAULT_NAMESPACE, "").exchange()) + .flatMap((it) -> it.bodyToMono(VaultHealthImpl.class)) + .onErrorResume(WebClientResponseException.class, VaultReactiveHealthIndicator::deserializeError) + .map((vaultHealthResponse) -> getHealth(builder, vaultHealthResponse)); } @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultReactiveObservationAutoConfiguration.java b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultReactiveObservationAutoConfiguration.java index 5cae12da1..856200775 100644 --- a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultReactiveObservationAutoConfiguration.java +++ b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultReactiveObservationAutoConfiguration.java @@ -46,7 +46,8 @@ public class VaultReactiveObservationAutoConfiguration { @ConditionalOnSingleCandidate(ObservationRegistry.class) public WebClientCustomizer observationVaultWebClientCustomizer(ObservationRegistry observationRegistry) { return webClientBuilder -> new ObservationWebClientCustomizer(observationRegistry, - new DefaultClientRequestObservationConvention()).customize(webClientBuilder); + new DefaultClientRequestObservationConvention()) + .customize(webClientBuilder); } } diff --git a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultRuntimeHints.java b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultRuntimeHints.java index 7ea30695b..44054070c 100644 --- a/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultRuntimeHints.java +++ b/spring-cloud-vault-config/src/main/java/org/springframework/cloud/vault/config/VaultRuntimeHints.java @@ -47,15 +47,19 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) { ReflectionHints reflection = hints.reflection(); // reflection required for ConfigDataLoader, early logging capture - reflection.registerTypes(Arrays.asList(SimpleSessionManager.class, LifecycleAwareSessionManager.class, - LifecycleAwareSessionManagerSupport.class, ClientHttpRequestFactoryFactory.class, - org.springframework.vault.core.env.VaultPropertySource.class, LeaseAwareVaultPropertySource.class) - .stream().map(TypeReference::of).collect(Collectors.toList()), - builder -> builder.withMembers(MemberCategory.DECLARED_FIELDS)); + reflection.registerTypes(Arrays + .asList(SimpleSessionManager.class, LifecycleAwareSessionManager.class, + LifecycleAwareSessionManagerSupport.class, ClientHttpRequestFactoryFactory.class, + org.springframework.vault.core.env.VaultPropertySource.class, LeaseAwareVaultPropertySource.class) + .stream() + .map(TypeReference::of) + .collect(Collectors.toList()), builder -> builder.withMembers(MemberCategory.DECLARED_FIELDS)); reflection.registerTypes( - Arrays.asList(VaultKeyValueBackendProperties.class).stream().map(TypeReference::of) - .collect(Collectors.toList()), + Arrays.asList(VaultKeyValueBackendProperties.class) + .stream() + .map(TypeReference::of) + .collect(Collectors.toList()), builder -> builder.withMembers(MemberCategory.DECLARED_FIELDS, MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)); @@ -69,15 +73,14 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) { builder -> builder.withMembers(MemberCategory.DECLARED_FIELDS)); reflection.registerType(TypeReference - .of("org.springframework.cloud.vault.config.VaultReactiveConfiguration$ReactiveSessionManagerAdapter"), + .of("org.springframework.cloud.vault.config.VaultReactiveConfiguration$ReactiveSessionManagerAdapter"), builder -> builder.withMembers(MemberCategory.DECLARED_FIELDS)); if (VaultConfigDataLoader.webclientPresent && VaultConfigDataLoader.reactorPresent) { - reflection - .registerTypes( - Arrays.asList(ReactiveLifecycleAwareSessionManager.class).stream().map(TypeReference::of) - .collect(Collectors.toList()), - builder -> builder.withMembers(MemberCategory.DECLARED_FIELDS)); + reflection.registerTypes(Arrays.asList(ReactiveLifecycleAwareSessionManager.class) + .stream() + .map(TypeReference::of) + .collect(Collectors.toList()), builder -> builder.withMembers(MemberCategory.DECLARED_FIELDS)); } // presence checks @@ -96,14 +99,16 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) { List pluggableDescriptors = new ArrayList<>(); pluggableDescriptors - .addAll(SpringFactoriesLoader.loadFactories(SecretBackendMetadataFactory.class, classLoader)); + .addAll(SpringFactoriesLoader.loadFactories(SecretBackendMetadataFactory.class, classLoader)); pluggableDescriptors - .addAll(SpringFactoriesLoader.loadFactories(VaultSecretBackendDescriptor.class, classLoader)); + .addAll(SpringFactoriesLoader.loadFactories(VaultSecretBackendDescriptor.class, classLoader)); pluggableDescriptors - .addAll(SpringFactoriesLoader.loadFactories(VaultSecretBackendDescriptorFactory.class, classLoader)); + .addAll(SpringFactoriesLoader.loadFactories(VaultSecretBackendDescriptorFactory.class, classLoader)); - List pluggableDescriptorReferences = pluggableDescriptors.stream().map(Object::getClass) - .map(TypeReference::of).collect(Collectors.toList()); + List pluggableDescriptorReferences = pluggableDescriptors.stream() + .map(Object::getClass) + .map(TypeReference::of) + .collect(Collectors.toList()); reflection.registerTypes(pluggableDescriptorReferences, builder -> { builder.withMembers(MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS, diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ApplicationFailFastTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ApplicationFailFastTests.java index 73e9dd08f..1c63db14d 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ApplicationFailFastTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ApplicationFailFastTests.java @@ -37,9 +37,9 @@ public class ApplicationFailFastTests { @Test public void contextLoadsWithFailFastUsingLeasing() { try { - new SpringApplicationBuilder().sources(ApplicationFailFastTests.class).run("--server.port=0", - "--spring.cloud.bootstrap.enabled=true", "--spring.cloud.vault.failFast=true", - "--spring.cloud.vault.config.lifecycle.enabled=true", "--spring.cloud.vault.port=9999"); + new SpringApplicationBuilder().sources(ApplicationFailFastTests.class) + .run("--server.port=0", "--spring.cloud.bootstrap.enabled=true", "--spring.cloud.vault.failFast=true", + "--spring.cloud.vault.config.lifecycle.enabled=true", "--spring.cloud.vault.port=9999"); fail("failFast option did not produce an exception"); } catch (Exception e) { @@ -50,10 +50,10 @@ public void contextLoadsWithFailFastUsingLeasing() { @Test public void contextLoadsWithFailFastWithoutLeasing() { try { - new SpringApplicationBuilder().sources(ApplicationFailFastTests.class).run("--server.port=0", - "--spring.cloud.bootstrap.enabled=true", "--spring.cloud.vault.failFast=true", - "--spring.cloud.vault.config.lifecycle.enabled=false", - "--spring.cloud.vault.session.lifecycle.enabled=false", "--spring.cloud.vault.port=9999"); + new SpringApplicationBuilder().sources(ApplicationFailFastTests.class) + .run("--server.port=0", "--spring.cloud.bootstrap.enabled=true", "--spring.cloud.vault.failFast=true", + "--spring.cloud.vault.config.lifecycle.enabled=false", + "--spring.cloud.vault.session.lifecycle.enabled=false", "--spring.cloud.vault.port=9999"); fail("failFast option did not produce an exception"); } catch (Exception e) { @@ -64,9 +64,9 @@ public void contextLoadsWithFailFastWithoutLeasing() { @Test @Ignore("Fails because of method errors in Discovery health check") public void contextLoadsWithoutFailFast() { - new SpringApplicationBuilder().sources(ApplicationFailFastTests.class).run("--server.port=0", - "--spring.cloud.bootstrap.enabled=true", "--spring.cloud.vault.failFast=false", - "--spring.cloud.vault.port=9999"); + new SpringApplicationBuilder().sources(ApplicationFailFastTests.class) + .run("--server.port=0", "--spring.cloud.bootstrap.enabled=true", "--spring.cloud.vault.failFast=false", + "--spring.cloud.vault.port=9999"); } } diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ClientAuthenticationFactoryUnitTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ClientAuthenticationFactoryUnitTests.java index c80ece70e..2841b45ad 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ClientAuthenticationFactoryUnitTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ClientAuthenticationFactoryUnitTests.java @@ -69,7 +69,7 @@ public void shouldSupportAwsIam() { new RestTemplate()); AwsIamAuthentication authentication = (AwsIamAuthentication) factory.awsIamAuthentication(properties); AwsIamAuthenticationOptions options = (AwsIamAuthenticationOptions) ReflectionTestUtils - .getField(authentication, "options"); + .getField(authentication, "options"); assertThat(options.getRegionProvider().getRegion()).isEqualTo(Region.AWS_GLOBAL); } @@ -177,7 +177,7 @@ public void shouldRejectUnconfiguredRoleId() { VaultProperties properties = new VaultProperties(); assertThatThrownBy(() -> ClientAuthenticationFactory.getAppRoleAuthenticationOptions(properties)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(IllegalArgumentException.class); } @Test @@ -187,7 +187,7 @@ public void shouldRejectUnconfiguredRoleIdIfRoleNameSet() { properties.getAppRole().setRole("my-role"); assertThatThrownBy(() -> ClientAuthenticationFactory.getAppRoleAuthenticationOptions(properties)) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(IllegalArgumentException.class); } @Test @@ -200,7 +200,8 @@ public void shouldSupportPcfAuthentication() { properties.getPcf().setInstanceCertificate(new ClassPathResource("bootstrap.yml")); ClientAuthentication clientAuthentication = new ClientAuthenticationFactory(properties, new RestTemplate(), - new RestTemplate()).createClientAuthentication(); + new RestTemplate()) + .createClientAuthentication(); assertThat(clientAuthentication).isInstanceOf(PcfAuthentication.class); } @@ -213,7 +214,8 @@ public void shouldSupportSslCertificateAuthentication() { properties.getSsl().setCertAuthPath("bert"); ClientAuthentication clientAuthentication = new ClientAuthenticationFactory(properties, new RestTemplate(), - new RestTemplate()).createClientAuthentication(); + new RestTemplate()) + .createClientAuthentication(); assertThat(clientAuthentication).isInstanceOf(ClientCertificateAuthentication.class); } @@ -229,7 +231,8 @@ public void shouldSupportTokenFromFile() throws IOException { StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE); try { ClientAuthentication clientAuthentication = new ClientAuthenticationFactory(properties, new RestTemplate(), - new RestTemplate()).createClientAuthentication(); + new RestTemplate()) + .createClientAuthentication(); assertThat(clientAuthentication).isInstanceOf(TokenAuthentication.class); VaultToken token = clientAuthentication.login(); diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ConfigDataShutdownTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ConfigDataShutdownTests.java index 640d9c399..b4740b997 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ConfigDataShutdownTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ConfigDataShutdownTests.java @@ -39,8 +39,8 @@ public class ConfigDataShutdownTests extends IntegrationTestSupport { @Test public void contextShutdownDestroysSecretLeaseContainer() { ConfigurableApplicationContext context = new SpringApplicationBuilder().sources(ConfigDataShutdownTests.class) - .run("--server.port=0", "--spring.cloud.bootstrap.enabled=false", "--spring.cloud.vault.failFast=true", - "--spring.cloud.vault.config.lifecycle.enabled=true", "--spring.config.import=vault://"); + .run("--server.port=0", "--spring.cloud.bootstrap.enabled=false", "--spring.cloud.vault.failFast=true", + "--spring.cloud.vault.config.lifecycle.enabled=true", "--spring.config.import=vault://"); SecretLeaseContainer container = context.getBean(SecretLeaseContainer.class); diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/DiscoveryClientVaultBootstrapConfigurationTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/DiscoveryClientVaultBootstrapConfigurationTests.java index c870d6173..1982651b7 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/DiscoveryClientVaultBootstrapConfigurationTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/DiscoveryClientVaultBootstrapConfigurationTests.java @@ -50,42 +50,42 @@ public class DiscoveryClientVaultBootstrapConfigurationTests { @Test public void shouldRegisterDefaultBeans() { - this.contextRunner - .withUserConfiguration(DiscoveryConfiguration.class).withPropertyValues("spring.cloud.vault.token=foo", - "spring.cloud.vault.discovery.enabled=true", "spring.cloud.bootstrap.enabled=true") - .run(context -> { - - assertThat(context.getBean(VaultServiceInstanceProvider.class)) - .isInstanceOf(DiscoveryClientVaultServiceInstanceProvider.class); - - VaultEndpointProvider endpointProvider = context.getBean(VaultEndpointProvider.class); - VaultEndpoint vaultEndpoint = endpointProvider.getVaultEndpoint(); - assertThat(vaultEndpoint.getPort()).isEqualTo(1234); - }); + this.contextRunner.withUserConfiguration(DiscoveryConfiguration.class) + .withPropertyValues("spring.cloud.vault.token=foo", "spring.cloud.vault.discovery.enabled=true", + "spring.cloud.bootstrap.enabled=true") + .run(context -> { + + assertThat(context.getBean(VaultServiceInstanceProvider.class)) + .isInstanceOf(DiscoveryClientVaultServiceInstanceProvider.class); + + VaultEndpointProvider endpointProvider = context.getBean(VaultEndpointProvider.class); + VaultEndpoint vaultEndpoint = endpointProvider.getVaultEndpoint(); + assertThat(vaultEndpoint.getPort()).isEqualTo(1234); + }); } @Test public void shouldNotRegisterBeansIfDiscoveryDisabled() { - this.contextRunner - .withUserConfiguration(DiscoveryConfiguration.class).withPropertyValues("spring.cloud.vault.token=foo", - "spring.cloud.vault.discovery.enabled=false", "spring.cloud.bootstrap.enabled=true") - .run(context -> { + this.contextRunner.withUserConfiguration(DiscoveryConfiguration.class) + .withPropertyValues("spring.cloud.vault.token=foo", "spring.cloud.vault.discovery.enabled=false", + "spring.cloud.bootstrap.enabled=true") + .run(context -> { - assertThat(context.getBeanNamesForType(VaultServiceInstanceProvider.class)).isEmpty(); - }); + assertThat(context.getBeanNamesForType(VaultServiceInstanceProvider.class)).isEmpty(); + }); } @Test public void shouldNotRegisterBeansIfVaultDisabled() { this.contextRunner.withUserConfiguration(DiscoveryConfiguration.class) - .withPropertyValues("spring.cloud.vault.token=foo", "spring.cloud.vault.enabled=false", - "spring.cloud.bootstrap.enabled=true") - .run(context -> { + .withPropertyValues("spring.cloud.vault.token=foo", "spring.cloud.vault.enabled=false", + "spring.cloud.bootstrap.enabled=true") + .run(context -> { - assertThat(context.getBeanNamesForType(VaultServiceInstanceProvider.class)).isEmpty(); - }); + assertThat(context.getBeanNamesForType(VaultServiceInstanceProvider.class)).isEmpty(); + }); } @@ -97,7 +97,7 @@ DiscoveryClient discoveryClient() { DiscoveryClient mock = Mockito.mock(DiscoveryClient.class); when(mock.getInstances(anyString())) - .thenReturn(Collections.singletonList(new SimpleServiceInstance(URI.create("https://foo:1234")))); + .thenReturn(Collections.singletonList(new SimpleServiceInstance(URI.create("https://foo:1234")))); return mock; } diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/KeyValueSecretBackendMetadataUnitTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/KeyValueSecretBackendMetadataUnitTests.java index 68ed66c0a..efb6aea51 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/KeyValueSecretBackendMetadataUnitTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/KeyValueSecretBackendMetadataUnitTests.java @@ -59,8 +59,9 @@ public void shouldCreateDefaultForAppNameAndDefaultContextWithProfiles() { List contexts = KeyValueSecretBackendMetadata.buildContexts(this.properties, Arrays.asList("cloud", "local")); - assertThat(contexts).hasSize(6).containsSequence("my-app/local", "my-app/cloud", "my-app", "application/local", - "application/cloud", "application"); + assertThat(contexts).hasSize(6) + .containsSequence("my-app/local", "my-app/cloud", "my-app", "application/local", "application/cloud", + "application"); } @Test @@ -92,8 +93,9 @@ public void shouldCreateContextsWithProfile() { List contexts = KeyValueSecretBackendMetadata.buildContexts(this.properties, Arrays.asList("cloud", "local")); - assertThat(contexts).hasSize(9).containsSequence("bar/local", "bar/cloud", "bar", "foo/local", "foo/cloud", - "foo", "application/local", "application/cloud", "application"); + assertThat(contexts).hasSize(9) + .containsSequence("bar/local", "bar/cloud", "bar", "foo/local", "foo/cloud", "foo", "application/local", + "application/cloud", "application"); } } diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/KeyValueSecretIntegrationTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/KeyValueSecretIntegrationTests.java index 09f0035fa..1b53b76a7 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/KeyValueSecretIntegrationTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/KeyValueSecretIntegrationTests.java @@ -51,7 +51,8 @@ public void setUp() { public void shouldReturnSecretsCorrectly() { Map secretProperties = this.configOperations - .read(KeyValueSecretBackendMetadata.create("secret", "app-name")).getData(); + .read(KeyValueSecretBackendMetadata.create("secret", "app-name")) + .getData(); assertThat(secretProperties).containsAllEntriesOf(createExpectedMap()); } diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/LeasingVaultPropertySourceLocatorUnitTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/LeasingVaultPropertySourceLocatorUnitTests.java index 389d34599..26819abe3 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/LeasingVaultPropertySourceLocatorUnitTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/LeasingVaultPropertySourceLocatorUnitTests.java @@ -98,7 +98,7 @@ public void shouldLocateLeaseAwareSources() { verify(this.secretLeaseContainer).addRequestedSecret(rotating); verify(this.secretLeaseContainer) - .addRequestedSecret(RequestedSecret.renewable("database/mysql/creds/readonly")); + .addRequestedSecret(RequestedSecret.renewable("database/mysql/creds/readonly")); } } diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/PropertyNameTransformerUnitTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/PropertyNameTransformerUnitTests.java index 7885dabdd..8e9f39815 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/PropertyNameTransformerUnitTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/PropertyNameTransformerUnitTests.java @@ -40,8 +40,8 @@ public void shouldTranslateProperties() { map.put("old-key", "value"); map.put("other-key", "other-value"); - assertThat(transformer.transformProperties(map)).containsEntry("new-key", "value").containsEntry("other-key", - "other-value"); + assertThat(transformer.transformProperties(map)).containsEntry("new-key", "value") + .containsEntry("other-key", "other-value"); } } diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ReactiveDiscoveryClientVaultBootstrapConfigurationTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ReactiveDiscoveryClientVaultBootstrapConfigurationTests.java index cdd87245c..829568ca5 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ReactiveDiscoveryClientVaultBootstrapConfigurationTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ReactiveDiscoveryClientVaultBootstrapConfigurationTests.java @@ -47,68 +47,66 @@ public class ReactiveDiscoveryClientVaultBootstrapConfigurationTests { private ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations - .of(ReactiveDiscoveryClientVaultBootstrapConfiguration.class, VaultBootstrapConfiguration.class)); + .of(ReactiveDiscoveryClientVaultBootstrapConfiguration.class, VaultBootstrapConfiguration.class)); @Test public void shouldRegisterDefaultBeans() { this.contextRunner.withUserConfiguration(ReactiveDiscoveryConfiguration.class) - .withPropertyValues("spring.cloud.vault.token=foo", "spring.cloud.vault.discovery.enabled=true", - "spring.cloud.bootstrap.enabled=true") - .run(context -> { + .withPropertyValues("spring.cloud.vault.token=foo", "spring.cloud.vault.discovery.enabled=true", + "spring.cloud.bootstrap.enabled=true") + .run(context -> { - assertThat(context).hasSingleBean(ReactiveVaultEndpointProvider.class); + assertThat(context).hasSingleBean(ReactiveVaultEndpointProvider.class); - ReactiveVaultEndpointProvider endpointProvider = context - .getBean(ReactiveVaultEndpointProvider.class); + ReactiveVaultEndpointProvider endpointProvider = context.getBean(ReactiveVaultEndpointProvider.class); - endpointProvider.getVaultEndpoint().as(StepVerifier::create).assertNext(actual -> { - assertThat(actual.getPort()).isEqualTo(1234); - }).verifyComplete(); - }); + endpointProvider.getVaultEndpoint().as(StepVerifier::create).assertNext(actual -> { + assertThat(actual.getPort()).isEqualTo(1234); + }).verifyComplete(); + }); } @Test public void shouldRegisterVaultEndpointAdapterBean() { this.contextRunner.withUserConfiguration(BridgedDiscoveryConfiguration.class) - .withPropertyValues("spring.cloud.vault.token=foo", "spring.cloud.vault.discovery.enabled=true", - "spring.cloud.bootstrap.enabled=true") - .run(context -> { + .withPropertyValues("spring.cloud.vault.token=foo", "spring.cloud.vault.discovery.enabled=true", + "spring.cloud.bootstrap.enabled=true") + .run(context -> { - assertThat(context).hasSingleBean(ReactiveVaultEndpointProvider.class); + assertThat(context).hasSingleBean(ReactiveVaultEndpointProvider.class); - ReactiveVaultEndpointProvider endpointProvider = context - .getBean(ReactiveVaultEndpointProvider.class); + ReactiveVaultEndpointProvider endpointProvider = context.getBean(ReactiveVaultEndpointProvider.class); - endpointProvider.getVaultEndpoint().as(StepVerifier::create).assertNext(actual -> { - assertThat(actual.getPort()).isEqualTo(1234); - }).verifyComplete(); - }); + endpointProvider.getVaultEndpoint().as(StepVerifier::create).assertNext(actual -> { + assertThat(actual.getPort()).isEqualTo(1234); + }).verifyComplete(); + }); } @Test public void shouldNotRegisterBeansIfDiscoveryDisabled() { this.contextRunner.withUserConfiguration(ReactiveDiscoveryConfiguration.class) - .withPropertyValues("spring.cloud.vault.token=foo", "spring.cloud.vault.discovery.enabled=false", - "spring.cloud.bootstrap.enabled=true") - .run(context -> { + .withPropertyValues("spring.cloud.vault.token=foo", "spring.cloud.vault.discovery.enabled=false", + "spring.cloud.bootstrap.enabled=true") + .run(context -> { - assertThat(context.getBeanNamesForType(ReactiveVaultEndpointProvider.class)).isEmpty(); - }); + assertThat(context.getBeanNamesForType(ReactiveVaultEndpointProvider.class)).isEmpty(); + }); } @Test public void shouldNotRegisterBeansIfVaultDisabled() { this.contextRunner.withUserConfiguration(ReactiveDiscoveryConfiguration.class) - .withPropertyValues("spring.cloud.vault.token=foo", "spring.cloud.vault.enabled=false", - "spring.cloud.bootstrap.enabled=true") - .run(context -> { + .withPropertyValues("spring.cloud.vault.token=foo", "spring.cloud.vault.enabled=false", + "spring.cloud.bootstrap.enabled=true") + .run(context -> { - assertThat(context.getBeanNamesForType(ReactiveVaultEndpointProvider.class)).isEmpty(); - }); + assertThat(context.getBeanNamesForType(ReactiveVaultEndpointProvider.class)).isEmpty(); + }); } @@ -120,7 +118,7 @@ ReactiveDiscoveryClient reactiveDiscoveryClient() { ReactiveDiscoveryClient mock = Mockito.mock(ReactiveDiscoveryClient.class); when(mock.getInstances(anyString())) - .thenReturn(Flux.just(new SimpleServiceInstance(URI.create("https://foo:1234")))); + .thenReturn(Flux.just(new SimpleServiceInstance(URI.create("https://foo:1234")))); return mock; } diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ReactiveVaultBootstrapConfigurationTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ReactiveVaultBootstrapConfigurationTests.java index 7932b2968..f076322b3 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ReactiveVaultBootstrapConfigurationTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/ReactiveVaultBootstrapConfigurationTests.java @@ -41,15 +41,17 @@ public class ReactiveVaultBootstrapConfigurationTests { @Test public void shouldConfigureWithoutAuthentication() { - this.contextRunner.withPropertyValues("spring.cloud.vault.kv.enabled=false", - "spring.cloud.vault.authentication=NONE", "spring.cloud.bootstrap.enabled=true").run(context -> { - - assertThat(context).doesNotHaveBean(SessionManager.class); - assertThat(context).doesNotHaveBean(ClientAuthentication.class); - assertThat(context).doesNotHaveBean(VaultTokenSupplier.class); - assertThat(context).doesNotHaveBean(ReactiveSessionManager.class); - assertThat(context).hasSingleBean(ReactiveVaultTemplate.class); - }); + this.contextRunner + .withPropertyValues("spring.cloud.vault.kv.enabled=false", "spring.cloud.vault.authentication=NONE", + "spring.cloud.bootstrap.enabled=true") + .run(context -> { + + assertThat(context).doesNotHaveBean(SessionManager.class); + assertThat(context).doesNotHaveBean(ClientAuthentication.class); + assertThat(context).doesNotHaveBean(VaultTokenSupplier.class); + assertThat(context).doesNotHaveBean(ReactiveSessionManager.class); + assertThat(context).hasSingleBean(ReactiveVaultTemplate.class); + }); } } diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultBootstrapConfigurationTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultBootstrapConfigurationTests.java index 855379e19..3ff744d17 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultBootstrapConfigurationTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultBootstrapConfigurationTests.java @@ -40,66 +40,70 @@ public class VaultBootstrapConfigurationTests { private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(VaultBootstrapConfiguration.class)); + .withConfiguration(AutoConfigurations.of(VaultBootstrapConfiguration.class)); @Test public void shouldConfigureWithoutAuthentication() { - this.contextRunner.withPropertyValues("spring.cloud.vault.kv.enabled=true", - "spring.cloud.vault.authentication=NONE", "spring.cloud.bootstrap.enabled=true").run(context -> { - - assertThat(context).doesNotHaveBean(SessionManager.class); - assertThat(context).doesNotHaveBean(ClientAuthentication.class); - assertThat(context).hasSingleBean(VaultTemplate.class); - assertThat(context).hasSingleBean(RestTemplateFactory.class); - }); + this.contextRunner + .withPropertyValues("spring.cloud.vault.kv.enabled=true", "spring.cloud.vault.authentication=NONE", + "spring.cloud.bootstrap.enabled=true") + .run(context -> { + + assertThat(context).doesNotHaveBean(SessionManager.class); + assertThat(context).doesNotHaveBean(ClientAuthentication.class); + assertThat(context).hasSingleBean(VaultTemplate.class); + assertThat(context).hasSingleBean(RestTemplateFactory.class); + }); } @Test public void shouldApplySslSettings() { - this.contextRunner.withPropertyValues("spring.cloud.vault.kv.enabled=false", - "spring.cloud.vault.authentication=NONE", "spring.cloud.bootstrap.enabled=true", - "spring.cloud.vault.ssl.enabled-protocols=TLSv1.2,TLSv1.3", - "spring.cloud.vault.ssl.enabled-cipher-suites=one,two").run(context -> { + this.contextRunner + .withPropertyValues("spring.cloud.vault.kv.enabled=false", "spring.cloud.vault.authentication=NONE", + "spring.cloud.bootstrap.enabled=true", "spring.cloud.vault.ssl.enabled-protocols=TLSv1.2,TLSv1.3", + "spring.cloud.vault.ssl.enabled-cipher-suites=one,two") + .run(context -> { - VaultProperties properties = context.getBean(VaultProperties.class); + VaultProperties properties = context.getBean(VaultProperties.class); - SslConfiguration sslConfiguration = VaultConfiguration.createSslConfiguration(properties.getSsl()); + SslConfiguration sslConfiguration = VaultConfiguration.createSslConfiguration(properties.getSsl()); - assertThat(sslConfiguration.getEnabledProtocols()).containsExactly("TLSv1.2", "TLSv1.3"); - assertThat(sslConfiguration.getEnabledCipherSuites()).containsExactly("one", "two"); - }); + assertThat(sslConfiguration.getEnabledProtocols()).containsExactly("TLSv1.2", "TLSv1.3"); + assertThat(sslConfiguration.getEnabledCipherSuites()).containsExactly("one", "two"); + }); } @Test public void shouldDisableSessionManagement() { this.contextRunner - .withPropertyValues("spring.cloud.vault.kv.enabled=false", "spring.cloud.vault.token=foo", - "spring.cloud.vault.session.lifecycle.enabled=false", "spring.cloud.bootstrap.enabled=true") - .run(context -> { + .withPropertyValues("spring.cloud.vault.kv.enabled=false", "spring.cloud.vault.token=foo", + "spring.cloud.vault.session.lifecycle.enabled=false", "spring.cloud.bootstrap.enabled=true") + .run(context -> { - SessionManager bean = context.getBean(SessionManager.class); - assertThat(bean).isExactlyInstanceOf(SimpleSessionManager.class); - }); + SessionManager bean = context.getBean(SessionManager.class); + assertThat(bean).isExactlyInstanceOf(SimpleSessionManager.class); + }); } @Test public void shouldConfigureSessionManagement() { - this.contextRunner.withPropertyValues("spring.cloud.vault.kv.enabled=false", "spring.cloud.vault.token=foo", - "spring.cloud.vault.session.lifecycle.refresh-before-expiry=11s", - "spring.cloud.vault.session.lifecycle.expiry-threshold=12s", "spring.cloud.bootstrap.enabled=true") - .run(context -> { + this.contextRunner + .withPropertyValues("spring.cloud.vault.kv.enabled=false", "spring.cloud.vault.token=foo", + "spring.cloud.vault.session.lifecycle.refresh-before-expiry=11s", + "spring.cloud.vault.session.lifecycle.expiry-threshold=12s", "spring.cloud.bootstrap.enabled=true") + .run(context -> { - SessionManager bean = context.getBean(SessionManager.class); + SessionManager bean = context.getBean(SessionManager.class); - Object refreshTrigger = ReflectionTestUtils.getField(bean, "refreshTrigger"); + Object refreshTrigger = ReflectionTestUtils.getField(bean, "refreshTrigger"); - assertThat(refreshTrigger).hasFieldOrPropertyWithValue("duration", Duration.ofSeconds(11)) - .hasFieldOrPropertyWithValue("expiryThreshold", Duration.ofSeconds(12)); - }); + assertThat(refreshTrigger).hasFieldOrPropertyWithValue("duration", Duration.ofSeconds(11)) + .hasFieldOrPropertyWithValue("expiryThreshold", Duration.ofSeconds(12)); + }); } } diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultBootstrapPropertySourceConfigurationTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultBootstrapPropertySourceConfigurationTests.java index c482fb8d3..62b7fc6e3 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultBootstrapPropertySourceConfigurationTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultBootstrapPropertySourceConfigurationTests.java @@ -45,44 +45,43 @@ public class VaultBootstrapPropertySourceConfigurationTests { private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(VaultBootstrapPropertySourceConfiguration.class)); + .withConfiguration(AutoConfigurations.of(VaultBootstrapPropertySourceConfiguration.class)); @Test public void shouldConfigureExpiryTimeoutsAndStrategy() { this.contextRunner - .withUserConfiguration(MockSecretLeaseContainerConfiguration.class, - MockVaultOperationsConfiguration.class) - .withAllowBeanDefinitionOverriding(true) - .withPropertyValues("spring.cloud.vault.kv.enabled=false", - "spring.cloud.vault.config.lifecycle.expiry-threshold=5m", - "spring.cloud.vault.config.lifecycle.min-renewal=6m", - "spring.cloud.vault.config.lifecycle.lease-endpoints=Leases", - "spring.cloud.vault.config.lifecycle.lease-strategy=retain-on-error", - "spring.cloud.bootstrap.enabled=true") - .run(context -> { - - SecretLeaseContainer container = context.getBean(SecretLeaseContainer.class); - verify(container).setExpiryThreshold(Duration.ofMinutes(5)); - verify(container).setMinRenewal(Duration.ofMinutes(6)); - verify(container).setLeaseEndpoints(LeaseEndpoints.Leases); - verify(container).setLeaseStrategy(LeaseStrategy.retainOnError()); - }); + .withUserConfiguration(MockSecretLeaseContainerConfiguration.class, MockVaultOperationsConfiguration.class) + .withAllowBeanDefinitionOverriding(true) + .withPropertyValues("spring.cloud.vault.kv.enabled=false", + "spring.cloud.vault.config.lifecycle.expiry-threshold=5m", + "spring.cloud.vault.config.lifecycle.min-renewal=6m", + "spring.cloud.vault.config.lifecycle.lease-endpoints=Leases", + "spring.cloud.vault.config.lifecycle.lease-strategy=retain-on-error", + "spring.cloud.bootstrap.enabled=true") + .run(context -> { + + SecretLeaseContainer container = context.getBean(SecretLeaseContainer.class); + verify(container).setExpiryThreshold(Duration.ofMinutes(5)); + verify(container).setMinRenewal(Duration.ofMinutes(6)); + verify(container).setLeaseEndpoints(LeaseEndpoints.Leases); + verify(container).setLeaseStrategy(LeaseStrategy.retainOnError()); + }); } @Test public void shouldConfigureWithoutAuthentication() { this.contextRunner.withUserConfiguration(MockVaultOperationsConfiguration.class) - .withAllowBeanDefinitionOverriding(true) - .withPropertyValues("spring.cloud.vault.kv.enabled=true", - "spring.cloud.vault.config.lifecycle.enabled=true", "spring.cloud.vault.authentication=NONE", - "spring.cloud.bootstrap.enabled=true") - .run(context -> { - - assertThat(context).doesNotHaveBean(SessionManager.class); - assertThat(context).hasSingleBean(SecretLeaseContainer.class); - }); + .withAllowBeanDefinitionOverriding(true) + .withPropertyValues("spring.cloud.vault.kv.enabled=true", + "spring.cloud.vault.config.lifecycle.enabled=true", "spring.cloud.vault.authentication=NONE", + "spring.cloud.bootstrap.enabled=true") + .run(context -> { + + assertThat(context).doesNotHaveBean(SessionManager.class); + assertThat(context).hasSingleBean(SecretLeaseContainer.class); + }); } @EnableConfigurationProperties(VaultProperties.class) diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultBootstrapperIntegrationTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultBootstrapperIntegrationTests.java index da7d9a4c3..8d1ca24f0 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultBootstrapperIntegrationTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultBootstrapperIntegrationTests.java @@ -44,11 +44,14 @@ public class VaultBootstrapperIntegrationTests extends IntegrationTestSupport { @Before public void before() { - this.vaultRule.prepare().getVaultOperations().write("secret/VaultBootstrapPropertySourceConfigurationTests", - Collections.singletonMap("default-key", "default")); - - this.vaultRule.prepare().getVaultOperations().write("secret/customized", - Collections.singletonMap("key", "customized")); + this.vaultRule.prepare() + .getVaultOperations() + .write("secret/VaultBootstrapPropertySourceConfigurationTests", + Collections.singletonMap("default-key", "default")); + + this.vaultRule.prepare() + .getVaultOperations() + .write("secret/customized", Collections.singletonMap("key", "customized")); SpringApplication application = new SpringApplication(Config.class); application.setWebApplicationType(WebApplicationType.NONE); diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigAppIdCustomMechanismTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigAppIdCustomMechanismTests.java index b8eeace79..dd22838b6 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigAppIdCustomMechanismTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigAppIdCustomMechanismTests.java @@ -124,8 +124,9 @@ ClientAuthentication clientAuthentication() { RestTemplate restTemplate = TestRestTemplateFactory.create(Settings.createSslConfiguration()); return new AppIdAuthentication(AppIdAuthenticationOptions.builder() - .appId(VaultConfigAppIdCustomMechanismTests.class.getSimpleName()) - .userIdMechanism(new StaticUserIdMechanism()).build(), restTemplate); + .appId(VaultConfigAppIdCustomMechanismTests.class.getSimpleName()) + .userIdMechanism(new StaticUserIdMechanism()) + .build(), restTemplate); } } diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigAppRoleTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigAppRoleTests.java index 954e57d85..68f16b940 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigAppRoleTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigAppRoleTests.java @@ -94,11 +94,13 @@ public static void beforeClass() { vaultOperations.write("auth/approle/role/with-secret-id", withSecretId); - String roleId = (String) vaultOperations.read("auth/approle/role/with-secret-id/role-id").getData() - .get("role_id"); + String roleId = (String) vaultOperations.read("auth/approle/role/with-secret-id/role-id") + .getData() + .get("role_id"); String secretId = (String) vaultOperations - .write(String.format("auth/approle/role/with-secret-id/secret-id", "with-secret-id"), null).getData() - .get("secret_id"); + .write(String.format("auth/approle/role/with-secret-id/secret-id", "with-secret-id"), null) + .getData() + .get("secret_id"); System.setProperty("spring.cloud.vault.app-role.role-id", roleId); System.setProperty("spring.cloud.vault.app-role.secret-id", secretId); diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigDataLoaderIntegrationTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigDataLoaderIntegrationTests.java index 94f1a65ab..ad3487f66 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigDataLoaderIntegrationTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigDataLoaderIntegrationTests.java @@ -42,11 +42,13 @@ public class VaultConfigDataLoaderIntegrationTests extends IntegrationTestSuppor @Before public void before() { - this.vaultRule.prepare().getVaultOperations().write("secret/my-config-loader", - Collections.singletonMap("default-key", "default")); + this.vaultRule.prepare() + .getVaultOperations() + .write("secret/my-config-loader", Collections.singletonMap("default-key", "default")); - this.vaultRule.prepare().getVaultOperations().write("secret/my-config-loader/cloud", - Collections.singletonMap("default-key", "cloud")); + this.vaultRule.prepare() + .getVaultOperations() + .write("secret/my-config-loader/cloud", Collections.singletonMap("default-key", "cloud")); } @Test diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigDataLocationResolverUnitTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigDataLocationResolverUnitTests.java index b48917d8c..94103eea6 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigDataLocationResolverUnitTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigDataLocationResolverUnitTests.java @@ -65,11 +65,11 @@ public void shouldDiscoverDefaultLocations() { assertThat( resolver.resolveProfileSpecific(this.contextMock, ConfigDataLocation.of("vault:"), this.profilesMock)) - .hasSize(3); + .hasSize(3); assertThat( resolver.resolveProfileSpecific(this.contextMock, ConfigDataLocation.of("vault://"), this.profilesMock)) - .hasSize(3); + .hasSize(3); } @Test @@ -78,9 +78,9 @@ public void shouldRejectLocationWithTrailingSlash() { VaultConfigDataLocationResolver resolver = new VaultConfigDataLocationResolver(); assertThatIllegalArgumentException() - .isThrownBy(() -> resolver.resolveProfileSpecific(this.contextMock, - ConfigDataLocation.of("vault://foo/"), this.profilesMock)) - .withMessage("Location 'vault://foo/' must not end with a trailing slash"); + .isThrownBy(() -> resolver.resolveProfileSpecific(this.contextMock, ConfigDataLocation.of("vault://foo/"), + this.profilesMock)) + .withMessage("Location 'vault://foo/' must not end with a trailing slash"); } @Test @@ -93,8 +93,10 @@ public void shouldDiscoverContextualLocations() { assertThat(locations).hasSize(1); assertThat(locations.get(0)).hasToString("VaultConfigLocation [path='my/context/path', optional=false]"); - assertThat(locations.get(0).getSecretBackendMetadata().getPropertyTransformer() - .transformProperties(Collections.singletonMap("key", "value"))).containsEntry("key", "value"); + assertThat(locations.get(0) + .getSecretBackendMetadata() + .getPropertyTransformer() + .transformProperties(Collections.singletonMap("key", "value"))).containsEntry("key", "value"); } @Test @@ -106,8 +108,10 @@ public void shouldDiscoverContextualLocationsWithPrefix() { ConfigDataLocation.of("vault://my/context/path?prefix=myPrefix."), this.profilesMock); assertThat(locations).hasSize(1); - assertThat(locations.get(0).getSecretBackendMetadata().getPropertyTransformer() - .transformProperties(Collections.singletonMap("key", "value"))).containsEntry("myPrefix.key", "value"); + assertThat(locations.get(0) + .getSecretBackendMetadata() + .getPropertyTransformer() + .transformProperties(Collections.singletonMap("key", "value"))).containsEntry("myPrefix.key", "value"); } @Test @@ -119,8 +123,10 @@ public void shouldNotPrefixWhenPrefixIsEmpty() { ConfigDataLocation.of("vault://my/context/path?prefix="), this.profilesMock); assertThat(locations).hasSize(1); - assertThat(locations.get(0).getSecretBackendMetadata().getPropertyTransformer() - .transformProperties(Collections.singletonMap("key", "value"))).containsEntry("key", "value"); + assertThat(locations.get(0) + .getSecretBackendMetadata() + .getPropertyTransformer() + .transformProperties(Collections.singletonMap("key", "value"))).containsEntry("key", "value"); } @Test @@ -134,7 +140,7 @@ public void kvProfilesPropertyPrecedenceShouldBeRespected() { assertThat( resolver.resolveProfileSpecific(this.contextMock, ConfigDataLocation.of("vault://"), this.profilesMock)) - .hasSize(4); + .hasSize(4); } } diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigDisabledTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigDisabledTests.java index 3ab01094e..cfafbb38d 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigDisabledTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigDisabledTests.java @@ -61,8 +61,9 @@ public static void beforeClass() { VaultRule vaultRule = new VaultRule(); vaultRule.before(); - vaultRule.prepare().getVaultOperations().write("secret/testVaultApp", - Collections.singletonMap("vault.value", "foo")); + vaultRule.prepare() + .getVaultOperations() + .write("secret/testVaultApp", Collections.singletonMap("vault.value", "foo")); } @Test diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigKeyValueBackendDisabledTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigKeyValueBackendDisabledTests.java index 0988cf56b..48793566a 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigKeyValueBackendDisabledTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigKeyValueBackendDisabledTests.java @@ -56,8 +56,9 @@ public static void beforeClass() { VaultRule vaultRule = new VaultRule(); vaultRule.before(); - vaultRule.prepare().getVaultOperations().write("secret/testVaultApp", - Collections.singletonMap("vault.value", "foo")); + vaultRule.prepare() + .getVaultOperations() + .write("secret/testVaultApp", Collections.singletonMap("vault.value", "foo")); } @Test diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigTemplateIntegrationTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigTemplateIntegrationTests.java index a808d22fe..8c4fa5ecb 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigTemplateIntegrationTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigTemplateIntegrationTests.java @@ -57,8 +57,10 @@ public void shouldReadVersionedValue() { assumeTrue(this.vaultRule.prepare().getVersion().isGreaterThanOrEqualTo(Version.parse("0.10.0"))); - this.vaultRule.prepare().getVaultOperations().write("versioned/data/testVaultApp", - Collections.singletonMap("data", Collections.singletonMap("key", "value"))); + this.vaultRule.prepare() + .getVaultOperations() + .write("versioned/data/testVaultApp", + Collections.singletonMap("data", Collections.singletonMap("key", "value"))); VaultProperties vaultProperties = Settings.createVaultProperties(); diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigTlsCertAuthenticationMountPathTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigTlsCertAuthenticationMountPathTests.java index 7671416f4..2e732c65f 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigTlsCertAuthenticationMountPathTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultConfigTlsCertAuthenticationMountPathTests.java @@ -69,8 +69,10 @@ public static void beforeClass() { vaultProperties.getSsl().setCertAuthPath("nonstandard"); if (!vaultRule.prepare().hasAuth(vaultProperties.getSsl().getCertAuthPath())) { - vaultRule.prepare().getVaultOperations().opsForSys().authMount(vaultProperties.getSsl().getCertAuthPath(), - VaultMount.builder().type("cert").build()); + vaultRule.prepare() + .getVaultOperations() + .opsForSys() + .authMount(vaultProperties.getSsl().getCertAuthPath(), VaultMount.builder().type("cert").build()); } VaultOperations vaultOperations = vaultRule.prepare().getVaultOperations(); diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultHealthIndicatorAutoConfigurationTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultHealthIndicatorAutoConfigurationTests.java index 5bb105f4f..20dcfc534 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultHealthIndicatorAutoConfigurationTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultHealthIndicatorAutoConfigurationTests.java @@ -36,7 +36,7 @@ class VaultHealthIndicatorAutoConfigurationTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(VaultHealthIndicatorAutoConfiguration.class)); + .withConfiguration(AutoConfigurations.of(VaultHealthIndicatorAutoConfiguration.class)); @Test void shouldNotConfigureHealthIndicatorWithoutVaultOperations() { @@ -67,11 +67,11 @@ void shouldConfigureReactiveHealthIndicator() { void shouldConfigureSingleHealthIndicator() { this.contextRunner.withUserConfiguration(ImperativeConfiguration.class, ReactiveConfiguration.class) - .run(context -> { - assertThat(context).hasBean("vaultHealthIndicator") - .hasSingleBean(VaultReactiveHealthIndicator.class) - .doesNotHaveBean(VaultHealthIndicator.class); - }); + .run(context -> { + assertThat(context).hasBean("vaultHealthIndicator") + .hasSingleBean(VaultReactiveHealthIndicator.class) + .doesNotHaveBean(VaultHealthIndicator.class); + }); } static class ImperativeConfiguration { diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultNamespaceTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultNamespaceTests.java index 3f00aa22b..8e02ef413 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultNamespaceTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultNamespaceTests.java @@ -63,16 +63,18 @@ public class VaultNamespaceTests { @ClassRule public static VaultRule vaultRule = new VaultRule(); - static final Policy POLICY = Policy - .of(Policy.Rule.builder().path("/*").capabilities(Policy.BuiltinCapabilities.READ, - Policy.BuiltinCapabilities.CREATE, Policy.BuiltinCapabilities.UPDATE).build()); + static final Policy POLICY = Policy.of(Policy.Rule.builder() + .path("/*") + .capabilities(Policy.BuiltinCapabilities.READ, Policy.BuiltinCapabilities.CREATE, + Policy.BuiltinCapabilities.UPDATE) + .build()); RestTemplateBuilder maketingRestTemplate; WebClientBuilder marketingWebClientBuilder = WebClientBuilder.builder() - .httpConnector(ClientHttpConnectorFactory.create(new ClientOptions(), Settings.createSslConfiguration())) - .endpoint(TestRestTemplateFactory.TEST_VAULT_ENDPOINT) - .defaultHeader(VaultHttpHeaders.VAULT_NAMESPACE, "marketing"); + .httpConnector(ClientHttpConnectorFactory.create(new ClientOptions(), Settings.createSslConfiguration())) + .endpoint(TestRestTemplateFactory.TEST_VAULT_ENDPOINT) + .defaultHeader(VaultHttpHeaders.VAULT_NAMESPACE, "marketing"); String marketingToken; @@ -90,18 +92,20 @@ public void before() { } this.maketingRestTemplate = RestTemplateBuilder.builder() - .requestFactory( - ClientHttpRequestFactoryFactory.create(new ClientOptions(), Settings.createSslConfiguration())) - .endpoint(TestRestTemplateFactory.TEST_VAULT_ENDPOINT) - .defaultHeader(VaultHttpHeaders.VAULT_NAMESPACE, "marketing"); + .requestFactory( + ClientHttpRequestFactoryFactory.create(new ClientOptions(), Settings.createSslConfiguration())) + .endpoint(TestRestTemplateFactory.TEST_VAULT_ENDPOINT) + .defaultHeader(VaultHttpHeaders.VAULT_NAMESPACE, "marketing"); VaultTemplate marketing = new VaultTemplate(this.maketingRestTemplate, new SimpleSessionManager(new TokenAuthentication(Settings.token()))); mountKv(marketing, "marketing-secrets"); marketing.opsForSys().createOrUpdatePolicy("relaxed", POLICY); - this.marketingToken = marketing.opsForToken().create(VaultTokenRequest.builder().withPolicy("relaxed").build()) - .getToken().getToken(); + this.marketingToken = marketing.opsForToken() + .create(VaultTokenRequest.builder().withPolicy("relaxed").build()) + .getToken() + .getToken(); } private void mountKv(VaultTemplate template, String path) { @@ -136,8 +140,10 @@ public void shouldReportReactiveHealth() { Health.Builder builder = Health.unknown(); - new VaultReactiveHealthIndicator(reactiveMarketing).doHealthCheck(builder).as(StepVerifier::create) - .assertNext(actual -> assertThat(actual.getStatus()).isEqualTo(Status.UP)).verifyComplete(); + new VaultReactiveHealthIndicator(reactiveMarketing).doHealthCheck(builder) + .as(StepVerifier::create) + .assertNext(actual -> assertThat(actual.getStatus()).isEqualTo(Status.UP)) + .verifyComplete(); } } diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultPropertySourceIntegrationTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultPropertySourceIntegrationTests.java index 3dc119235..90202ce88 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultPropertySourceIntegrationTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultPropertySourceIntegrationTests.java @@ -60,8 +60,10 @@ public void shouldReadVersionedValue() { assumeTrue(this.vaultRule.prepare().getVersion().isGreaterThanOrEqualTo(Version.parse("0.10.0"))); - this.vaultRule.prepare().getVaultOperations().write("versioned/data/testVaultApp", - Collections.singletonMap("data", Collections.singletonMap("key", "value"))); + this.vaultRule.prepare() + .getVaultOperations() + .write("versioned/data/testVaultApp", + Collections.singletonMap("data", Collections.singletonMap("key", "value"))); VaultProperties vaultProperties = Settings.createVaultProperties(); diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultPropertySourceLocatorIntegrationTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultPropertySourceLocatorIntegrationTests.java index cf89bccd3..b58d7dcbb 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultPropertySourceLocatorIntegrationTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultPropertySourceLocatorIntegrationTests.java @@ -58,20 +58,29 @@ public static void beforeClass() { VaultRule vaultRule = new VaultRule(); vaultRule.before(); - vaultRule.prepare().getVaultOperations().write("secret/wintermute", - Collections.singletonMap("vault.value", "wintermute")); - vaultRule.prepare().getVaultOperations().write("secret/wintermute/integrationtest", - Collections.singletonMap("vault.value", "integrationtest wintermute")); - - vaultRule.prepare().getVaultOperations().write("secret/neuromancer", - Collections.singletonMap("vault.value", "neuromancer")); - vaultRule.prepare().getVaultOperations().write("secret/neuromancer/integrationtest", - Collections.singletonMap("vault.value", "integrationtest neuromancer")); - - vaultRule.prepare().getVaultOperations().write("secret/icebreaker", - Collections.singletonMap("icebreaker.value", "icebreaker")); - vaultRule.prepare().getVaultOperations().write("secret/icebreaker/integrationtest", - Collections.singletonMap("icebreaker.value", "integrationtest icebreaker")); + vaultRule.prepare() + .getVaultOperations() + .write("secret/wintermute", Collections.singletonMap("vault.value", "wintermute")); + vaultRule.prepare() + .getVaultOperations() + .write("secret/wintermute/integrationtest", + Collections.singletonMap("vault.value", "integrationtest wintermute")); + + vaultRule.prepare() + .getVaultOperations() + .write("secret/neuromancer", Collections.singletonMap("vault.value", "neuromancer")); + vaultRule.prepare() + .getVaultOperations() + .write("secret/neuromancer/integrationtest", + Collections.singletonMap("vault.value", "integrationtest neuromancer")); + + vaultRule.prepare() + .getVaultOperations() + .write("secret/icebreaker", Collections.singletonMap("icebreaker.value", "icebreaker")); + vaultRule.prepare() + .getVaultOperations() + .write("secret/icebreaker/integrationtest", + Collections.singletonMap("icebreaker.value", "integrationtest icebreaker")); } @Test diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultPropertySourceLocatorProfilesIntegrationTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultPropertySourceLocatorProfilesIntegrationTests.java index a54124877..1ac71aea2 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultPropertySourceLocatorProfilesIntegrationTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultPropertySourceLocatorProfilesIntegrationTests.java @@ -55,14 +55,17 @@ public static void beforeClass() { VaultRule vaultRule = new VaultRule(); vaultRule.before(); - vaultRule.prepare().getVaultOperations().write("secret/my-profiles-app/hello", - Collections.singletonMap("vault.hello", "true")); + vaultRule.prepare() + .getVaultOperations() + .write("secret/my-profiles-app/hello", Collections.singletonMap("vault.hello", "true")); - vaultRule.prepare().getVaultOperations().write("secret/my-profiles-app/world", - Collections.singletonMap("vault.world", "true")); + vaultRule.prepare() + .getVaultOperations() + .write("secret/my-profiles-app/world", Collections.singletonMap("vault.world", "true")); - vaultRule.prepare().getVaultOperations().write("secret/my-profiles-app/other", - Collections.singletonMap("vault.other", "true")); + vaultRule.prepare() + .getVaultOperations() + .write("secret/my-profiles-app/other", Collections.singletonMap("vault.other", "true")); } @Test diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultPropertySourceLocatorUnitTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultPropertySourceLocatorUnitTests.java index 6fccfabe0..7534c9af1 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultPropertySourceLocatorUnitTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultPropertySourceLocatorUnitTests.java @@ -89,8 +89,8 @@ public void shouldLocatePropertySourcesForActiveProfilesInDefaultContext() { assertThat(propertySource).isInstanceOf(CompositePropertySource.class); CompositePropertySource composite = (CompositePropertySource) propertySource; - assertThat(composite.getPropertySources()).extracting("name").containsSequence("secret/application/periwinkle", - "secret/application/vermillion"); + assertThat(composite.getPropertySources()).extracting("name") + .containsSequence("secret/application/periwinkle", "secret/application/vermillion"); } @Test @@ -108,8 +108,8 @@ public void shouldLocatePropertySourcesInVaultApplicationContext() { assertThat(propertySource).isInstanceOf(CompositePropertySource.class); CompositePropertySource composite = (CompositePropertySource) propertySource; - assertThat(composite.getPropertySources()).extracting("name").containsSequence("secret/wintermute/periwinkle", - "secret/wintermute/vermillion", "secret/wintermute"); + assertThat(composite.getPropertySources()).extracting("name") + .containsSequence("secret/wintermute/periwinkle", "secret/wintermute/vermillion", "secret/wintermute"); } @Test @@ -127,10 +127,11 @@ public void shouldLocatePropertySourcesInEachPathSpecifiedWhenApplicationNameCon assertThat(propertySource).isInstanceOf(CompositePropertySource.class); CompositePropertySource composite = (CompositePropertySource) propertySource; - assertThat(composite.getPropertySources()).extracting("name").contains("secret/wintermute", "secret/straylight", - "secret/icebreaker/armitage", "secret/wintermute/vermillion", "secret/wintermute/periwinkle", - "secret/straylight/vermillion", "secret/straylight/periwinkle", "secret/icebreaker/armitage/vermillion", - "secret/icebreaker/armitage/periwinkle"); + assertThat(composite.getPropertySources()).extracting("name") + .contains("secret/wintermute", "secret/straylight", "secret/icebreaker/armitage", + "secret/wintermute/vermillion", "secret/wintermute/periwinkle", "secret/straylight/vermillion", + "secret/straylight/periwinkle", "secret/icebreaker/armitage/vermillion", + "secret/icebreaker/armitage/periwinkle"); } @Test diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultReactiveAutoConfigurationTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultReactiveAutoConfigurationTests.java index dd8cd7451..8f8909378 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultReactiveAutoConfigurationTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultReactiveAutoConfigurationTests.java @@ -61,150 +61,161 @@ public class VaultReactiveAutoConfigurationTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(VaultReactiveAutoConfiguration.class)); + .withConfiguration(AutoConfigurations.of(VaultReactiveAutoConfiguration.class)); @Test public void shouldConfigureTemplate() { this.contextRunner.withUserConfiguration(AuthenticationFactoryConfiguration.class) - .withPropertyValues("spring.cloud.vault.session.lifecycle.enabled=false").run(context -> { - - assertThat(context).hasSingleBean(ReactiveVaultOperations.class); - assertThat(context).hasSingleBean(AuthenticationStepsFactory.class); - assertThat(context.getBean(SessionManager.class)).isNotNull() - .isNotInstanceOf(LifecycleAwareSessionManager.class) - .isNotInstanceOf(SimpleSessionManager.class); - assertThat(context.getBeanNamesForType(WebClient.class)).isEmpty(); - assertThat(context).hasSingleBean(WebClientFactory.class); - }); + .withPropertyValues("spring.cloud.vault.session.lifecycle.enabled=false") + .run(context -> { + + assertThat(context).hasSingleBean(ReactiveVaultOperations.class); + assertThat(context).hasSingleBean(AuthenticationStepsFactory.class); + assertThat(context.getBean(SessionManager.class)).isNotNull() + .isNotInstanceOf(LifecycleAwareSessionManager.class) + .isNotInstanceOf(SimpleSessionManager.class); + assertThat(context.getBeanNamesForType(WebClient.class)).isEmpty(); + assertThat(context).hasSingleBean(WebClientFactory.class); + }); } @Test public void shouldNotConfigureIfHttpClientIsMissing() { this.contextRunner.withUserConfiguration(AuthenticationFactoryConfiguration.class) - .withClassLoader(new FilteredClassLoader("reactor.netty.http.client.HttpClient")).run(context -> { + .withClassLoader(new FilteredClassLoader("reactor.netty.http.client.HttpClient")) + .run(context -> { - assertThat(context).doesNotHaveBean(ReactiveVaultOperations.class); - }); + assertThat(context).doesNotHaveBean(ReactiveVaultOperations.class); + }); } @Test public void shouldConfigureTemplateWithTokenSupplier() { this.contextRunner.withUserConfiguration(TokenSupplierConfiguration.class) - .withPropertyValues("spring.cloud.vault.session.lifecycle.enabled=false").run(context -> { - - assertThat(context).hasSingleBean(ReactiveVaultOperations.class); - assertThat(context.getBean(SessionManager.class)).isNotNull() - .isNotInstanceOf(LifecycleAwareSessionManager.class) - .isNotInstanceOf(SimpleSessionManager.class); - assertThat(context).doesNotHaveBean(WebClient.class); - }); + .withPropertyValues("spring.cloud.vault.session.lifecycle.enabled=false") + .run(context -> { + + assertThat(context).hasSingleBean(ReactiveVaultOperations.class); + assertThat(context.getBean(SessionManager.class)).isNotNull() + .isNotInstanceOf(LifecycleAwareSessionManager.class) + .isNotInstanceOf(SimpleSessionManager.class); + assertThat(context).doesNotHaveBean(WebClient.class); + }); } @Test public void shouldNotConfigureReactiveSupport() { this.contextRunner.withUserConfiguration(VaultAutoConfiguration.class) - .withPropertyValues("spring.cloud.vault.reactive.enabled=false", "spring.cloud.vault.token=foo") - .run(context -> { + .withPropertyValues("spring.cloud.vault.reactive.enabled=false", "spring.cloud.vault.token=foo") + .run(context -> { - assertThat(context).doesNotHaveBean(ReactiveVaultTemplate.class) - .doesNotHaveBean(ReactiveVaultOperations.class); - assertThat(context.getBean(SessionManager.class)).isInstanceOf(LifecycleAwareSessionManager.class); - }); + assertThat(context).doesNotHaveBean(ReactiveVaultTemplate.class) + .doesNotHaveBean(ReactiveVaultOperations.class); + assertThat(context.getBean(SessionManager.class)).isInstanceOf(LifecycleAwareSessionManager.class); + }); } @Test public void sessionManagerBridgeShouldNotCacheTokens() { this.contextRunner.withUserConfiguration(TokenSupplierConfiguration.class, CustomSessionManager.class) - .run(context -> { + .run(context -> { - SessionManager sessionManager = context.getBean(SessionManager.class); + SessionManager sessionManager = context.getBean(SessionManager.class); - assertThat(sessionManager.getSessionToken().getToken()).isEqualTo("token-1"); - assertThat(sessionManager.getSessionToken().getToken()).isEqualTo("token-2"); - }); + assertThat(sessionManager.getSessionToken().getToken()).isEqualTo("token-1"); + assertThat(sessionManager.getSessionToken().getToken()).isEqualTo("token-2"); + }); } @Test public void shouldDisableSessionManagement() { this.contextRunner - .withPropertyValues("spring.cloud.vault.kv.enabled=false", "spring.cloud.vault.token=foo", - "spring.cloud.vault.session.lifecycle.enabled=false") - .withBean("vaultTokenSupplier", VaultTokenSupplier.class, () -> Mono::empty) - .withBean("taskSchedulerWrapper", VaultAutoConfiguration.TaskSchedulerWrapper.class, - () -> new VaultAutoConfiguration.TaskSchedulerWrapper(new ThreadPoolTaskScheduler())) - .run(context -> { - - ReactiveSessionManager bean = context.getBean(ReactiveSessionManager.class); - assertThat(bean).isExactlyInstanceOf(CachingVaultTokenSupplier.class); - }); + .withPropertyValues("spring.cloud.vault.kv.enabled=false", "spring.cloud.vault.token=foo", + "spring.cloud.vault.session.lifecycle.enabled=false") + .withBean("vaultTokenSupplier", VaultTokenSupplier.class, () -> Mono::empty) + .withBean("taskSchedulerWrapper", VaultAutoConfiguration.TaskSchedulerWrapper.class, + () -> new VaultAutoConfiguration.TaskSchedulerWrapper(new ThreadPoolTaskScheduler())) + .run(context -> { + + ReactiveSessionManager bean = context.getBean(ReactiveSessionManager.class); + assertThat(bean).isExactlyInstanceOf(CachingVaultTokenSupplier.class); + }); } @Test public void shouldConfigureSessionManagement() { this.contextRunner - .withPropertyValues("spring.cloud.vault.kv.enabled=false", "spring.cloud.vault.token=foo", - "spring.cloud.vault.session.lifecycle.refresh-before-expiry=11s", - "spring.cloud.vault.session.lifecycle.expiry-threshold=12s") - .withBean("vaultTokenSupplier", VaultTokenSupplier.class, () -> Mono::empty) - .withBean("taskSchedulerWrapper", VaultAutoConfiguration.TaskSchedulerWrapper.class, - () -> new VaultAutoConfiguration.TaskSchedulerWrapper(new ThreadPoolTaskScheduler())) - .run(context -> { + .withPropertyValues("spring.cloud.vault.kv.enabled=false", "spring.cloud.vault.token=foo", + "spring.cloud.vault.session.lifecycle.refresh-before-expiry=11s", + "spring.cloud.vault.session.lifecycle.expiry-threshold=12s") + .withBean("vaultTokenSupplier", VaultTokenSupplier.class, () -> Mono::empty) + .withBean("taskSchedulerWrapper", VaultAutoConfiguration.TaskSchedulerWrapper.class, + () -> new VaultAutoConfiguration.TaskSchedulerWrapper(new ThreadPoolTaskScheduler())) + .run(context -> { - ReactiveSessionManager bean = context.getBean(ReactiveSessionManager.class); + ReactiveSessionManager bean = context.getBean(ReactiveSessionManager.class); - Object refreshTrigger = ReflectionTestUtils.getField(bean, "refreshTrigger"); + Object refreshTrigger = ReflectionTestUtils.getField(bean, "refreshTrigger"); - assertThat(refreshTrigger).hasFieldOrPropertyWithValue("duration", Duration.ofSeconds(11)) - .hasFieldOrPropertyWithValue("expiryThreshold", Duration.ofSeconds(12)); - }); + assertThat(refreshTrigger).hasFieldOrPropertyWithValue("duration", Duration.ofSeconds(11)) + .hasFieldOrPropertyWithValue("expiryThreshold", Duration.ofSeconds(12)); + }); } @Test public void shouldConfigureEndpointProvider() { this.contextRunner - .withPropertyValues("spring.cloud.vault.kv.enabled=false", "spring.cloud.vault.token=foo", - "spring.cloud.vault.session.lifecycle.enabled=false") - .withUserConfiguration(ReactiveEndpointProviderConfiguration.class) - .withBean("vaultTokenSupplier", VaultTokenSupplier.class, () -> Mono::empty) - .withBean("taskSchedulerWrapper", VaultAutoConfiguration.TaskSchedulerWrapper.class, - () -> new VaultAutoConfiguration.TaskSchedulerWrapper(new ThreadPoolTaskScheduler())) - .run(context -> { - - WebClientFactory factory = context.getBean(WebClientFactory.class); - WebClient webClient = factory.create(); - - webClient.get().uri("foo").retrieve().bodyToMono(String.class).as(StepVerifier::create) - .verifyErrorMatches(throwable -> throwable.getMessage().contains("foobar-1")); - - webClient.get().uri("foo").retrieve().bodyToMono(String.class).as(StepVerifier::create) - .verifyErrorMatches(throwable -> throwable.getMessage().contains("foobar-2")); - }); + .withPropertyValues("spring.cloud.vault.kv.enabled=false", "spring.cloud.vault.token=foo", + "spring.cloud.vault.session.lifecycle.enabled=false") + .withUserConfiguration(ReactiveEndpointProviderConfiguration.class) + .withBean("vaultTokenSupplier", VaultTokenSupplier.class, () -> Mono::empty) + .withBean("taskSchedulerWrapper", VaultAutoConfiguration.TaskSchedulerWrapper.class, + () -> new VaultAutoConfiguration.TaskSchedulerWrapper(new ThreadPoolTaskScheduler())) + .run(context -> { + + WebClientFactory factory = context.getBean(WebClientFactory.class); + WebClient webClient = factory.create(); + + webClient.get() + .uri("foo") + .retrieve() + .bodyToMono(String.class) + .as(StepVerifier::create) + .verifyErrorMatches(throwable -> throwable.getMessage().contains("foobar-1")); + + webClient.get() + .uri("foo") + .retrieve() + .bodyToMono(String.class) + .as(StepVerifier::create) + .verifyErrorMatches(throwable -> throwable.getMessage().contains("foobar-2")); + }); } @Test public void shouldConsiderCustomConnector() { this.contextRunner - .withPropertyValues("spring.cloud.vault.kv.enabled=false", "spring.cloud.vault.token=foo", - "spring.cloud.vault.session.lifecycle.enabled=false") - .withUserConfiguration(CustomConnector.class) - .withBean("vaultTokenSupplier", VaultTokenSupplier.class, - () -> () -> Mono.just(VaultToken.of("foo".toCharArray()))) - .withBean("taskSchedulerWrapper", VaultAutoConfiguration.TaskSchedulerWrapper.class, - () -> new VaultAutoConfiguration.TaskSchedulerWrapper(new ThreadPoolTaskScheduler())) - .run(context -> { - - ReactiveVaultOperations operations = context.getBean(ReactiveVaultOperations.class); - operations.delete("foo").as(StepVerifier::create).verifyError(WebClientRequestException.class); - }); + .withPropertyValues("spring.cloud.vault.kv.enabled=false", "spring.cloud.vault.token=foo", + "spring.cloud.vault.session.lifecycle.enabled=false") + .withUserConfiguration(CustomConnector.class) + .withBean("vaultTokenSupplier", VaultTokenSupplier.class, + () -> () -> Mono.just(VaultToken.of("foo".toCharArray()))) + .withBean("taskSchedulerWrapper", VaultAutoConfiguration.TaskSchedulerWrapper.class, + () -> new VaultAutoConfiguration.TaskSchedulerWrapper(new ThreadPoolTaskScheduler())) + .run(context -> { + + ReactiveVaultOperations operations = context.getBean(ReactiveVaultOperations.class); + operations.delete("foo").as(StepVerifier::create).verifyError(WebClientRequestException.class); + }); } @Configuration(proxyBeanMethods = false) diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultReactiveBootstrapConfigurationTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultReactiveBootstrapConfigurationTests.java index edaed1074..c576e3ce3 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultReactiveBootstrapConfigurationTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultReactiveBootstrapConfigurationTests.java @@ -53,114 +53,115 @@ public class VaultReactiveBootstrapConfigurationTests { private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(VaultReactiveBootstrapConfiguration.class)) - .withAllowBeanDefinitionOverriding(true); + .withConfiguration(AutoConfigurations.of(VaultReactiveBootstrapConfiguration.class)) + .withAllowBeanDefinitionOverriding(true); @Test public void shouldConfigureTemplate() { this.contextRunner.withUserConfiguration(AuthenticationFactoryConfiguration.class) - .withPropertyValues("spring.cloud.vault.session.lifecycle.enabled=false", - "spring.cloud.bootstrap.enabled=true") - .run(context -> { - - assertThat(context).hasSingleBean(ReactiveVaultOperations.class); - assertThat(context).hasSingleBean(AuthenticationStepsFactory.class); - assertThat(context.getBean(SessionManager.class)).isNotNull() - .isNotInstanceOf(LifecycleAwareSessionManager.class) - .isNotInstanceOf(SimpleSessionManager.class); - assertThat(context.getBeanNamesForType(WebClient.class)).isEmpty(); - assertThat(context).hasSingleBean(WebClientFactory.class); - }); + .withPropertyValues("spring.cloud.vault.session.lifecycle.enabled=false", + "spring.cloud.bootstrap.enabled=true") + .run(context -> { + + assertThat(context).hasSingleBean(ReactiveVaultOperations.class); + assertThat(context).hasSingleBean(AuthenticationStepsFactory.class); + assertThat(context.getBean(SessionManager.class)).isNotNull() + .isNotInstanceOf(LifecycleAwareSessionManager.class) + .isNotInstanceOf(SimpleSessionManager.class); + assertThat(context.getBeanNamesForType(WebClient.class)).isEmpty(); + assertThat(context).hasSingleBean(WebClientFactory.class); + }); } @Test public void shouldNotConfigureIfHttpClientIsMissing() { this.contextRunner.withUserConfiguration(AuthenticationFactoryConfiguration.class) - .withClassLoader(new FilteredClassLoader("reactor.netty.http.client.HttpClient")).run(context -> { + .withClassLoader(new FilteredClassLoader("reactor.netty.http.client.HttpClient")) + .run(context -> { - assertThat(context).doesNotHaveBean(ReactiveVaultOperations.class); - }); + assertThat(context).doesNotHaveBean(ReactiveVaultOperations.class); + }); } @Test public void shouldConfigureTemplateWithTokenSupplier() { this.contextRunner.withUserConfiguration(TokenSupplierConfiguration.class) - .withPropertyValues("spring.cloud.vault.session.lifecycle.enabled=false", - "spring.cloud.bootstrap.enabled=true") - .run(context -> { - - assertThat(context).hasSingleBean(ReactiveVaultOperations.class); - assertThat(context.getBean(SessionManager.class)).isNotNull() - .isNotInstanceOf(LifecycleAwareSessionManager.class) - .isNotInstanceOf(SimpleSessionManager.class); - assertThat(context).doesNotHaveBean(WebClient.class); - }); + .withPropertyValues("spring.cloud.vault.session.lifecycle.enabled=false", + "spring.cloud.bootstrap.enabled=true") + .run(context -> { + + assertThat(context).hasSingleBean(ReactiveVaultOperations.class); + assertThat(context.getBean(SessionManager.class)).isNotNull() + .isNotInstanceOf(LifecycleAwareSessionManager.class) + .isNotInstanceOf(SimpleSessionManager.class); + assertThat(context).doesNotHaveBean(WebClient.class); + }); } @Test public void shouldNotConfigureReactiveSupport() { this.contextRunner.withUserConfiguration(VaultBootstrapConfiguration.class) - .withPropertyValues("spring.cloud.vault.reactive.enabled=false", "spring.cloud.vault.token=foo") - .run(context -> { + .withPropertyValues("spring.cloud.vault.reactive.enabled=false", "spring.cloud.vault.token=foo") + .run(context -> { - assertThat(context).doesNotHaveBean(ReactiveVaultTemplate.class) - .doesNotHaveBean(ReactiveVaultOperations.class); - assertThat(context.getBean(SessionManager.class)).isInstanceOf(LifecycleAwareSessionManager.class); - }); + assertThat(context).doesNotHaveBean(ReactiveVaultTemplate.class) + .doesNotHaveBean(ReactiveVaultOperations.class); + assertThat(context.getBean(SessionManager.class)).isInstanceOf(LifecycleAwareSessionManager.class); + }); } @Test public void sessionManagerBridgeShouldNotCacheTokens() { this.contextRunner.withUserConfiguration(TokenSupplierConfiguration.class, CustomSessionManager.class) - .run(context -> { + .run(context -> { - SessionManager sessionManager = context.getBean(SessionManager.class); + SessionManager sessionManager = context.getBean(SessionManager.class); - assertThat(sessionManager.getSessionToken().getToken()).isEqualTo("token-1"); - assertThat(sessionManager.getSessionToken().getToken()).isEqualTo("token-2"); - }); + assertThat(sessionManager.getSessionToken().getToken()).isEqualTo("token-1"); + assertThat(sessionManager.getSessionToken().getToken()).isEqualTo("token-2"); + }); } @Test public void shouldDisableSessionManagement() { this.contextRunner - .withPropertyValues("spring.cloud.vault.kv.enabled=false", "spring.cloud.vault.token=foo", - "spring.cloud.vault.session.lifecycle.enabled=false") - .withBean("vaultTokenSupplier", VaultTokenSupplier.class, () -> Mono::empty) - .withBean("taskSchedulerWrapper", VaultBootstrapConfiguration.TaskSchedulerWrapper.class, - () -> new VaultBootstrapConfiguration.TaskSchedulerWrapper(new ThreadPoolTaskScheduler())) - .run(context -> { - - ReactiveSessionManager bean = context.getBean(ReactiveSessionManager.class); - assertThat(bean).isExactlyInstanceOf(CachingVaultTokenSupplier.class); - }); + .withPropertyValues("spring.cloud.vault.kv.enabled=false", "spring.cloud.vault.token=foo", + "spring.cloud.vault.session.lifecycle.enabled=false") + .withBean("vaultTokenSupplier", VaultTokenSupplier.class, () -> Mono::empty) + .withBean("taskSchedulerWrapper", VaultBootstrapConfiguration.TaskSchedulerWrapper.class, + () -> new VaultBootstrapConfiguration.TaskSchedulerWrapper(new ThreadPoolTaskScheduler())) + .run(context -> { + + ReactiveSessionManager bean = context.getBean(ReactiveSessionManager.class); + assertThat(bean).isExactlyInstanceOf(CachingVaultTokenSupplier.class); + }); } @Test public void shouldConfigureSessionManagement() { this.contextRunner - .withPropertyValues("spring.cloud.vault.kv.enabled=false", "spring.cloud.vault.token=foo", - "spring.cloud.vault.session.lifecycle.refresh-before-expiry=11s", - "spring.cloud.vault.session.lifecycle.expiry-threshold=12s") - .withBean("vaultTokenSupplier", VaultTokenSupplier.class, () -> Mono::empty) - .withBean("taskSchedulerWrapper", VaultBootstrapConfiguration.TaskSchedulerWrapper.class, - () -> new VaultBootstrapConfiguration.TaskSchedulerWrapper(new ThreadPoolTaskScheduler())) - .run(context -> { + .withPropertyValues("spring.cloud.vault.kv.enabled=false", "spring.cloud.vault.token=foo", + "spring.cloud.vault.session.lifecycle.refresh-before-expiry=11s", + "spring.cloud.vault.session.lifecycle.expiry-threshold=12s") + .withBean("vaultTokenSupplier", VaultTokenSupplier.class, () -> Mono::empty) + .withBean("taskSchedulerWrapper", VaultBootstrapConfiguration.TaskSchedulerWrapper.class, + () -> new VaultBootstrapConfiguration.TaskSchedulerWrapper(new ThreadPoolTaskScheduler())) + .run(context -> { - ReactiveSessionManager bean = context.getBean(ReactiveSessionManager.class); + ReactiveSessionManager bean = context.getBean(ReactiveSessionManager.class); - Object refreshTrigger = ReflectionTestUtils.getField(bean, "refreshTrigger"); + Object refreshTrigger = ReflectionTestUtils.getField(bean, "refreshTrigger"); - assertThat(refreshTrigger).hasFieldOrPropertyWithValue("duration", Duration.ofSeconds(11)) - .hasFieldOrPropertyWithValue("expiryThreshold", Duration.ofSeconds(12)); - }); + assertThat(refreshTrigger).hasFieldOrPropertyWithValue("duration", Duration.ofSeconds(11)) + .hasFieldOrPropertyWithValue("expiryThreshold", Duration.ofSeconds(12)); + }); } @Configuration(proxyBeanMethods = false) diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultVersionedKvBackendConfigTests.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultVersionedKvBackendConfigTests.java index 13d896556..a4fc4a63e 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultVersionedKvBackendConfigTests.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/config/VaultVersionedKvBackendConfigTests.java @@ -80,8 +80,9 @@ public static void beforeClass() { object.put("vault.value", "foo"); object.put("nested", Collections.singletonMap("key", "value")); - vaultRule.prepare().getVaultOperations().write("versioned/data/testVaultApp", - Collections.singletonMap("data", object)); + vaultRule.prepare() + .getVaultOperations() + .write("versioned/data/testVaultApp", Collections.singletonMap("data", object)); } @Test diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/util/PrepareVault.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/util/PrepareVault.java index 99c57c30a..819bb96be 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/util/PrepareVault.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/util/PrepareVault.java @@ -58,7 +58,7 @@ public VaultToken initializeVault() { int requiredKeys = 2; VaultInitializationResponse initialized = this.vaultOperations.opsForSys() - .initialize(VaultInitializationRequest.create(createKeys, requiredKeys)); + .initialize(VaultInitializationRequest.create(createKeys, requiredKeys)); for (int i = 0; i < requiredKeys; i++) { diff --git a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/util/TestRestTemplateFactory.java b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/util/TestRestTemplateFactory.java index 68e3ad293..00590dd1a 100644 --- a/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/util/TestRestTemplateFactory.java +++ b/spring-cloud-vault-config/src/test/java/org/springframework/cloud/vault/util/TestRestTemplateFactory.java @@ -86,7 +86,7 @@ private static void initializeClientHttpRequestFactory(SslConfiguration sslConfi } final ClientHttpRequestFactory clientHttpRequestFactory = ClientHttpRequestFactoryFactory - .create(new ClientOptions(), sslConfiguration); + .create(new ClientOptions(), sslConfiguration); if (factoryCache.compareAndSet(null, clientHttpRequestFactory)) {