diff --git a/settings.gradle b/settings.gradle index db83fd3b..66d10bce 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,7 +17,7 @@ pluginManagement { plugins { id 'io.spring.nohttp' version '0.0.11' - id 'io.spring.javaformat' version '0.0.35' + id 'io.spring.javaformat' version '0.0.39' id 'org.asciidoctor.jvm.convert' version '3.3.2' id 'org.springframework.boot' version '3.0.10' } diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/configuration/ClientHttpConnectorFactory.java b/spring-credhub-core/src/main/java/org/springframework/credhub/configuration/ClientHttpConnectorFactory.java index 22501fd2..30bb6941 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/configuration/ClientHttpConnectorFactory.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/configuration/ClientHttpConnectorFactory.java @@ -62,12 +62,14 @@ public static ClientHttpConnector create(ClientOptions options) { if (usingCustomCerts(options)) { TrustManagerFactory trustManagerFactory = sslCertificateUtils - .createTrustManagerFactory(options.getCaCertFiles()); + .createTrustManagerFactory(options.getCaCertFiles()); httpClient = httpClient.secure((sslContextSpec) -> { try { - sslContextSpec.sslContext(SslContextBuilder.forClient().sslProvider(SslProvider.JDK) - .trustManager(trustManagerFactory).build()); + sslContextSpec.sslContext(SslContextBuilder.forClient() + .sslProvider(SslProvider.JDK) + .trustManager(trustManagerFactory) + .build()); } catch (SSLException ex) { logger.error("Error configuring HTTP connections using custom certs", ex); diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/configuration/ClientHttpRequestFactoryFactory.java b/spring-credhub-core/src/main/java/org/springframework/credhub/configuration/ClientHttpRequestFactoryFactory.java index d0090708..f034d9ef 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/configuration/ClientHttpRequestFactoryFactory.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/configuration/ClientHttpRequestFactoryFactory.java @@ -148,15 +148,21 @@ static ClientHttpRequestFactory usingHttpComponents(ClientOptions options) throw SSLContext sslContext = sslCertificateUtils.getSSLContext(options.getCaCertFiles()); SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext); PoolingHttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder - .create().setSSLSocketFactory(sslSocketFactory).setDefaultSocketConfig(socketConfig).build(); + .create() + .setSSLSocketFactory(sslSocketFactory) + .setDefaultSocketConfig(socketConfig) + .build(); httpClientBuilder.setConnectionManager(connectionManager); } else { SSLContext sslContext = SSLContext.getDefault(); SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext); PoolingHttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder - .create().useSystemProperties().setSSLSocketFactory(sslSocketFactory) - .setDefaultSocketConfig(socketConfig).build(); + .create() + .useSystemProperties() + .setSSLSocketFactory(sslSocketFactory) + .setDefaultSocketConfig(socketConfig) + .build(); httpClientBuilder.setConnectionManager(connectionManager); } @@ -164,7 +170,7 @@ static ClientHttpRequestFactory usingHttpComponents(ClientOptions options) throw if (options.getConnectionTimeout() != null) { requestConfigBuilder - .setConnectTimeout(Timeout.ofMilliseconds(options.getConnectionTimeout().toMillis())); + .setConnectTimeout(Timeout.ofMilliseconds(options.getConnectionTimeout().toMillis())); } httpClientBuilder.setDefaultRequestConfig(requestConfigBuilder.build()); @@ -187,7 +193,7 @@ static ClientHttpRequestFactory usingOkHttp3(ClientOptions options) throws Gener if (usingCustomCerts(options)) { SSLSocketFactory socketFactory = sslCertificateUtils.getSSLContext(options.getCaCertFiles()) - .getSocketFactory(); + .getSocketFactory(); X509TrustManager trustManager = sslCertificateUtils.createTrustManager(options.getCaCertFiles()); builder.sslSocketFactory(socketFactory, trustManager); diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/configuration/SslCertificateUtils.java b/spring-credhub-core/src/main/java/org/springframework/credhub/configuration/SslCertificateUtils.java index 1ad212cf..01ce5850 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/configuration/SslCertificateUtils.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/configuration/SslCertificateUtils.java @@ -47,7 +47,7 @@ class SslCertificateUtils { X509TrustManager getDefaultX509TrustManager() { try { TrustManagerFactory trustManagerFactory = TrustManagerFactory - .getInstance(TrustManagerFactory.getDefaultAlgorithm()); + .getInstance(TrustManagerFactory.getDefaultAlgorithm()); trustManagerFactory.init((KeyStore) null); TrustManager[] trustManagers = trustManagerFactory.getTrustManagers(); @@ -86,7 +86,7 @@ TrustManagerFactory createTrustManagerFactory(String[] caCertFiles) { KeyStore trustStore = loadCertificateStore(caCertFiles); TrustManagerFactory trustManagerFactory = TrustManagerFactory - .getInstance(TrustManagerFactory.getDefaultAlgorithm()); + .getInstance(TrustManagerFactory.getDefaultAlgorithm()); trustManagerFactory.init(trustStore); return trustManagerFactory; diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/core/CredHubOAuth2RequestInterceptor.java b/spring-credhub-core/src/main/java/org/springframework/credhub/core/CredHubOAuth2RequestInterceptor.java index e7d700c3..7f26c735 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/core/CredHubOAuth2RequestInterceptor.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/core/CredHubOAuth2RequestInterceptor.java @@ -67,8 +67,9 @@ public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttp private OAuth2AuthorizedClient authorizeClient() { OAuth2AuthorizeRequest authorizeRequest = OAuth2AuthorizeRequest - .withClientRegistrationId(this.clientRegistration.getRegistrationId()) - .principal(new OAuth2ClientCredentialsGrantAuthenticationToken(this.clientRegistration)).build(); + .withClientRegistrationId(this.clientRegistration.getRegistrationId()) + .principal(new OAuth2ClientCredentialsGrantAuthenticationToken(this.clientRegistration)) + .build(); return this.clientManager.authorize(authorizeRequest); } diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/core/CredHubRestTemplateFactory.java b/spring-credhub-core/src/main/java/org/springframework/credhub/core/CredHubRestTemplateFactory.java index b218d7e4..a3caae74 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/core/CredHubRestTemplateFactory.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/core/CredHubRestTemplateFactory.java @@ -131,9 +131,9 @@ private static void configureRestTemplate(RestTemplate restTemplate, String base restTemplate.setRequestFactory(clientHttpRequestFactory); restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(baseUri)); restTemplate.getInterceptors().add(new CredHubRequestInterceptor()); - restTemplate.setMessageConverters( - Arrays.asList(new ByteArrayHttpMessageConverter(), new StringHttpMessageConverter(), - new MappingJackson2HttpMessageConverter(JsonUtils.buildObjectMapper()))); + restTemplate + .setMessageConverters(Arrays.asList(new ByteArrayHttpMessageConverter(), new StringHttpMessageConverter(), + new MappingJackson2HttpMessageConverter(JsonUtils.buildObjectMapper()))); } /** @@ -168,9 +168,9 @@ private static OAuth2AuthorizedClientManager buildClientManager( ClientHttpRequestFactory clientHttpRequestFactory) { OAuth2AuthorizedClientProvider authorizedClientProvider = OAuth2AuthorizedClientProviderBuilder.builder() - .authorizationCode().clientCredentials( - (b) -> b.accessTokenResponseClient(buildTokenResponseClient(clientHttpRequestFactory))) - .build(); + .authorizationCode() + .clientCredentials((b) -> b.accessTokenResponseClient(buildTokenResponseClient(clientHttpRequestFactory))) + .build(); DefaultOAuth2AuthorizedClientManager authorizedClientManager = new DefaultOAuth2AuthorizedClientManager( clientRegistrationRepository, authorizedClientRepository); diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/core/CredHubWebClientFactory.java b/spring-credhub-core/src/main/java/org/springframework/credhub/core/CredHubWebClientFactory.java index 79806d38..9112bab6 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/core/CredHubWebClientFactory.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/core/CredHubWebClientFactory.java @@ -93,16 +93,18 @@ static WebClient createWebClient(CredHubProperties properties, ClientHttpConnect ServerOAuth2AuthorizedClientExchangeFilterFunction oauth = new ServerOAuth2AuthorizedClientExchangeFilterFunction( clientManager); - return buildWebClient(properties.getUrl(), clientHttpConnector).filter(oauth).defaultRequest( - (requestHeadersSpec) -> requestHeadersSpec.attributes(ServerOAuth2AuthorizedClientExchangeFilterFunction - .clientRegistrationId(properties.getOauth2().getRegistrationId()))) - .build(); + return buildWebClient(properties.getUrl(), clientHttpConnector).filter(oauth) + .defaultRequest((requestHeadersSpec) -> requestHeadersSpec + .attributes(ServerOAuth2AuthorizedClientExchangeFilterFunction + .clientRegistrationId(properties.getOauth2().getRegistrationId()))) + .build(); } private static ReactiveOAuth2AuthorizedClientProvider buildClientProvider(ClientHttpConnector clientHttpConnector) { - return ReactiveOAuth2AuthorizedClientProviderBuilder.builder().authorizationCode() - .clientCredentials((b) -> b.accessTokenResponseClient(buildTokenResponseClient(clientHttpConnector))) - .build(); + return ReactiveOAuth2AuthorizedClientProviderBuilder.builder() + .authorizationCode() + .clientCredentials((b) -> b.accessTokenResponseClient(buildTokenResponseClient(clientHttpConnector))) + .build(); } private static WebClientReactiveClientCredentialsTokenResponseClient buildTokenResponseClient( @@ -131,10 +133,12 @@ private static WebClient.Builder buildWebClient(String baseUri, ClientHttpConnec dc.jackson2JsonEncoder(new Jackson2JsonEncoder(mapper)); }).build(); - return WebClient.builder().clientConnector(clientHttpConnector).baseUrl(baseUri) - .defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE) - .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) - .exchangeStrategies(strategies); + return WebClient.builder() + .clientConnector(clientHttpConnector) + .baseUrl(baseUri) + .defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE) + .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .exchangeStrategies(strategies); } } diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/core/certificate/CredHubCertificateTemplate.java b/spring-credhub-core/src/main/java/org/springframework/credhub/core/certificate/CredHubCertificateTemplate.java index dd77c529..95880751 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/core/certificate/CredHubCertificateTemplate.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/core/certificate/CredHubCertificateTemplate.java @@ -127,7 +127,7 @@ public List regenerate(final CredentialName certificateName) { request.put(SIGNED_BY_REQUEST_FIELD, certificateName.getName()); ResponseEntity>> response = restOperations - .exchange(BULK_REGENERATE_URL_PATH, HttpMethod.POST, new HttpEntity<>(request), ref); + .exchange(BULK_REGENERATE_URL_PATH, HttpMethod.POST, new HttpEntity<>(request), ref); ExceptionUtils.throwExceptionOnError(response); @@ -146,7 +146,7 @@ public List updateTransitionalVersion(final String request.put(VERSION_REQUEST_FIELD, versionId); ResponseEntity> response = restOperations - .exchange(UPDATE_TRANSITIONAL_URL_PATH, HttpMethod.PUT, new HttpEntity(request), ref, id); + .exchange(UPDATE_TRANSITIONAL_URL_PATH, HttpMethod.PUT, new HttpEntity(request), ref, id); ExceptionUtils.throwExceptionOnError(response); diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/core/certificate/ReactiveCredHubCertificateTemplate.java b/spring-credhub-core/src/main/java/org/springframework/credhub/core/certificate/ReactiveCredHubCertificateTemplate.java index e78c55be..1c85fbdd 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/core/certificate/ReactiveCredHubCertificateTemplate.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/core/certificate/ReactiveCredHubCertificateTemplate.java @@ -72,19 +72,26 @@ public ReactiveCredHubCertificateTemplate(ReactiveCredHubOperations credHubOpera @Override public Flux getAll() { - return this.credHubOperations.doWithWebClient((webClient) -> webClient.get().uri(BASE_URL_PATH).retrieve() - .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(CertificateSummaryData.class) - .flatMapMany((data) -> Flux.fromIterable(data.getCertificates()))); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.get() + .uri(BASE_URL_PATH) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToMono(CertificateSummaryData.class) + .flatMapMany((data) -> Flux.fromIterable(data.getCertificates()))); } @Override public Mono getByName(final CredentialName name) { Assert.notNull(name, "certificate name must not be null"); - return this.credHubOperations.doWithWebClient((webClient) -> webClient.get().uri(NAME_URL_QUERY, name.getName()) - .retrieve().onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + return this.credHubOperations + .doWithWebClient((webClient) -> webClient.get() + .uri(NAME_URL_QUERY, name.getName()) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) .bodyToMono(CertificateSummaryData.class) - .flatMapMany((data) -> Flux.fromIterable(data.getCertificates()))).single(); + .flatMapMany((data) -> Flux.fromIterable(data.getCertificates()))) + .single(); } @Override @@ -97,9 +104,12 @@ public Mono regenerate(final String id, final bool Map request = new HashMap<>(1); request.put(TRANSITIONAL_REQUEST_FIELD, setAsTransitional); - return this.credHubOperations - .doWithWebClient((webClient) -> webClient.post().uri(REGENERATE_URL_PATH, id).bodyValue(request) - .retrieve().onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(ref)); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.post() + .uri(REGENERATE_URL_PATH, id) + .bodyValue(request) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToMono(ref)); } @Override @@ -112,10 +122,13 @@ public Flux regenerate(final CredentialName certificateName) { Map request = new HashMap<>(1); request.put(SIGNED_BY_REQUEST_FIELD, certificateName.getName()); - return this.credHubOperations - .doWithWebClient((webClient) -> webClient.post().uri(BULK_REGENERATE_URL_PATH).bodyValue(request) - .retrieve().onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToFlux(ref) - .flatMap((body) -> Flux.fromIterable(body.get(REGENERATED_CREDENTIALS_RESPONSE_FIELD)))); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.post() + .uri(BULK_REGENERATE_URL_PATH) + .bodyValue(request) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToFlux(ref) + .flatMap((body) -> Flux.fromIterable(body.get(REGENERATED_CREDENTIALS_RESPONSE_FIELD)))); } public Flux updateTransitionalVersion(final String id, final String versionId) { @@ -124,10 +137,12 @@ public Flux updateTransitionalVersion(final String Map request = new HashMap<>(1); request.put(VERSION_REQUEST_FIELD, versionId); - return this.credHubOperations - .doWithWebClient((webClient) -> webClient.put().uri(UPDATE_TRANSITIONAL_URL_PATH, id).bodyValue(request) - .retrieve().onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) - .bodyToFlux(CertificateCredentialDetails.class)); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.put() + .uri(UPDATE_TRANSITIONAL_URL_PATH, id) + .bodyValue(request) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToFlux(CertificateCredentialDetails.class)); } } diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/core/credential/ReactiveCredHubCredentialTemplate.java b/spring-credhub-core/src/main/java/org/springframework/credhub/core/credential/ReactiveCredHubCredentialTemplate.java index 77317f0f..51333436 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/core/credential/ReactiveCredHubCredentialTemplate.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/core/credential/ReactiveCredHubCredentialTemplate.java @@ -78,9 +78,12 @@ public Mono> write(final CredentialRequest credentia final ParameterizedTypeReference> ref = new ParameterizedTypeReference>() { }; - return this.credHubOperations - .doWithWebClient((webClient) -> webClient.put().uri(BASE_URL_PATH).bodyValue(credentialRequest) - .retrieve().onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(ref)); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.put() + .uri(BASE_URL_PATH) + .bodyValue(credentialRequest) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToMono(ref)); } @Override @@ -91,9 +94,12 @@ public Mono> generate(final ParametersRequest

par final ParameterizedTypeReference> ref = new ParameterizedTypeReference>() { }; - return this.credHubOperations - .doWithWebClient((webClient) -> webClient.post().uri(BASE_URL_PATH).bodyValue(parametersRequest) - .retrieve().onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(ref)); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.post() + .uri(BASE_URL_PATH) + .bodyValue(parametersRequest) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToMono(ref)); } @Override @@ -107,9 +113,12 @@ public Mono> regenerate(final CredentialName name, Clas Map request = new HashMap<>(1); request.put(NAME_REQUEST_FIELD, name.getName()); - return this.credHubOperations - .doWithWebClient((webClient) -> webClient.post().uri(REGENERATE_URL_PATH).bodyValue(request).retrieve() - .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(ref)); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.post() + .uri(REGENERATE_URL_PATH) + .bodyValue(request) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToMono(ref)); } @Override @@ -120,8 +129,11 @@ public Mono> getById(final String id, final Class cr final ParameterizedTypeReference> ref = new ParameterizedTypeReference>() { }; - return this.credHubOperations.doWithWebClient((webClient) -> webClient.get().uri(ID_URL_PATH, id).retrieve() - .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(ref)); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.get() + .uri(ID_URL_PATH, id) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToMono(ref)); } @Override @@ -132,10 +144,12 @@ public Mono> getByName(final CredentialName name, final final ParameterizedTypeReference> ref = new ParameterizedTypeReference>() { }; - return this.credHubOperations - .doWithWebClient((webClient) -> webClient.get().uri(NAME_URL_QUERY_CURRENT, name.getName()).retrieve() - .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(ref) - .map((body) -> body.getData().get(0))); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.get() + .uri(NAME_URL_QUERY_CURRENT, name.getName()) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToMono(ref) + .map((body) -> body.getData().get(0))); } @Override @@ -147,9 +161,12 @@ public Flux> getByNameWithHistory(final CredentialName final ParameterizedTypeReference> ref = new ParameterizedTypeReference>() { }; - return this.credHubOperations.doWithWebClient((webClient) -> webClient.get().uri(NAME_URL_QUERY, name.getName()) - .retrieve().onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToFlux(ref) - .flatMap((body) -> Flux.fromIterable(body.getData()))); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.get() + .uri(NAME_URL_QUERY, name.getName()) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToFlux(ref) + .flatMap((body) -> Flux.fromIterable(body.getData()))); } @Override @@ -161,10 +178,12 @@ public Flux> getByNameWithHistory(final CredentialName final ParameterizedTypeReference> ref = new ParameterizedTypeReference>() { }; - return this.credHubOperations - .doWithWebClient((webClient) -> webClient.get().uri(NAME_URL_QUERY_VERSIONS, name.getName(), versions) - .retrieve().onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToFlux(ref) - .flatMap((body) -> Flux.fromIterable(body.getData()))); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.get() + .uri(NAME_URL_QUERY_VERSIONS, name.getName(), versions) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToFlux(ref) + .flatMap((body) -> Flux.fromIterable(body.getData()))); } @Override @@ -172,28 +191,34 @@ public Flux findByName(final CredentialName name) { Assert.notNull(name, "credential name must not be null"); return this.credHubOperations.doWithWebClient((webClient) -> webClient.get() - .uri(NAME_LIKE_URL_QUERY, name.getName()).retrieve() - .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(CredentialSummaryData.class) - .flatMapMany((data) -> Flux.fromIterable(data.getCredentials()))); + .uri(NAME_LIKE_URL_QUERY, name.getName()) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToMono(CredentialSummaryData.class) + .flatMapMany((data) -> Flux.fromIterable(data.getCredentials()))); } @Override public Flux findByPath(final String path) { Assert.notNull(path, "credential path must not be null"); - return this.credHubOperations.doWithWebClient((webClient) -> webClient.get().uri(PATH_URL_QUERY, path) - .retrieve().onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) - .bodyToMono(CredentialSummaryData.class) - .flatMapMany((data) -> Flux.fromIterable(data.getCredentials()))); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.get() + .uri(PATH_URL_QUERY, path) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToMono(CredentialSummaryData.class) + .flatMapMany((data) -> Flux.fromIterable(data.getCredentials()))); } @Override public Mono deleteByName(final CredentialName name) { Assert.notNull(name, "credential name must not be null"); - return this.credHubOperations - .doWithWebClient((webClient) -> webClient.delete().uri(NAME_URL_QUERY, name.getName()).retrieve() - .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(Void.class)); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.delete() + .uri(NAME_URL_QUERY, name.getName()) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToMono(Void.class)); } } diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/core/info/ReactiveCredHubInfoTemplate.java b/spring-credhub-core/src/main/java/org/springframework/credhub/core/info/ReactiveCredHubInfoTemplate.java index 0a9c4b16..58b526dc 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/core/info/ReactiveCredHubInfoTemplate.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/core/info/ReactiveCredHubInfoTemplate.java @@ -49,8 +49,11 @@ public ReactiveCredHubInfoTemplate(ReactiveCredHubOperations credHubOperations) */ @Override public Mono version() { - return this.credHubOperations.doWithWebClient((webClient) -> webClient.get().uri(VERSION_URL_PATH).retrieve() - .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(VersionInfo.class)); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.get() + .uri(VERSION_URL_PATH) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToMono(VersionInfo.class)); } } diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/core/interpolation/ReactiveCredHubInterpolationTemplate.java b/spring-credhub-core/src/main/java/org/springframework/credhub/core/interpolation/ReactiveCredHubInterpolationTemplate.java index b9c3947e..31243c0e 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/core/interpolation/ReactiveCredHubInterpolationTemplate.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/core/interpolation/ReactiveCredHubInterpolationTemplate.java @@ -50,9 +50,12 @@ public ReactiveCredHubInterpolationTemplate(ReactiveCredHubOperations credHubOpe public Mono interpolateServiceData(final ServicesData serviceData) { Assert.notNull(serviceData, "serviceData must not be null"); - return this.credHubOperations.doWithWebClient( - (webClient) -> webClient.post().uri(INTERPOLATE_URL_PATH).bodyValue(serviceData).retrieve() - .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(ServicesData.class)); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.post() + .uri(INTERPOLATE_URL_PATH) + .bodyValue(serviceData) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToMono(ServicesData.class)); } } diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/core/permission/ReactiveCredHubPermissionTemplate.java b/spring-credhub-core/src/main/java/org/springframework/credhub/core/permission/ReactiveCredHubPermissionTemplate.java index 2b9b0c28..a9ced84c 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/core/permission/ReactiveCredHubPermissionTemplate.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/core/permission/ReactiveCredHubPermissionTemplate.java @@ -57,9 +57,11 @@ public Flux getPermissions(final CredentialName name) { Assert.notNull(name, "credential name must not be null"); return this.credHubOperations.doWithWebClient((webClient) -> webClient.get() - .uri(PERMISSIONS_URL_QUERY, name.getName()).retrieve() - .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(CredentialPermissions.class) - .flatMapMany((data) -> Flux.fromIterable(data.getPermissions()))); + .uri(PERMISSIONS_URL_QUERY, name.getName()) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToMono(CredentialPermissions.class) + .flatMapMany((data) -> Flux.fromIterable(data.getPermissions()))); } @Override @@ -68,9 +70,12 @@ public Mono addPermissions(final CredentialName name, final Permission... final CredentialPermissions credentialPermissions = new CredentialPermissions(name, permissions); - return this.credHubOperations.doWithWebClient( - (webClient) -> webClient.post().uri(PERMISSIONS_URL_PATH).bodyValue(credentialPermissions).retrieve() - .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(Void.class)); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.post() + .uri(PERMISSIONS_URL_PATH) + .bodyValue(credentialPermissions) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToMono(Void.class)); } @Override @@ -79,8 +84,10 @@ public Mono deletePermission(final CredentialName name, final Actor actor) Assert.notNull(actor, "actor must not be null"); return this.credHubOperations.doWithWebClient((webClient) -> webClient.delete() - .uri(PERMISSIONS_ACTOR_URL_QUERY, name.getName(), actor.getIdentity()).retrieve() - .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(Void.class)); + .uri(PERMISSIONS_ACTOR_URL_QUERY, name.getName(), actor.getIdentity()) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToMono(Void.class)); } } diff --git a/spring-credhub-core/src/main/java/org/springframework/credhub/core/permissionV2/ReactiveCredHubPermissionV2Template.java b/spring-credhub-core/src/main/java/org/springframework/credhub/core/permissionV2/ReactiveCredHubPermissionV2Template.java index af2a6720..7f58c679 100644 --- a/spring-credhub-core/src/main/java/org/springframework/credhub/core/permissionV2/ReactiveCredHubPermissionV2Template.java +++ b/spring-credhub-core/src/main/java/org/springframework/credhub/core/permissionV2/ReactiveCredHubPermissionV2Template.java @@ -56,8 +56,10 @@ public ReactiveCredHubPermissionV2Template(ReactiveCredHubOperations credHubOper public Mono getPermissions(final String id) { Assert.notNull(id, "credential ID must not be null"); - return this.credHubOperations.doWithWebClient((webClient) -> webClient.get().uri(PERMISSIONS_ID_URL_PATH, id) - .retrieve().bodyToMono(CredentialPermission.class)); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.get() + .uri(PERMISSIONS_ID_URL_PATH, id) + .retrieve() + .bodyToMono(CredentialPermission.class)); } @Override @@ -67,9 +69,12 @@ public Mono addPermissions(final CredentialName path, fina final CredentialPermission credentialPermission = new CredentialPermission(path, permission); - return this.credHubOperations.doWithWebClient((webClient) -> webClient.post().uri(PERMISSIONS_URL_PATH) - .bodyValue(credentialPermission).retrieve() - .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(CredentialPermission.class)); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.post() + .uri(PERMISSIONS_URL_PATH) + .bodyValue(credentialPermission) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToMono(CredentialPermission.class)); } @Override @@ -78,8 +83,10 @@ public Mono getPermissionsByPathAndActor(final CredentialN Assert.notNull(actor, "credential actor must not be null"); return this.credHubOperations.doWithWebClient((webClient) -> webClient.get() - .uri(PERMISSIONS_PATH_ACTOR_URL_QUERY, path.getName(), actor.getIdentity()).retrieve() - .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(CredentialPermission.class)); + .uri(PERMISSIONS_PATH_ACTOR_URL_QUERY, path.getName(), actor.getIdentity()) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToMono(CredentialPermission.class)); } @Override @@ -91,17 +98,23 @@ public Mono updatePermissions(final String id, final Crede final CredentialPermission credentialPermission = new CredentialPermission(path, permission); - return this.credHubOperations.doWithWebClient((webClient) -> webClient.put().uri(PERMISSIONS_ID_URL_PATH, id) - .bodyValue(credentialPermission).retrieve() - .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(CredentialPermission.class)); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.put() + .uri(PERMISSIONS_ID_URL_PATH, id) + .bodyValue(credentialPermission) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToMono(CredentialPermission.class)); } @Override public Mono deletePermission(final String id) { Assert.notNull(id, "credential ID must not be null"); - return this.credHubOperations.doWithWebClient((webClient) -> webClient.delete().uri(PERMISSIONS_ID_URL_PATH, id) - .retrieve().onStatus(HttpStatusCode::isError, ExceptionUtils::buildError).bodyToMono(Void.class)); + return this.credHubOperations.doWithWebClient((webClient) -> webClient.delete() + .uri(PERMISSIONS_ID_URL_PATH, id) + .retrieve() + .onStatus(HttpStatusCode::isError, ExceptionUtils::buildError) + .bodyToMono(Void.class)); } } diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/core/certificate/CredHubCertificateTemplateUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/core/certificate/CredHubCertificateTemplateUnitTests.java index 919a59a3..af86f979 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/core/certificate/CredHubCertificateTemplateUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/core/certificate/CredHubCertificateTemplateUnitTests.java @@ -69,7 +69,7 @@ public void getAll() { new CertificateSummary("id2", "name2"), new CertificateSummary("id3", "name3")); given(this.restTemplate.getForEntity(CredHubCertificateTemplate.BASE_URL_PATH, CertificateSummaryData.class)) - .willReturn(new ResponseEntity<>(expectedCertificates, HttpStatus.OK)); + .willReturn(new ResponseEntity<>(expectedCertificates, HttpStatus.OK)); List response = this.credHubTemplate.getAll(); @@ -84,7 +84,8 @@ public void getByName() { new CertificateSummary("id1", "name1")); given(this.restTemplate.getForEntity(CredHubCertificateTemplate.NAME_URL_QUERY, CertificateSummaryData.class, - NAME.getName())).willReturn(new ResponseEntity<>(expectedCertificates, HttpStatus.OK)); + NAME.getName())) + .willReturn(new ResponseEntity<>(expectedCertificates, HttpStatus.OK)); CertificateSummary response = this.credHubTemplate.getByName(NAME); @@ -104,7 +105,7 @@ public void regenerate() { given(this.restTemplate.exchange(eq(CredHubCertificateTemplate.REGENERATE_URL_PATH), eq(HttpMethod.POST), eq(new HttpEntity<>(request)), isA(ParameterizedTypeReference.class), eq("id"))) - .willReturn(new ResponseEntity<>(expectedCertificate, HttpStatus.OK)); + .willReturn(new ResponseEntity<>(expectedCertificate, HttpStatus.OK)); CertificateCredentialDetails response = this.credHubTemplate.regenerate("id", true); @@ -133,13 +134,13 @@ public void bulkRegenerate() { given(this.restTemplate.exchange(eq(CredHubCertificateTemplate.BULK_REGENERATE_URL_PATH), eq(HttpMethod.POST), eq(new HttpEntity<>(request)), isA(ParameterizedTypeReference.class))) - .willReturn(new ResponseEntity<>(expectedResponse, HttpStatus.OK)); + .willReturn(new ResponseEntity<>(expectedResponse, HttpStatus.OK)); List response = this.credHubTemplate.regenerate(NAME); assertThat(response).isNotNull(); assertThat(response) - .isEqualTo(expectedResponse.get(CredHubCertificateTemplate.REGENERATED_CREDENTIALS_RESPONSE_FIELD)); + .isEqualTo(expectedResponse.get(CredHubCertificateTemplate.REGENERATED_CREDENTIALS_RESPONSE_FIELD)); } @Test @@ -156,14 +157,14 @@ public void updateTransitionalVersion() { given(this.restTemplate.exchange(eq(CredHubCertificateTemplate.UPDATE_TRANSITIONAL_URL_PATH), eq(HttpMethod.PUT), eq(new HttpEntity<>(request)), isA(ParameterizedTypeReference.class), eq("id1"))) - .willReturn(new ResponseEntity<>(expectedCertificates, HttpStatus.OK)); + .willReturn(new ResponseEntity<>(expectedCertificates, HttpStatus.OK)); List response = this.credHubTemplate.updateTransitionalVersion("id1", "id2"); assertThat(response).hasSize(2); assertThat(response).extracting("id").contains("id1", "id2"); - assertThat(response).extracting("credentialType").contains(CredentialType.CERTIFICATE, - CredentialType.CERTIFICATE); + assertThat(response).extracting("credentialType") + .contains(CredentialType.CERTIFICATE, CredentialType.CERTIFICATE); assertThat(response).extracting("transitional").contains(false, true); assertThat(response).extracting("value.certificate").contains("cert1", "cert2"); assertThat(response).extracting("value.certificateAuthority").contains("authority1", "authority2"); diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/core/credential/CredHubCredentialTemplateSummaryUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/core/credential/CredHubCredentialTemplateSummaryUnitTests.java index de5c49fc..2156482d 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/core/credential/CredHubCredentialTemplateSummaryUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/core/credential/CredHubCredentialTemplateSummaryUnitTests.java @@ -41,7 +41,8 @@ public class CredHubCredentialTemplateSummaryUnitTests extends CredHubCredential @ArgumentsSource(ResponseArgumentsProvider.class) public void findByName(ResponseEntity expectedResponse) { given(this.restTemplate.getForEntity(CredHubCredentialTemplate.NAME_LIKE_URL_QUERY, CredentialSummaryData.class, - NAME.getName())).willReturn(expectedResponse); + NAME.getName())) + .willReturn(expectedResponse); if (!expectedResponse.getStatusCode().equals(HttpStatus.OK)) { try { @@ -63,7 +64,8 @@ public void findByName(ResponseEntity expectedResponse) { @ArgumentsSource(ResponseArgumentsProvider.class) public void findByPath(ResponseEntity expectedResponse) { given(this.restTemplate.getForEntity(CredHubCredentialTemplate.PATH_URL_QUERY, CredentialSummaryData.class, - NAME.getName())).willReturn(expectedResponse); + NAME.getName())) + .willReturn(expectedResponse); if (!expectedResponse.getStatusCode().equals(HttpStatus.OK)) { try { diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/core/credential/CredHubTemplateDetailCertificateUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/core/credential/CredHubTemplateDetailCertificateUnitTests.java index 089f19ae..6eb315b4 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/core/credential/CredHubTemplateDetailCertificateUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/core/credential/CredHubTemplateDetailCertificateUnitTests.java @@ -41,8 +41,10 @@ public class CredHubTemplateDetailCertificateUnitTests private static final CertificateCredential CREDENTIAL = new CertificateCredential("certificate", "authority", "private-key"); - private static final CertificateParameters PARAMETERS = CertificateParameters.builder().commonName("common") - .certificateAuthorityCredential("credential").build(); + private static final CertificateParameters PARAMETERS = CertificateParameters.builder() + .commonName("common") + .certificateAuthorityCredential("credential") + .build(); @Override public CredentialRequest getWriteRequest() { diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/core/credential/CredHubTemplateDetailUnitTestsBase.java b/spring-credhub-core/src/test/java/org/springframework/credhub/core/credential/CredHubTemplateDetailUnitTestsBase.java index b461f870..29935fa2 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/core/credential/CredHubTemplateDetailUnitTestsBase.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/core/credential/CredHubTemplateDetailUnitTestsBase.java @@ -63,8 +63,8 @@ static Stream buildDetailArguments(CredentialType type, static Stream buildDataArguments(CredentialType type, T credential) { return Stream.of( - Arguments.of(ResponseEntity.ok().body( - new CredentialDetailsData<>(new CredentialDetails<>(CREDENTIAL_ID, NAME, type, credential)))), + Arguments.of(ResponseEntity.ok() + .body(new CredentialDetailsData<>(new CredentialDetails<>(CREDENTIAL_ID, NAME, type, credential)))), Arguments.of(ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new CredentialDetailsData<>()))); } @@ -72,7 +72,8 @@ void verifyWrite(ResponseEntity> expectedResponse) { CredentialRequest request = getWriteRequest(); given(this.restTemplate.exchange(eq(CredHubCredentialTemplate.BASE_URL_PATH), eq(HttpMethod.PUT), - eq(new HttpEntity<>(request)), isA(ParameterizedTypeReference.class))).willReturn(expectedResponse); + eq(new HttpEntity<>(request)), isA(ParameterizedTypeReference.class))) + .willReturn(expectedResponse); if (!expectedResponse.getStatusCode().equals(HttpStatus.OK)) { try { @@ -94,7 +95,8 @@ void verifyGenerate(ResponseEntity> expectedResponse) { ParametersRequest

request = getGenerateRequest(); given(this.restTemplate.exchange(eq(CredHubCredentialTemplate.BASE_URL_PATH), eq(HttpMethod.POST), - eq(new HttpEntity<>(request)), isA(ParameterizedTypeReference.class))).willReturn(expectedResponse); + eq(new HttpEntity<>(request)), isA(ParameterizedTypeReference.class))) + .willReturn(expectedResponse); if (!expectedResponse.getStatusCode().equals(HttpStatus.OK)) { try { @@ -120,7 +122,8 @@ void verifyRegenerate(ResponseEntity> expectedResponse) { }; given(this.restTemplate.exchange(eq(CredHubCredentialTemplate.REGENERATE_URL_PATH), eq(HttpMethod.POST), - eq(new HttpEntity<>(request)), isA(ParameterizedTypeReference.class))).willReturn(expectedResponse); + eq(new HttpEntity<>(request)), isA(ParameterizedTypeReference.class))) + .willReturn(expectedResponse); if (!expectedResponse.getStatusCode().equals(HttpStatus.OK)) { try { @@ -140,7 +143,8 @@ void verifyRegenerate(ResponseEntity> expectedResponse) { void verifyGetById(ResponseEntity> expectedResponse) { given(this.restTemplate.exchange(eq(CredHubCredentialTemplate.ID_URL_PATH), eq(HttpMethod.GET), isNull(), - isA(ParameterizedTypeReference.class), eq(CREDENTIAL_ID))).willReturn(expectedResponse); + isA(ParameterizedTypeReference.class), eq(CREDENTIAL_ID))) + .willReturn(expectedResponse); if (!expectedResponse.getStatusCode().equals(HttpStatus.OK)) { try { @@ -160,7 +164,8 @@ void verifyGetById(ResponseEntity> expectedResponse) { void verifyGetByName(ResponseEntity> expectedResponse) { given(this.restTemplate.exchange(eq(CredHubCredentialTemplate.NAME_URL_QUERY_CURRENT), eq(HttpMethod.GET), - isNull(), isA(ParameterizedTypeReference.class), eq(NAME.getName()))).willReturn(expectedResponse); + isNull(), isA(ParameterizedTypeReference.class), eq(NAME.getName()))) + .willReturn(expectedResponse); if (!expectedResponse.getStatusCode().equals(HttpStatus.OK)) { try { @@ -180,7 +185,8 @@ void verifyGetByName(ResponseEntity> expectedResponse) void verifyGetByNameWithHistory(ResponseEntity> expectedResponse) { given(this.restTemplate.exchange(eq(CredHubCredentialTemplate.NAME_URL_QUERY), eq(HttpMethod.GET), isNull(), - isA(ParameterizedTypeReference.class), eq(NAME.getName()))).willReturn(expectedResponse); + isA(ParameterizedTypeReference.class), eq(NAME.getName()))) + .willReturn(expectedResponse); if (!expectedResponse.getStatusCode().equals(HttpStatus.OK)) { try { @@ -201,7 +207,7 @@ void verifyGetByNameWithHistory(ResponseEntity> expecte void verifyGetByNameWithVersions(ResponseEntity> expectedResponse) { given(this.restTemplate.exchange(eq(CredHubCredentialTemplate.NAME_URL_QUERY_VERSIONS), eq(HttpMethod.GET), isNull(), isA(ParameterizedTypeReference.class), eq(NAME.getName()), eq(5))) - .willReturn(expectedResponse); + .willReturn(expectedResponse); if (!expectedResponse.getStatusCode().equals(HttpStatus.OK)) { try { diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/core/info/CredHubInfoTemplateUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/core/info/CredHubInfoTemplateUnitTests.java index 494ff056..0c6852a7 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/core/info/CredHubInfoTemplateUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/core/info/CredHubInfoTemplateUnitTests.java @@ -50,7 +50,7 @@ public void setUp() { @Test public void getVersion() { given(this.restTemplate.getForEntity(CredHubInfoTemplate.VERSION_URL_PATH, VersionInfo.class)) - .willReturn(new ResponseEntity<>(new VersionInfo("2.0.0"), HttpStatus.OK)); + .willReturn(new ResponseEntity<>(new VersionInfo("2.0.0"), HttpStatus.OK)); VersionInfo response = this.credHubTemplate.version(); diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/core/interpolation/CredHubInterpolationTemplateUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/core/interpolation/CredHubInterpolationTemplateUnitTests.java index 180c8ed0..926fe84b 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/core/interpolation/CredHubInterpolationTemplateUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/core/interpolation/CredHubInterpolationTemplateUnitTests.java @@ -57,8 +57,11 @@ public void setUp() { @Test public void interpolateServiceData() throws IOException { ServiceInstanceCredentialName credentialName = ServiceInstanceCredentialName.builder() - .serviceBrokerName("service-broker").serviceOfferingName("service-offering") - .serviceBindingId("1111-1111-1111-111").credentialName("credential_json").build(); + .serviceBrokerName("service-broker") + .serviceOfferingName("service-offering") + .serviceBindingId("1111-1111-1111-111") + .credentialName("credential_json") + .build(); ServicesData vcapServices = buildVcapServices(credentialName.getName()); @@ -66,7 +69,7 @@ public void interpolateServiceData() throws IOException { given(this.restTemplate.exchange(CredHubInterpolationTemplate.INTERPOLATE_URL_PATH, HttpMethod.POST, new HttpEntity<>(vcapServices), ServicesData.class)) - .willReturn(new ResponseEntity<>(expectedResponse, HttpStatus.OK)); + .willReturn(new ResponseEntity<>(expectedResponse, HttpStatus.OK)); ServicesData response = this.credHubTemplate.interpolateServiceData(vcapServices); diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/core/permission/CredHubPermissionTemplateUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/core/permission/CredHubPermissionTemplateUnitTests.java index 6e750987..cf58a2fb 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/core/permission/CredHubPermissionTemplateUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/core/permission/CredHubPermissionTemplateUnitTests.java @@ -63,12 +63,16 @@ public void setUp() { public void getPermissions() { CredentialPermissions expectedResponse = new CredentialPermissions(NAME, Permission.builder().app("app-id").operation(Operation.READ).operation(Operation.WRITE).build(), - Permission.builder().user("zone1", "user-id").operations(Operation.READ_ACL) - .operations(Operation.WRITE_ACL).operation(Operation.DELETE).build()); + Permission.builder() + .user("zone1", "user-id") + .operations(Operation.READ_ACL) + .operations(Operation.WRITE_ACL) + .operation(Operation.DELETE) + .build()); given(this.restTemplate.getForEntity(CredHubPermissionTemplate.PERMISSIONS_URL_QUERY, CredentialPermissions.class, NAME.getName())) - .willReturn(new ResponseEntity<>(expectedResponse, HttpStatus.OK)); + .willReturn(new ResponseEntity<>(expectedResponse, HttpStatus.OK)); List response = this.credHubTemplate.getPermissions(NAME); @@ -79,11 +83,18 @@ public void getPermissions() { @Test public void addPermissions() { - Permission permission1 = Permission.builder().app("app-id").operation(Operation.READ).operation(Operation.WRITE) - .build(); - - Permission permission2 = Permission.builder().user("zone1", "user-id").operations(Operation.READ_ACL) - .operations(Operation.WRITE_ACL).operation(Operation.DELETE).build(); + Permission permission1 = Permission.builder() + .app("app-id") + .operation(Operation.READ) + .operation(Operation.WRITE) + .build(); + + Permission permission2 = Permission.builder() + .user("zone1", "user-id") + .operations(Operation.READ_ACL) + .operations(Operation.WRITE_ACL) + .operation(Operation.DELETE) + .build(); this.credHubTemplate.addPermissions(NAME, permission1, permission2); diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/core/permissionV2/CredHubPermissionV2TemplateUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/core/permissionV2/CredHubPermissionV2TemplateUnitTests.java index cd6dcbe2..c092614e 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/core/permissionV2/CredHubPermissionV2TemplateUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/core/permissionV2/CredHubPermissionV2TemplateUnitTests.java @@ -63,7 +63,7 @@ public void getPermissions() { given(this.restTemplate.getForEntity(CredHubPermissionV2Template.PERMISSIONS_ID_URL_PATH, CredentialPermission.class, permissionId)) - .willReturn(new ResponseEntity<>(expectedResponse, HttpStatus.OK)); + .willReturn(new ResponseEntity<>(expectedResponse, HttpStatus.OK)); CredentialPermission response = this.credHubTemplate.getPermissions(permissionId); @@ -83,7 +83,7 @@ public void getPermissionsByPathAndActor() { String actor = ActorType.OAUTH_CLIENT + ":" + clientId; given(this.restTemplate.getForEntity(CredHubPermissionV2Template.PERMISSIONS_PATH_ACTOR_URL_QUERY, CredentialPermission.class, PATH.getName(), actor)) - .willReturn(new ResponseEntity<>(expectedResponse, HttpStatus.OK)); + .willReturn(new ResponseEntity<>(expectedResponse, HttpStatus.OK)); CredentialPermission response = this.credHubTemplate.getPermissionsByPathAndActor(PATH, Actor.client(clientId)); @@ -96,14 +96,17 @@ public void getPermissionsByPathAndActor() { @Test public void addPermissions() { - Permission permission = Permission.builder().app("app-id").operation(Operation.READ).operation(Operation.WRITE) - .build(); + Permission permission = Permission.builder() + .app("app-id") + .operation(Operation.READ) + .operation(Operation.WRITE) + .build(); CredentialPermission expectedResponse = new CredentialPermission(PATH, permission); given(this.restTemplate.exchange(CredHubPermissionV2Template.PERMISSIONS_URL_PATH, HttpMethod.POST, new HttpEntity<>(expectedResponse), CredentialPermission.class)) - .willReturn(new ResponseEntity<>(expectedResponse, HttpStatus.OK)); + .willReturn(new ResponseEntity<>(expectedResponse, HttpStatus.OK)); CredentialPermission response = this.credHubTemplate.addPermissions(PATH, permission); @@ -117,14 +120,17 @@ public void addPermissions() { public void updatePermissions() { String permissionId = "uuid"; - Permission permission = Permission.builder().app("app-id").operation(Operation.READ).operation(Operation.WRITE) - .build(); + Permission permission = Permission.builder() + .app("app-id") + .operation(Operation.READ) + .operation(Operation.WRITE) + .build(); CredentialPermission expectedResponse = new CredentialPermission(PATH, permission); given(this.restTemplate.exchange(CredHubPermissionV2Template.PERMISSIONS_ID_URL_PATH, HttpMethod.PUT, new HttpEntity<>(expectedResponse), CredentialPermission.class, permissionId)) - .willReturn(new ResponseEntity<>(expectedResponse, HttpStatus.OK)); + .willReturn(new ResponseEntity<>(expectedResponse, HttpStatus.OK)); CredentialPermission response = this.credHubTemplate.updatePermissions(permissionId, PATH, permission); diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/support/CertificateSummaryDataTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/support/CertificateSummaryDataTests.java index f49b0787..5323d68b 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/support/CertificateSummaryDataTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/support/CertificateSummaryDataTests.java @@ -44,10 +44,10 @@ public void deserializeWithCertificates() { CertificateSummaryData certificates = parseResponse(json, CertificateSummaryData.class); assertThat(certificates.getCertificates().size()).isEqualTo(2); - assertThat(certificates.getCertificates()).extracting("id").contains("2993f622-cb1e-4e00-a267-4b23c273bf3d", - "b40d3d3b-2cf5-4a73-babd-9dceefa9b0db"); - assertThat(certificates.getCertificates()).extracting("name").contains("/example-certificate-1", - "/example-certificate-2"); + assertThat(certificates.getCertificates()).extracting("id") + .contains("2993f622-cb1e-4e00-a267-4b23c273bf3d", "b40d3d3b-2cf5-4a73-babd-9dceefa9b0db"); + assertThat(certificates.getCertificates()).extracting("name") + .contains("/example-certificate-1", "/example-certificate-2"); } @Test diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/support/JsonParsingUnitTestsBase.java b/spring-credhub-core/src/test/java/org/springframework/credhub/support/JsonParsingUnitTestsBase.java index ccbecbbd..99f40e76 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/support/JsonParsingUnitTestsBase.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/support/JsonParsingUnitTestsBase.java @@ -79,7 +79,7 @@ protected void assertCommonDetails(CredentialDetails data) { assertThat(data.getVersionCreatedAt()).isEqualTo(this.testDate); assertThat(data.getId()).isEqualTo("80cbb13f-7562-4e72-92de-f3ccf69eaa59"); assertThat(data.getName().getName()) - .isEqualTo("/service-broker-name/service-instance-name/binding-id/credentials-json"); + .isEqualTo("/service-broker-name/service-instance-name/binding-id/credentials-json"); } } diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/support/JsonTestUtils.java b/spring-credhub-core/src/test/java/org/springframework/credhub/support/JsonTestUtils.java index cd6c3e27..a0bfb207 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/support/JsonTestUtils.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/support/JsonTestUtils.java @@ -58,8 +58,10 @@ public static T fromJson(String json, Class type) { } public static DocumentContext toJsonPath(Object object) { - Configuration configuration = Configuration.builder().jsonProvider(new JacksonJsonProvider()) - .mappingProvider(new JacksonMappingProvider()).build(); + Configuration configuration = Configuration.builder() + .jsonProvider(new JacksonJsonProvider()) + .mappingProvider(new JacksonMappingProvider()) + .build(); return JsonPath.parse(toJson(object), configuration); } diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/support/certificate/CertificateCredentialRequestUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/support/certificate/CertificateCredentialRequestUnitTests.java index 7c36a6ef..d2e96b4e 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/support/certificate/CertificateCredentialRequestUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/support/certificate/CertificateCredentialRequestUnitTests.java @@ -84,7 +84,9 @@ public void serializeWithNoValues() { private void buildRequest(CertificateCredential value) { this.requestBuilder = CertificateCredentialRequest.builder() - .name(new SimpleCredentialName("example", "credential")).mode(WriteMode.OVERWRITE).value(value); + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.OVERWRITE) + .value(value); } } diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/support/certificate/CertificateParametersRequestUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/support/certificate/CertificateParametersRequestUnitTests.java index eaa1a088..ad90dd97 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/support/certificate/CertificateParametersRequestUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/support/certificate/CertificateParametersRequestUnitTests.java @@ -38,18 +38,27 @@ public void setUp() { @Test public void serializeWithParameters() { this.requestBuilder = CertificateParametersRequest.builder() - .name(new SimpleCredentialName("example", "credential")).mode(WriteMode.OVERWRITE) - .parameters(CertificateParameters.builder().keyLength(KeyLength.LENGTH_2048).commonName("common") - .alternateNames("alt1", "alt2").organization("org").organizationUnit("dev").locality("city") - .state("state").country("country").duration(1234).certificateAuthorityCredential("credential") - .certificateAuthority(true).selfSign(false) - .keyUsage(KeyUsage.CRL_SIGN, KeyUsage.DATA_ENCIPHERMENT, KeyUsage.DECIPHER_ONLY, - KeyUsage.DIGITAL_SIGNATURE, KeyUsage.ENCIPHER_ONLY, KeyUsage.KEY_AGREEMENT, - KeyUsage.KEY_CERT_SIGN, KeyUsage.KEY_ENCIPHERMENT, KeyUsage.NON_REPUDIATION) - .extendedKeyUsage(ExtendedKeyUsage.CLIENT_AUTH, ExtendedKeyUsage.CODE_SIGNING, - ExtendedKeyUsage.EMAIL_PROTECTION, ExtendedKeyUsage.SERVER_AUTH, - ExtendedKeyUsage.TIMESTAMPING) - .build()); + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.OVERWRITE) + .parameters(CertificateParameters.builder() + .keyLength(KeyLength.LENGTH_2048) + .commonName("common") + .alternateNames("alt1", "alt2") + .organization("org") + .organizationUnit("dev") + .locality("city") + .state("state") + .country("country") + .duration(1234) + .certificateAuthorityCredential("credential") + .certificateAuthority(true) + .selfSign(false) + .keyUsage(KeyUsage.CRL_SIGN, KeyUsage.DATA_ENCIPHERMENT, KeyUsage.DECIPHER_ONLY, + KeyUsage.DIGITAL_SIGNATURE, KeyUsage.ENCIPHER_ONLY, KeyUsage.KEY_AGREEMENT, + KeyUsage.KEY_CERT_SIGN, KeyUsage.KEY_ENCIPHERMENT, KeyUsage.NON_REPUDIATION) + .extendedKeyUsage(ExtendedKeyUsage.CLIENT_AUTH, ExtendedKeyUsage.CODE_SIGNING, + ExtendedKeyUsage.EMAIL_PROTECTION, ExtendedKeyUsage.SERVER_AUTH, ExtendedKeyUsage.TIMESTAMPING) + .build()); DocumentContext json = toJsonPath(this.requestBuilder); @@ -68,40 +77,56 @@ public void serializeWithParameters() { JsonPathAssert.assertThat(json).hasPath("$.parameters.is_ca").isEqualTo(true); JsonPathAssert.assertThat(json).hasPath("$.parameters.self_sign").isEqualTo(false); JsonPathAssert.assertThat(json).hasPath("$.parameters.key_usage[0]").isEqualTo(KeyUsage.CRL_SIGN.getValue()); - JsonPathAssert.assertThat(json).hasPath("$.parameters.key_usage[1]") - .isEqualTo(KeyUsage.DATA_ENCIPHERMENT.getValue()); - JsonPathAssert.assertThat(json).hasPath("$.parameters.key_usage[2]") - .isEqualTo(KeyUsage.DECIPHER_ONLY.getValue()); - JsonPathAssert.assertThat(json).hasPath("$.parameters.key_usage[3]") - .isEqualTo(KeyUsage.DIGITAL_SIGNATURE.getValue()); - JsonPathAssert.assertThat(json).hasPath("$.parameters.key_usage[4]") - .isEqualTo(KeyUsage.ENCIPHER_ONLY.getValue()); - JsonPathAssert.assertThat(json).hasPath("$.parameters.key_usage[5]") - .isEqualTo(KeyUsage.KEY_AGREEMENT.getValue()); - JsonPathAssert.assertThat(json).hasPath("$.parameters.key_usage[6]") - .isEqualTo(KeyUsage.KEY_CERT_SIGN.getValue()); - JsonPathAssert.assertThat(json).hasPath("$.parameters.key_usage[7]") - .isEqualTo(KeyUsage.KEY_ENCIPHERMENT.getValue()); - JsonPathAssert.assertThat(json).hasPath("$.parameters.key_usage[8]") - .isEqualTo(KeyUsage.NON_REPUDIATION.getValue()); - JsonPathAssert.assertThat(json).hasPath("$.parameters.extended_key_usage[0]") - .isEqualTo(ExtendedKeyUsage.CLIENT_AUTH.getValue()); - JsonPathAssert.assertThat(json).hasPath("$.parameters.extended_key_usage[1]") - .isEqualTo(ExtendedKeyUsage.CODE_SIGNING.getValue()); - JsonPathAssert.assertThat(json).hasPath("$.parameters.extended_key_usage[2]") - .isEqualTo(ExtendedKeyUsage.EMAIL_PROTECTION.getValue()); - JsonPathAssert.assertThat(json).hasPath("$.parameters.extended_key_usage[3]") - .isEqualTo(ExtendedKeyUsage.SERVER_AUTH.getValue()); - JsonPathAssert.assertThat(json).hasPath("$.parameters.extended_key_usage[4]") - .isEqualTo(ExtendedKeyUsage.TIMESTAMPING.getValue()); + JsonPathAssert.assertThat(json) + .hasPath("$.parameters.key_usage[1]") + .isEqualTo(KeyUsage.DATA_ENCIPHERMENT.getValue()); + JsonPathAssert.assertThat(json) + .hasPath("$.parameters.key_usage[2]") + .isEqualTo(KeyUsage.DECIPHER_ONLY.getValue()); + JsonPathAssert.assertThat(json) + .hasPath("$.parameters.key_usage[3]") + .isEqualTo(KeyUsage.DIGITAL_SIGNATURE.getValue()); + JsonPathAssert.assertThat(json) + .hasPath("$.parameters.key_usage[4]") + .isEqualTo(KeyUsage.ENCIPHER_ONLY.getValue()); + JsonPathAssert.assertThat(json) + .hasPath("$.parameters.key_usage[5]") + .isEqualTo(KeyUsage.KEY_AGREEMENT.getValue()); + JsonPathAssert.assertThat(json) + .hasPath("$.parameters.key_usage[6]") + .isEqualTo(KeyUsage.KEY_CERT_SIGN.getValue()); + JsonPathAssert.assertThat(json) + .hasPath("$.parameters.key_usage[7]") + .isEqualTo(KeyUsage.KEY_ENCIPHERMENT.getValue()); + JsonPathAssert.assertThat(json) + .hasPath("$.parameters.key_usage[8]") + .isEqualTo(KeyUsage.NON_REPUDIATION.getValue()); + JsonPathAssert.assertThat(json) + .hasPath("$.parameters.extended_key_usage[0]") + .isEqualTo(ExtendedKeyUsage.CLIENT_AUTH.getValue()); + JsonPathAssert.assertThat(json) + .hasPath("$.parameters.extended_key_usage[1]") + .isEqualTo(ExtendedKeyUsage.CODE_SIGNING.getValue()); + JsonPathAssert.assertThat(json) + .hasPath("$.parameters.extended_key_usage[2]") + .isEqualTo(ExtendedKeyUsage.EMAIL_PROTECTION.getValue()); + JsonPathAssert.assertThat(json) + .hasPath("$.parameters.extended_key_usage[3]") + .isEqualTo(ExtendedKeyUsage.SERVER_AUTH.getValue()); + JsonPathAssert.assertThat(json) + .hasPath("$.parameters.extended_key_usage[4]") + .isEqualTo(ExtendedKeyUsage.TIMESTAMPING.getValue()); } @Test public void serializeWithMinimalParameters() { this.requestBuilder = CertificateParametersRequest.builder() - .name(new SimpleCredentialName("example", "credential")).mode(WriteMode.NO_OVERWRITE) - .parameters(CertificateParameters.builder().commonName("common") - .certificateAuthorityCredential("credential").build()); + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.NO_OVERWRITE) + .parameters(CertificateParameters.builder() + .commonName("common") + .certificateAuthorityCredential("credential") + .build()); DocumentContext json = toJsonPath(this.requestBuilder); @@ -125,7 +150,8 @@ public void serializeWithMinimalParameters() { @Test public void serializeWithNoParameters() { this.requestBuilder = CertificateParametersRequest.builder() - .name(new SimpleCredentialName("example", "credential")).mode(WriteMode.CONVERGE); + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.CONVERGE); DocumentContext json = toJsonPath(this.requestBuilder); @@ -137,8 +163,8 @@ public void serializeWithNoParameters() { public void serializeWithEmptyParameters() { assertThatIllegalArgumentException().isThrownBy(() -> { this.requestBuilder = CertificateParametersRequest.builder() - .name(new SimpleCredentialName("example", "credential")) - .parameters(CertificateParameters.builder().keyLength(KeyLength.LENGTH_2048).build()); + .name(new SimpleCredentialName("example", "credential")) + .parameters(CertificateParameters.builder().keyLength(KeyLength.LENGTH_2048).build()); toJsonPath(this.requestBuilder); }); diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/support/json/JsonCredentialDetailsUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/support/json/JsonCredentialDetailsUnitTests.java index a1022b7a..276b41d6 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/support/json/JsonCredentialDetailsUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/support/json/JsonCredentialDetailsUnitTests.java @@ -57,8 +57,9 @@ private void assertDetails(CredentialDetails data) { assertThat(data.getCredentialType()).isEqualTo(CredentialType.JSON); JsonCredential valueMap = data.getValue(); - assertThat(valueMap).containsEntry("client_id", "test-id").containsEntry("client_secret", "test-secret") - .containsEntry("uri", "https://example.com"); + assertThat(valueMap).containsEntry("client_id", "test-id") + .containsEntry("client_secret", "test-secret") + .containsEntry("uri", "https://example.com"); } } diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/support/json/JsonCredentialRequestUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/support/json/JsonCredentialRequestUnitTests.java index 389df4ae..ec2c9ba2 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/support/json/JsonCredentialRequestUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/support/json/JsonCredentialRequestUnitTests.java @@ -29,13 +29,15 @@ public class JsonCredentialRequestUnitTests extends CredHubRequestUnitTestsBase @BeforeEach public void setUp() { - this.requestBuilder = JsonCredentialRequest.builder().name(new SimpleCredentialName("example", "credential")) - .value(new JsonCredential() { - { - put("data", "value"); - put("test", true); - } - }).mode(WriteMode.OVERWRITE); + this.requestBuilder = JsonCredentialRequest.builder() + .name(new SimpleCredentialName("example", "credential")) + .value(new JsonCredential() { + { + put("data", "value"); + put("test", true); + } + }) + .mode(WriteMode.OVERWRITE); } @Test diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/support/password/PasswordCredentialRequestUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/support/password/PasswordCredentialRequestUnitTests.java index f7112b92..8554710b 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/support/password/PasswordCredentialRequestUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/support/password/PasswordCredentialRequestUnitTests.java @@ -30,8 +30,9 @@ public class PasswordCredentialRequestUnitTests extends CredHubRequestUnitTestsB @BeforeEach public void setUp() { this.requestBuilder = PasswordCredentialRequest.builder() - .name(new SimpleCredentialName("example", "credential")).mode(WriteMode.OVERWRITE) - .value(new PasswordCredential("secret")); + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.OVERWRITE) + .value(new PasswordCredential("secret")); } @Test @@ -47,7 +48,9 @@ public void serializeWithPasswordValue() { @Test public void serializeWithStringValue() { this.requestBuilder = PasswordCredentialRequest.builder() - .name(new SimpleCredentialName("example", "credential")).mode(WriteMode.OVERWRITE).value("secret"); + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.OVERWRITE) + .value("secret"); DocumentContext json = toJsonPath(this.requestBuilder); diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/support/password/PasswordParametersRequestUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/support/password/PasswordParametersRequestUnitTests.java index 50b5b2b0..d8c745e9 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/support/password/PasswordParametersRequestUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/support/password/PasswordParametersRequestUnitTests.java @@ -35,9 +35,15 @@ public void setUp() { @Test public void serializeWithParameters() { this.requestBuilder = PasswordParametersRequest.builder() - .name(new SimpleCredentialName("example", "credential")).mode(WriteMode.OVERWRITE) - .parameters(PasswordParameters.builder().length(20).excludeLower(true).excludeUpper(false) - .excludeNumber(true).includeSpecial(false).build()); + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.OVERWRITE) + .parameters(PasswordParameters.builder() + .length(20) + .excludeLower(true) + .excludeUpper(false) + .excludeNumber(true) + .includeSpecial(false) + .build()); DocumentContext json = toJsonPath(this.requestBuilder); @@ -52,8 +58,9 @@ public void serializeWithParameters() { @Test public void serializeWithEmptyParameters() { this.requestBuilder = PasswordParametersRequest.builder() - .name(new SimpleCredentialName("example", "credential")).mode(WriteMode.CONVERGE) - .parameters(new PasswordParameters()); + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.CONVERGE) + .parameters(new PasswordParameters()); DocumentContext json = toJsonPath(this.requestBuilder); @@ -64,7 +71,8 @@ public void serializeWithEmptyParameters() { @Test public void serializeWithNoParameters() { this.requestBuilder = PasswordParametersRequest.builder() - .name(new SimpleCredentialName("example", "credential")).mode(WriteMode.NO_OVERWRITE); + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.NO_OVERWRITE); DocumentContext json = toJsonPath(this.requestBuilder); diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/support/rsa/RsaCredentialRequestUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/support/rsa/RsaCredentialRequestUnitTests.java index 0c483b7f..7121c1fa 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/support/rsa/RsaCredentialRequestUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/support/rsa/RsaCredentialRequestUnitTests.java @@ -82,8 +82,10 @@ public void serializeWithNeitherKey() { } private void buildRequest(RsaCredential value) { - this.requestBuilder = RsaCredentialRequest.builder().name(new SimpleCredentialName("example", "credential")) - .mode(WriteMode.OVERWRITE).value(value); + this.requestBuilder = RsaCredentialRequest.builder() + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.OVERWRITE) + .value(value); } } diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/support/rsa/RsaParametersRequestUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/support/rsa/RsaParametersRequestUnitTests.java index b8f5f60b..450a9359 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/support/rsa/RsaParametersRequestUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/support/rsa/RsaParametersRequestUnitTests.java @@ -35,8 +35,10 @@ public void setUp() { @Test public void serializeWithParameters() { - this.requestBuilder = RsaParametersRequest.builder().name(new SimpleCredentialName("example", "credential")) - .mode(WriteMode.OVERWRITE).parameters(new RsaParameters(KeyLength.LENGTH_4096)); + this.requestBuilder = RsaParametersRequest.builder() + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.OVERWRITE) + .parameters(new RsaParameters(KeyLength.LENGTH_4096)); DocumentContext json = toJsonPath(this.requestBuilder); @@ -46,8 +48,9 @@ public void serializeWithParameters() { @Test public void serializeWithNoParameters() { - this.requestBuilder = RsaParametersRequest.builder().name(new SimpleCredentialName("example", "credential")) - .mode(WriteMode.OVERWRITE); + this.requestBuilder = RsaParametersRequest.builder() + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.OVERWRITE); DocumentContext json = toJsonPath(this.requestBuilder); diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/support/ssh/SshCredentialRequestUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/support/ssh/SshCredentialRequestUnitTests.java index d5eaad53..baec91d8 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/support/ssh/SshCredentialRequestUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/support/ssh/SshCredentialRequestUnitTests.java @@ -81,8 +81,10 @@ public void serializeWithNeitherKey() { } private void buildRequest(SshCredential value) { - this.requestBuilder = SshCredentialRequest.builder().name(new SimpleCredentialName("example", "credential")) - .mode(WriteMode.OVERWRITE).value(value); + this.requestBuilder = SshCredentialRequest.builder() + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.OVERWRITE) + .value(value); } } diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/support/ssh/SshParametersRequestUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/support/ssh/SshParametersRequestUnitTests.java index 59f802c6..a466a63c 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/support/ssh/SshParametersRequestUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/support/ssh/SshParametersRequestUnitTests.java @@ -35,8 +35,10 @@ public void setUp() { @Test public void serializeWithParameters() { - this.requestBuilder = SshParametersRequest.builder().name(new SimpleCredentialName("example", "credential")) - .mode(WriteMode.OVERWRITE).parameters(new SshParameters(KeyLength.LENGTH_2048, "ssh comment")); + this.requestBuilder = SshParametersRequest.builder() + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.OVERWRITE) + .parameters(new SshParameters(KeyLength.LENGTH_2048, "ssh comment")); DocumentContext json = toJsonPath(this.requestBuilder); @@ -47,8 +49,10 @@ public void serializeWithParameters() { @Test public void serializeWithLengthParameter() { - this.requestBuilder = SshParametersRequest.builder().name(new SimpleCredentialName("example", "credential")) - .mode(WriteMode.NO_OVERWRITE).parameters(new SshParameters(KeyLength.LENGTH_2048)); + this.requestBuilder = SshParametersRequest.builder() + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.NO_OVERWRITE) + .parameters(new SshParameters(KeyLength.LENGTH_2048)); DocumentContext json = toJsonPath(this.requestBuilder); @@ -59,8 +63,10 @@ public void serializeWithLengthParameter() { @Test public void serializeWithCommentParameter() { - this.requestBuilder = SshParametersRequest.builder().name(new SimpleCredentialName("example", "credential")) - .mode(WriteMode.CONVERGE).parameters(new SshParameters("ssh comment")); + this.requestBuilder = SshParametersRequest.builder() + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.CONVERGE) + .parameters(new SshParameters("ssh comment")); DocumentContext json = toJsonPath(this.requestBuilder); @@ -71,8 +77,9 @@ public void serializeWithCommentParameter() { @Test public void serializeWithNoParameters() { - this.requestBuilder = SshParametersRequest.builder().name(new SimpleCredentialName("example", "credential")) - .mode(WriteMode.OVERWRITE); + this.requestBuilder = SshParametersRequest.builder() + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.OVERWRITE); DocumentContext json = toJsonPath(this.requestBuilder); diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/support/user/UserCredentialRequestUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/support/user/UserCredentialRequestUnitTests.java index 38b773c8..0b37eedf 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/support/user/UserCredentialRequestUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/support/user/UserCredentialRequestUnitTests.java @@ -30,8 +30,10 @@ public class UserCredentialRequestUnitTests extends CredHubRequestUnitTestsBase @BeforeEach public void setUp() { - this.requestBuilder = UserCredentialRequest.builder().name(new SimpleCredentialName("example", "credential")) - .mode(WriteMode.OVERWRITE).value(new UserCredential("myname", "secret")); + this.requestBuilder = UserCredentialRequest.builder() + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.OVERWRITE) + .value(new UserCredential("myname", "secret")); } @Test @@ -49,8 +51,9 @@ public void serializeWithUsernameAndPassword() { @Test public void serializeWithPassword() { UserCredentialRequestBuilder builder = UserCredentialRequest.builder() - .name(new SimpleCredentialName("example", "credential")).mode(WriteMode.OVERWRITE) - .value(new UserCredential("secret")); + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.OVERWRITE) + .value(new UserCredential("secret")); DocumentContext json = toJsonPath(builder); diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/support/user/UserParametersRequestUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/support/user/UserParametersRequestUnitTests.java index 9f070118..d881bb1c 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/support/user/UserParametersRequestUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/support/user/UserParametersRequestUnitTests.java @@ -35,9 +35,17 @@ public void setUp() { @Test public void serializeWithParameters() { - this.requestBuilder = UserParametersRequest.builder().name(new SimpleCredentialName("example", "credential")) - .mode(WriteMode.OVERWRITE).username("user").parameters(PasswordParameters.builder().length(20) - .excludeLower(true).excludeUpper(false).excludeNumber(true).includeSpecial(false).build()); + this.requestBuilder = UserParametersRequest.builder() + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.OVERWRITE) + .username("user") + .parameters(PasswordParameters.builder() + .length(20) + .excludeLower(true) + .excludeUpper(false) + .excludeNumber(true) + .includeSpecial(false) + .build()); DocumentContext json = toJsonPath(this.requestBuilder); @@ -52,8 +60,10 @@ public void serializeWithParameters() { @Test public void serializeWithEmptyParameters() { - this.requestBuilder = UserParametersRequest.builder().name(new SimpleCredentialName("example", "credential")) - .mode(WriteMode.NO_OVERWRITE).parameters(new PasswordParameters()); + this.requestBuilder = UserParametersRequest.builder() + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.NO_OVERWRITE) + .parameters(new PasswordParameters()); DocumentContext json = toJsonPath(this.requestBuilder); @@ -63,8 +73,9 @@ public void serializeWithEmptyParameters() { @Test public void serializeWithNoParameters() { - this.requestBuilder = UserParametersRequest.builder().name(new SimpleCredentialName("example", "credential")) - .mode(WriteMode.CONVERGE); + this.requestBuilder = UserParametersRequest.builder() + .name(new SimpleCredentialName("example", "credential")) + .mode(WriteMode.CONVERGE); DocumentContext json = toJsonPath(this.requestBuilder); diff --git a/spring-credhub-core/src/test/java/org/springframework/credhub/support/value/ValueCredentialRequestUnitTests.java b/spring-credhub-core/src/test/java/org/springframework/credhub/support/value/ValueCredentialRequestUnitTests.java index 6725aca6..3a0207d9 100644 --- a/spring-credhub-core/src/test/java/org/springframework/credhub/support/value/ValueCredentialRequestUnitTests.java +++ b/spring-credhub-core/src/test/java/org/springframework/credhub/support/value/ValueCredentialRequestUnitTests.java @@ -28,8 +28,9 @@ public class ValueCredentialRequestUnitTests extends CredHubRequestUnitTestsBase @BeforeEach public void setUp() { - this.requestBuilder = ValueCredentialRequest.builder().name(new SimpleCredentialName("example", "credential")) - .value(new ValueCredential("somevalue")); + this.requestBuilder = ValueCredentialRequest.builder() + .name(new SimpleCredentialName("example", "credential")) + .value(new ValueCredential("somevalue")); } @Test @@ -45,8 +46,9 @@ public void serializeWithValue() { @Test public void serializeWithStringValue() { - this.requestBuilder = ValueCredentialRequest.builder().name(new SimpleCredentialName("example", "credential")) - .value("somevalue"); + this.requestBuilder = ValueCredentialRequest.builder() + .name(new SimpleCredentialName("example", "credential")) + .value("somevalue"); DocumentContext json = toJsonPath(this.requestBuilder); diff --git a/spring-credhub-docs/src/test/java/com/example/credhub/CredHubService.java b/spring-credhub-docs/src/test/java/com/example/credhub/CredHubService.java index 7aebf267..8e54a6cf 100644 --- a/spring-credhub-docs/src/test/java/com/example/credhub/CredHubService.java +++ b/spring-credhub-docs/src/test/java/com/example/credhub/CredHubService.java @@ -38,18 +38,23 @@ public CredHubService(CredHubOperations credHubOperations) { } public String generatePassword() { - PasswordParameters parameters = PasswordParameters.builder().length(12).excludeLower(false).excludeUpper(false) - .excludeNumber(false).includeSpecial(true).build(); + PasswordParameters parameters = PasswordParameters.builder() + .length(12) + .excludeLower(false) + .excludeUpper(false) + .excludeNumber(false) + .includeSpecial(true) + .build(); CredentialDetails password = this.credHubOperations.credentials() - .generate(PasswordParametersRequest.builder().name(this.credentialName).parameters(parameters).build()); + .generate(PasswordParametersRequest.builder().name(this.credentialName).parameters(parameters).build()); return password.getValue().getPassword(); } public String getPassword() { CredentialDetails password = this.credHubOperations.credentials() - .getByName(this.credentialName, PasswordCredential.class); + .getByName(this.credentialName, PasswordCredential.class); return password.getValue().getPassword(); } diff --git a/spring-credhub-docs/src/test/java/com/example/credhub/ReactiveCredHubService.java b/spring-credhub-docs/src/test/java/com/example/credhub/ReactiveCredHubService.java index 6280a57f..00db9d4b 100644 --- a/spring-credhub-docs/src/test/java/com/example/credhub/ReactiveCredHubService.java +++ b/spring-credhub-docs/src/test/java/com/example/credhub/ReactiveCredHubService.java @@ -39,18 +39,24 @@ public ReactiveCredHubService(ReactiveCredHubOperations credHubOperations) { } public Mono generatePassword() { - PasswordParameters parameters = PasswordParameters.builder().length(12).excludeLower(false).excludeUpper(false) - .excludeNumber(false).includeSpecial(true).build(); + PasswordParameters parameters = PasswordParameters.builder() + .length(12) + .excludeLower(false) + .excludeUpper(false) + .excludeNumber(false) + .includeSpecial(true) + .build(); return this.credHubOperations.credentials() - .generate(PasswordParametersRequest.builder().name(this.credentialName).parameters(parameters).build(), - PasswordCredential.class) - .map((password) -> password.getValue().getPassword()); + .generate(PasswordParametersRequest.builder().name(this.credentialName).parameters(parameters).build(), + PasswordCredential.class) + .map((password) -> password.getValue().getPassword()); } public Mono getPassword() { - return this.credHubOperations.credentials().getByName(this.credentialName, PasswordCredential.class) - .map((password) -> password.getValue().getPassword()); + return this.credHubOperations.credentials() + .getByName(this.credentialName, PasswordCredential.class) + .map((password) -> password.getValue().getPassword()); } } diff --git a/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/CertificateIntegrationTests.java b/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/CertificateIntegrationTests.java index 8974b142..3b334514 100644 --- a/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/CertificateIntegrationTests.java +++ b/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/CertificateIntegrationTests.java @@ -65,9 +65,11 @@ public void tearDown() { @Test public void generateCertificate() { - CredentialDetails certificate = this.credentials.generate(CertificateParametersRequest - .builder().name(TEST_CERT_NAME) - .parameters(CertificateParameters.builder().commonName("example.com").selfSign(true).build()).build()); + CredentialDetails certificate = this.credentials + .generate(CertificateParametersRequest.builder() + .name(TEST_CERT_NAME) + .parameters(CertificateParameters.builder().commonName("example.com").selfSign(true).build()) + .build()); assertThat(certificate.getName().getName()).isEqualTo(TEST_CERT_NAME.getName()); assertThat(certificate.getCredentialType()).isEqualTo(CredentialType.CERTIFICATE); assertThat(certificate.getId()).isNotNull(); @@ -86,9 +88,11 @@ public void generateCertificate() { @Test public void regenerateCertificate() { - CredentialDetails certificate = this.credentials.generate(CertificateParametersRequest - .builder().name(TEST_CERT_NAME) - .parameters(CertificateParameters.builder().commonName("example.com").selfSign(true).build()).build()); + CredentialDetails certificate = this.credentials + .generate(CertificateParametersRequest.builder() + .name(TEST_CERT_NAME) + .parameters(CertificateParameters.builder().commonName("example.com").selfSign(true).build()) + .build()); assertThat(certificate.getName().getName()).isEqualTo(TEST_CERT_NAME.getName()); CertificateSummary byName = this.certificates.getByName(TEST_CERT_NAME); @@ -98,21 +102,23 @@ public void regenerateCertificate() { assertThat(regenerated.isTransitional()).isTrue(); assertThat(regenerated.getValue().getCertificate()).isNotEqualTo(certificate.getValue().getCertificate()); assertThat(regenerated.getValue().getCertificateAuthority()) - .isNotEqualTo(certificate.getValue().getCertificateAuthority()); + .isNotEqualTo(certificate.getValue().getCertificateAuthority()); assertThat(regenerated.getValue().getPrivateKey()).isNotEqualTo(certificate.getValue().getPrivateKey()); } @Test public void rotateCertificate() { - CredentialDetails certificate = this.credentials.generate(CertificateParametersRequest - .builder().name(TEST_CERT_NAME) - .parameters(CertificateParameters.builder().commonName("example.com").selfSign(true).build()).build()); + CredentialDetails certificate = this.credentials + .generate(CertificateParametersRequest.builder() + .name(TEST_CERT_NAME) + .parameters(CertificateParameters.builder().commonName("example.com").selfSign(true).build()) + .build()); assertThat(certificate.getName().getName()).isEqualTo(TEST_CERT_NAME.getName()); String credentialVersion0Id = certificate.getId(); List> allVersions = this.credentials - .getByNameWithHistory(TEST_CERT_NAME, CertificateCredential.class); + .getByNameWithHistory(TEST_CERT_NAME, CertificateCredential.class); assertThat(allVersions).hasSize(1); assertThat(allVersions.get(0).getId()).isEqualTo(credentialVersion0Id); @@ -123,7 +129,7 @@ public void rotateCertificate() { assertThat(regenerated.getName().getName()).isEqualTo(TEST_CERT_NAME.getName()); assertThat(regenerated.getValue().getCertificate()).isNotEqualTo(certificate.getValue().getCertificate()); assertThat(regenerated.getValue().getCertificateAuthority()) - .isNotEqualTo(certificate.getValue().getCertificateAuthority()); + .isNotEqualTo(certificate.getValue().getCertificateAuthority()); assertThat(regenerated.getValue().getPrivateKey()).isNotEqualTo(certificate.getValue().getPrivateKey()); String credentialVersion1Id = regenerated.getId(); @@ -133,7 +139,7 @@ public void rotateCertificate() { assertThat(allVersions).extracting("id").contains(credentialVersion1Id, credentialVersion0Id); List updatedCertificate = this.certificates - .updateTransitionalVersion(certificateId, credentialVersion0Id); + .updateTransitionalVersion(certificateId, credentialVersion0Id); assertThat(updatedCertificate).hasSize(2); assertThat(updatedCertificate).extracting("id").contains(credentialVersion1Id, credentialVersion0Id); assertThat(updatedCertificate).extracting("transitional").contains(false, true); @@ -147,22 +153,28 @@ public void rotateCertificate() { @Test public void bulkRegenerateCertificates() { CredentialDetails rootCertificate = this.credentials - .generate( - CertificateParametersRequest - .builder().name(ROOT_CERT_NAME).parameters(CertificateParameters.builder() - .commonName("example.com").certificateAuthority(true).selfSign(true).build()) - .build()); + .generate(CertificateParametersRequest.builder() + .name(ROOT_CERT_NAME) + .parameters(CertificateParameters.builder() + .commonName("example.com") + .certificateAuthority(true) + .selfSign(true) + .build()) + .build()); CredentialDetails signedCertificate = this.credentials - .generate(CertificateParametersRequest - .builder().name(TEST_CERT_NAME).parameters(CertificateParameters.builder() - .commonName("example.com").certificateAuthorityCredential(ROOT_CERT_NAME).build()) - .build()); + .generate(CertificateParametersRequest.builder() + .name(TEST_CERT_NAME) + .parameters(CertificateParameters.builder() + .commonName("example.com") + .certificateAuthorityCredential(ROOT_CERT_NAME) + .build()) + .build()); assertThat(signedCertificate.getValue().getCertificateAuthority()) - .isEqualTo(rootCertificate.getValue().getCertificate()); + .isEqualTo(rootCertificate.getValue().getCertificate()); List> allVersions = this.credentials - .getByNameWithHistory(TEST_CERT_NAME, CertificateCredential.class); + .getByNameWithHistory(TEST_CERT_NAME, CertificateCredential.class); assertThat(allVersions).hasSize(1); assertThat(allVersions.get(0).getId()).isEqualTo(signedCertificate.getId()); diff --git a/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/CredentialIntegrationTests.java b/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/CredentialIntegrationTests.java index 130bfe75..f7c348cc 100644 --- a/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/CredentialIntegrationTests.java +++ b/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/CredentialIntegrationTests.java @@ -51,8 +51,12 @@ public class CredentialIntegrationTests extends CredHubIntegrationTests { public void setUp() { this.credentials = this.operations.credentials(); - this.passwordParameters = PasswordParameters.builder().length(12).excludeLower(false).excludeUpper(false) - .excludeNumber(false).includeSpecial(true); + this.passwordParameters = PasswordParameters.builder() + .length(12) + .excludeLower(false) + .excludeUpper(false) + .excludeNumber(false) + .includeSpecial(true); deleteCredentialIfExists(CREDENTIAL_NAME); } @@ -68,7 +72,7 @@ public void tearDown() { @Test public void writeCredential() { CredentialDetails written = this.credentials - .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build()); + .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build()); assertThat(written.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); assertThat(written.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); assertThat(written.getCredentialType()).isEqualTo(CredentialType.VALUE); @@ -96,14 +100,14 @@ public void writeCredential() { @Test public void overwriteCredential() { CredentialDetails written = this.credentials - .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build()); + .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build()); assertThat(written.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); assertThat(written.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); assertThat(written.getCredentialType()).isEqualTo(CredentialType.VALUE); assertThat(written.getId()).isNotNull(); CredentialDetails overwritten = this.credentials - .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value("new-value").build()); + .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value("new-value").build()); assertThat(overwritten.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); assertThat(overwritten.getValue().getValue()).isEqualTo("new-value"); @@ -130,7 +134,10 @@ private void verifyHistory() { @Test public void generateCredential() { CredentialDetails generated = this.credentials.generate(UserParametersRequest.builder() - .name(CREDENTIAL_NAME).username("test-user").parameters(this.passwordParameters.build()).build()); + .name(CREDENTIAL_NAME) + .username("test-user") + .parameters(this.passwordParameters.build()) + .build()); assertThat(generated.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); assertThat(generated.getCredentialType()).isEqualTo(CredentialType.USER); assertThat(generated.getValue().getUsername()).isEqualTo("test-user"); @@ -152,15 +159,21 @@ public void generateCredential() { @Test public void generateNoOverwriteCredential() { CredentialDetails generated = this.credentials.generate(UserParametersRequest.builder() - .name(CREDENTIAL_NAME).username("test-user").parameters(this.passwordParameters.build()).build()); + .name(CREDENTIAL_NAME) + .username("test-user") + .parameters(this.passwordParameters.build()) + .build()); assertThat(generated.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); assertThat(generated.getValue().getUsername()).isEqualTo("test-user"); assertThat(generated.getValue().getPassword()).matches("^[a-zA-Z0-9\\p{Punct}]{12}$"); assertThat(generated.getValue().getPasswordHash()).isNotNull(); - CredentialDetails noOverwrite = this.credentials - .generate(UserParametersRequest.builder().name(CREDENTIAL_NAME).mode(WriteMode.NO_OVERWRITE) - .username("test-user").parameters(this.passwordParameters.build()).build()); + CredentialDetails noOverwrite = this.credentials.generate(UserParametersRequest.builder() + .name(CREDENTIAL_NAME) + .mode(WriteMode.NO_OVERWRITE) + .username("test-user") + .parameters(this.passwordParameters.build()) + .build()); assertThat(noOverwrite.getValue().getUsername()).isEqualTo("test-user"); assertThat(noOverwrite.getValue().getPassword()).isEqualTo(generated.getValue().getPassword()); assertThat(noOverwrite.getValue().getPasswordHash()).isEqualTo(generated.getValue().getPasswordHash()); @@ -169,15 +182,21 @@ public void generateNoOverwriteCredential() { @Test public void generateOverwriteCredential() { CredentialDetails generated = this.credentials.generate(UserParametersRequest.builder() - .name(CREDENTIAL_NAME).username("test-user").parameters(this.passwordParameters.build()).build()); + .name(CREDENTIAL_NAME) + .username("test-user") + .parameters(this.passwordParameters.build()) + .build()); assertThat(generated.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); assertThat(generated.getValue().getUsername()).isEqualTo("test-user"); assertThat(generated.getValue().getPassword()).matches("^[a-zA-Z0-9\\p{Punct}]{12}$"); assertThat(generated.getValue().getPasswordHash()).isNotNull(); - CredentialDetails overwrite = this.credentials - .generate(UserParametersRequest.builder().name(CREDENTIAL_NAME).mode(WriteMode.OVERWRITE) - .username("test-user").parameters(this.passwordParameters.build()).build()); + CredentialDetails overwrite = this.credentials.generate(UserParametersRequest.builder() + .name(CREDENTIAL_NAME) + .mode(WriteMode.OVERWRITE) + .username("test-user") + .parameters(this.passwordParameters.build()) + .build()); assertThat(overwrite.getValue().getUsername()).isEqualTo("test-user"); assertThat(overwrite.getValue().getPassword()).isNotEqualTo(generated.getValue().getPassword()); assertThat(overwrite.getValue().getPasswordHash()).isNotEqualTo(generated.getValue().getPasswordHash()); @@ -186,29 +205,40 @@ public void generateOverwriteCredential() { @Test public void generateConvergeCredential() { CredentialDetails generated = this.credentials.generate(UserParametersRequest.builder() - .name(CREDENTIAL_NAME).username("test-user").parameters(this.passwordParameters.build()).build()); + .name(CREDENTIAL_NAME) + .username("test-user") + .parameters(this.passwordParameters.build()) + .build()); assertThat(generated.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); assertThat(generated.getValue().getUsername()).isEqualTo("test-user"); assertThat(generated.getValue().getPassword()).matches("^[a-zA-Z0-9\\p{Punct}]{12}$"); assertThat(generated.getValue().getPasswordHash()).isNotNull(); CredentialDetails convergeWithoutChanges = this.credentials - .generate(UserParametersRequest.builder().name(CREDENTIAL_NAME).mode(WriteMode.CONVERGE) - .username("test-user").parameters(this.passwordParameters.build()).build()); + .generate(UserParametersRequest.builder() + .name(CREDENTIAL_NAME) + .mode(WriteMode.CONVERGE) + .username("test-user") + .parameters(this.passwordParameters.build()) + .build()); assertThat(convergeWithoutChanges.getValue().getUsername()).isEqualTo("test-user"); assertThat(convergeWithoutChanges.getValue().getPassword()).isEqualTo(generated.getValue().getPassword()); assertThat(convergeWithoutChanges.getValue().getPasswordHash()) - .isEqualTo(generated.getValue().getPasswordHash()); + .isEqualTo(generated.getValue().getPasswordHash()); this.passwordParameters.includeSpecial(false); CredentialDetails convergeWithChanges = this.credentials - .generate(UserParametersRequest.builder().name(CREDENTIAL_NAME).mode(WriteMode.CONVERGE) - .username("test-user").parameters(this.passwordParameters.build()).build()); + .generate(UserParametersRequest.builder() + .name(CREDENTIAL_NAME) + .mode(WriteMode.CONVERGE) + .username("test-user") + .parameters(this.passwordParameters.build()) + .build()); assertThat(convergeWithChanges.getValue().getUsername()).isEqualTo("test-user"); assertThat(convergeWithChanges.getValue().getPassword()).isNotEqualTo(generated.getValue().getPassword()); assertThat(convergeWithChanges.getValue().getPasswordHash()) - .isNotEqualTo(generated.getValue().getPasswordHash()); + .isNotEqualTo(generated.getValue().getPasswordHash()); } } diff --git a/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/InterpolationIntegrationTests.java b/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/InterpolationIntegrationTests.java index 37094940..4d174649 100644 --- a/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/InterpolationIntegrationTests.java +++ b/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/InterpolationIntegrationTests.java @@ -69,22 +69,24 @@ public void interpolate() throws IOException { }; CredentialDetails written = this.credentials - .write(JsonCredentialRequest.builder().name(CREDENTIAL_NAME).value(json).build()); + .write(JsonCredentialRequest.builder().name(CREDENTIAL_NAME).value(json).build()); assertThat(written.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); assertThat(written.getValue()).isEqualTo(json); assertThat(written.getCredentialType()).isEqualTo(CredentialType.JSON); assertThat(written.getId()).isNotNull(); ServicesData servicesData = this.interpolation - .interpolateServiceData(buildVcapServices(CREDENTIAL_NAME.getName())); + .interpolateServiceData(buildVcapServices(CREDENTIAL_NAME.getName())); assertThat(servicesData).containsKey("service-offering"); assertThat(servicesData.get("service-offering")).hasSize(1); assertThat(servicesData.get("service-offering").get(0)).containsKey("credentials"); - Map credentials = (Map) servicesData.get("service-offering").get(0) - .get("credentials"); - assertThat(credentials).containsEntry("url", "https://example.com").containsEntry("username", "user") - .containsEntry("password", "secret"); + Map credentials = (Map) servicesData.get("service-offering") + .get(0) + .get("credentials"); + assertThat(credentials).containsEntry("url", "https://example.com") + .containsEntry("username", "user") + .containsEntry("password", "secret"); } private ServicesData buildVcapServices(String credHubReferenceName) throws IOException { diff --git a/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/PermissionIntegrationTests.java b/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/PermissionIntegrationTests.java index 690acde0..670c90db 100644 --- a/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/PermissionIntegrationTests.java +++ b/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/PermissionIntegrationTests.java @@ -61,10 +61,14 @@ public void managePermissions() { this.credentials.write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build()); Permission appPermission = Permission.builder().app("app1").operation(Operation.READ).build(); - Permission userPermission = Permission.builder().user("user1") - .operations(Operation.READ, Operation.WRITE, Operation.DELETE).build(); - Permission clientPermission = Permission.builder().client("client1") - .operations(Operation.READ_ACL, Operation.WRITE_ACL).build(); + Permission userPermission = Permission.builder() + .user("user1") + .operations(Operation.READ, Operation.WRITE, Operation.DELETE) + .build(); + Permission clientPermission = Permission.builder() + .client("client1") + .operations(Operation.READ_ACL, Operation.WRITE_ACL) + .build(); this.permissions.addPermissions(CREDENTIAL_NAME, appPermission, userPermission, clientPermission); diff --git a/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/PermissionV2IntegrationTests.java b/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/PermissionV2IntegrationTests.java index 7d8eb962..fde522ea 100644 --- a/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/PermissionV2IntegrationTests.java +++ b/spring-credhub-integration-tests/src/test/java/org/springframework/credhub/integration/PermissionV2IntegrationTests.java @@ -62,8 +62,10 @@ public void tearDown() { public void managePermissions() { this.credentials.write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build()); - Permission clientPermission = Permission.builder().client("client1") - .operations(Operation.READ, Operation.WRITE, Operation.DELETE).build(); + Permission clientPermission = Permission.builder() + .client("client1") + .operations(Operation.READ, Operation.WRITE, Operation.DELETE) + .build(); CredentialPermission added = this.permissions.addPermissions(CREDENTIAL_NAME, clientPermission); assertThat(added.getId()).isNotNull(); @@ -85,8 +87,10 @@ public void managePermissions() { public void updatePermissions() { this.credentials.write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build()); - Permission clientPermission = Permission.builder().client("client1") - .operations(Operation.READ, Operation.WRITE, Operation.DELETE).build(); + Permission clientPermission = Permission.builder() + .client("client1") + .operations(Operation.READ, Operation.WRITE, Operation.DELETE) + .build(); CredentialPermission added = this.permissions.addPermissions(CREDENTIAL_NAME, clientPermission); assertThat(added.getId()).isNotNull(); @@ -95,8 +99,10 @@ public void updatePermissions() { String permissionId = added.getId(); - Permission newPermission = Permission.builder().client("client1") - .operations(Operation.READ_ACL, Operation.WRITE_ACL).build(); + Permission newPermission = Permission.builder() + .client("client1") + .operations(Operation.READ_ACL, Operation.WRITE_ACL) + .build(); CredentialPermission updated = this.permissions.updatePermissions(permissionId, CREDENTIAL_NAME, newPermission); assertThat(updated.getId()).isEqualTo(permissionId); diff --git a/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactiveCertificateIntegrationTests.java b/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactiveCertificateIntegrationTests.java index a4d5cae3..30d4f99c 100644 --- a/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactiveCertificateIntegrationTests.java +++ b/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactiveCertificateIntegrationTests.java @@ -65,16 +65,17 @@ public void tearDown() { public void generateCertificate() { assumeTrue(serverApiIsV2()); - StepVerifier.create(this.credentials.generate(CertificateParametersRequest.builder().name(TEST_CERT_NAME) - .parameters(CertificateParameters.builder().commonName("example.com").selfSign(true).build()).build(), - CertificateCredential.class)).assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(TEST_CERT_NAME.getName()); - assertThat(response.getCredentialType()).isEqualTo(CredentialType.CERTIFICATE); - assertThat(response.getId()).isNotNull(); - assertThat(response.getValue().getCertificate()).isNotNull(); - assertThat(response.getValue().getCertificateAuthority()).isNotNull(); - assertThat(response.getValue().getPrivateKey()).isNotNull(); - }).verifyComplete(); + StepVerifier.create(this.credentials.generate(CertificateParametersRequest.builder() + .name(TEST_CERT_NAME) + .parameters(CertificateParameters.builder().commonName("example.com").selfSign(true).build()) + .build(), CertificateCredential.class)).assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(TEST_CERT_NAME.getName()); + assertThat(response.getCredentialType()).isEqualTo(CredentialType.CERTIFICATE); + assertThat(response.getId()).isNotNull(); + assertThat(response.getValue().getCertificate()).isNotNull(); + assertThat(response.getValue().getCertificateAuthority()).isNotNull(); + assertThat(response.getValue().getPrivateKey()).isNotNull(); + }).verifyComplete(); StepVerifier.create(this.certificates.getByName(TEST_CERT_NAME)).assertNext((response) -> { assertThat(response.getName()).isEqualTo(TEST_CERT_NAME.getName()); @@ -82,8 +83,9 @@ public void generateCertificate() { }).verifyComplete(); StepVerifier.create(this.certificates.getAll()) - .assertNext((response) -> assertThat(response.getName()).isEqualTo(TEST_CERT_NAME.getName())) - .thenCancel().verify(); + .assertNext((response) -> assertThat(response.getName()).isEqualTo(TEST_CERT_NAME.getName())) + .thenCancel() + .verify(); } @Test @@ -93,13 +95,14 @@ public void regenerateCertificate() { AtomicReference certificate = new AtomicReference<>(); AtomicReference certificateId = new AtomicReference<>(); - StepVerifier.create(this.credentials.generate(CertificateParametersRequest.builder().name(TEST_CERT_NAME) - .parameters(CertificateParameters.builder().commonName("example.com").selfSign(true).build()).build(), - CertificateCredential.class)).assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(TEST_CERT_NAME.getName()); + StepVerifier.create(this.credentials.generate(CertificateParametersRequest.builder() + .name(TEST_CERT_NAME) + .parameters(CertificateParameters.builder().commonName("example.com").selfSign(true).build()) + .build(), CertificateCredential.class)).assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(TEST_CERT_NAME.getName()); - certificate.set(response.getValue()); - }).verifyComplete(); + certificate.set(response.getValue()); + }).verifyComplete(); StepVerifier.create(this.certificates.getByName(TEST_CERT_NAME)).assertNext((response) -> { assertThat(response.getName()).isEqualTo(TEST_CERT_NAME.getName()); @@ -113,7 +116,7 @@ public void regenerateCertificate() { assertThat(response.isTransitional()).isTrue(); assertThat(response.getValue().getCertificate()).isNotEqualTo(certificate.get().getCertificate()); assertThat(response.getValue().getCertificateAuthority()) - .isNotEqualTo(certificate.get().getCertificateAuthority()); + .isNotEqualTo(certificate.get().getCertificateAuthority()); assertThat(response.getValue().getPrivateKey()).isNotEqualTo(certificate.get().getPrivateKey()); }).verifyComplete(); } @@ -127,18 +130,19 @@ public void rotateCertificate() { AtomicReference credentialVersion1Id = new AtomicReference<>(); AtomicReference certificateId = new AtomicReference<>(); - StepVerifier.create(this.credentials.generate(CertificateParametersRequest.builder().name(TEST_CERT_NAME) - .parameters(CertificateParameters.builder().commonName("example.com").selfSign(true).build()).build(), - CertificateCredential.class)).assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(TEST_CERT_NAME.getName()); + StepVerifier.create(this.credentials.generate(CertificateParametersRequest.builder() + .name(TEST_CERT_NAME) + .parameters(CertificateParameters.builder().commonName("example.com").selfSign(true).build()) + .build(), CertificateCredential.class)).assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(TEST_CERT_NAME.getName()); - certificate.set(response.getValue()); - credentialVersion0Id.set(response.getId()); - }).verifyComplete(); + certificate.set(response.getValue()); + credentialVersion0Id.set(response.getId()); + }).verifyComplete(); StepVerifier.create(this.credentials.getByNameWithHistory(TEST_CERT_NAME, CertificateCredential.class)) - .assertNext((response) -> assertThat(response.getId()).isEqualTo(credentialVersion0Id.get())) - .verifyComplete(); + .assertNext((response) -> assertThat(response.getId()).isEqualTo(credentialVersion0Id.get())) + .verifyComplete(); StepVerifier.create(this.certificates.getByName(TEST_CERT_NAME)).assertNext((response) -> { assertThat(response.getName()).isEqualTo(TEST_CERT_NAME.getName()); @@ -151,32 +155,35 @@ public void rotateCertificate() { assertThat(response.getName().getName()).isEqualTo(TEST_CERT_NAME.getName()); assertThat(response.getValue().getCertificate()).isNotEqualTo(certificate.get().getCertificate()); assertThat(response.getValue().getCertificateAuthority()) - .isNotEqualTo(certificate.get().getCertificateAuthority()); + .isNotEqualTo(certificate.get().getCertificateAuthority()); assertThat(response.getValue().getPrivateKey()).isNotEqualTo(certificate.get().getPrivateKey()); credentialVersion1Id.set(response.getId()); }).verifyComplete(); StepVerifier.create(this.credentials.getByNameWithHistory(TEST_CERT_NAME, CertificateCredential.class)) - .assertNext((response) -> assertThat(response.getId()).isEqualTo(credentialVersion1Id.get())) - .assertNext((response) -> assertThat(response.getId()).isEqualTo(credentialVersion0Id.get())) - .verifyComplete(); + .assertNext((response) -> assertThat(response.getId()).isEqualTo(credentialVersion1Id.get())) + .assertNext((response) -> assertThat(response.getId()).isEqualTo(credentialVersion0Id.get())) + .verifyComplete(); StepVerifier - .create(this.certificates.updateTransitionalVersion(certificateId.get(), credentialVersion0Id.get())) - .assertNext((response) -> { - assertThat(response.getId()).isEqualTo(credentialVersion1Id.get()); - assertThat(response.isTransitional()).isFalse(); - }).assertNext((response) -> { - assertThat(response.getId()).isEqualTo(credentialVersion0Id.get()); - assertThat(response.isTransitional()).isTrue(); - }).verifyComplete(); + .create(this.certificates.updateTransitionalVersion(certificateId.get(), credentialVersion0Id.get())) + .assertNext((response) -> { + assertThat(response.getId()).isEqualTo(credentialVersion1Id.get()); + assertThat(response.isTransitional()).isFalse(); + }) + .assertNext((response) -> { + assertThat(response.getId()).isEqualTo(credentialVersion0Id.get()); + assertThat(response.isTransitional()).isTrue(); + }) + .verifyComplete(); StepVerifier.create(this.certificates.updateTransitionalVersion(certificateId.get(), null)) - .assertNext((response) -> { - assertThat(response.getId()).isEqualTo(credentialVersion1Id.get()); - assertThat(response.isTransitional()).isFalse(); - }).verifyComplete(); + .assertNext((response) -> { + assertThat(response.getId()).isEqualTo(credentialVersion1Id.get()); + assertThat(response.isTransitional()).isFalse(); + }) + .verifyComplete(); } @Test @@ -184,37 +191,39 @@ public void bulkRegenerateCertificates() { AtomicReference rootCertificate = new AtomicReference<>(); AtomicReference signedCertificateId = new AtomicReference<>(); - StepVerifier - .create(this.credentials.generate( - CertificateParametersRequest.builder().name(ROOT_CERT_NAME) - .parameters(CertificateParameters.builder().commonName("example.com") - .certificateAuthority(true).selfSign(true).build()) - .build(), - CertificateCredential.class)) - .assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(ROOT_CERT_NAME.getName()); - - rootCertificate.set(response.getValue()); - }).verifyComplete(); - - StepVerifier.create(this.credentials.generate( - CertificateParametersRequest.builder().name(TEST_CERT_NAME) - .parameters(CertificateParameters.builder().commonName("example.com") - .certificateAuthorityCredential(ROOT_CERT_NAME).build()) - .build(), - CertificateCredential.class)).assertNext((response) -> { - assertThat(response.getValue().getCertificateAuthority()) - .isEqualTo(rootCertificate.get().getCertificate()); - - signedCertificateId.set(response.getId()); - }).verifyComplete(); + StepVerifier.create(this.credentials.generate(CertificateParametersRequest.builder() + .name(ROOT_CERT_NAME) + .parameters(CertificateParameters.builder() + .commonName("example.com") + .certificateAuthority(true) + .selfSign(true) + .build()) + .build(), CertificateCredential.class)).assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(ROOT_CERT_NAME.getName()); + + rootCertificate.set(response.getValue()); + }).verifyComplete(); + + StepVerifier.create(this.credentials.generate(CertificateParametersRequest.builder() + .name(TEST_CERT_NAME) + .parameters(CertificateParameters.builder() + .commonName("example.com") + .certificateAuthorityCredential(ROOT_CERT_NAME) + .build()) + .build(), CertificateCredential.class)).assertNext((response) -> { + assertThat(response.getValue().getCertificateAuthority()) + .isEqualTo(rootCertificate.get().getCertificate()); + + signedCertificateId.set(response.getId()); + }).verifyComplete(); StepVerifier.create(this.credentials.getByNameWithHistory(TEST_CERT_NAME, CertificateCredential.class)) - .assertNext((response) -> assertThat(response.getId()).isEqualTo(signedCertificateId.get())) - .verifyComplete(); + .assertNext((response) -> assertThat(response.getId()).isEqualTo(signedCertificateId.get())) + .verifyComplete(); StepVerifier.create(this.certificates.regenerate(ROOT_CERT_NAME)) - .assertNext((response) -> assertThat(response).isEqualTo(TEST_CERT_NAME)).verifyComplete(); + .assertNext((response) -> assertThat(response).isEqualTo(TEST_CERT_NAME)) + .verifyComplete(); } } diff --git a/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactiveCredentialIntegrationTests.java b/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactiveCredentialIntegrationTests.java index 462a6b7d..f04cdc19 100644 --- a/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactiveCredentialIntegrationTests.java +++ b/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactiveCredentialIntegrationTests.java @@ -52,8 +52,12 @@ public class ReactiveCredentialIntegrationTests extends ReactiveCredHubIntegrati public void setUp() { this.credentials = this.operations.credentials(); - this.passwordParameters = PasswordParameters.builder().length(12).excludeLower(false).excludeUpper(false) - .excludeNumber(false).includeSpecial(true); + this.passwordParameters = PasswordParameters.builder() + .length(12) + .excludeLower(false) + .excludeUpper(false) + .excludeNumber(false) + .includeSpecial(true); deleteCredentialIfExists(CREDENTIAL_NAME); } @@ -70,40 +74,47 @@ public void writeCredential() { AtomicReference> written = new AtomicReference<>(); StepVerifier - .create(this.credentials - .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build())) - .assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); - assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); - assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE); - assertThat(response.getId()).isNotNull(); - - written.set(response); - }).verifyComplete(); + .create(this.credentials + .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build())) + .assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); + assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); + assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE); + assertThat(response.getId()).isNotNull(); + + written.set(response); + }) + .verifyComplete(); StepVerifier.create(this.credentials.getById(written.get().getId(), ValueCredential.class)) - .assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); - assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); - assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE); - }).verifyComplete(); + .assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); + assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); + assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE); + }) + .verifyComplete(); StepVerifier.create(this.credentials.getByName(CREDENTIAL_NAME, ValueCredential.class)) - .assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); - assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); - assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE); - }).verifyComplete(); + .assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); + assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); + assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE); + }) + .verifyComplete(); StepVerifier.create(this.credentials.findByName(new SimpleCredentialName("/test"))) - .assertNext((response) -> assertThat(response).extracting("name").extracting("name").asString() - .contains(CREDENTIAL_NAME.getName())) - .verifyComplete(); + .assertNext((response) -> assertThat(response).extracting("name") + .extracting("name") + .asString() + .contains(CREDENTIAL_NAME.getName())) + .verifyComplete(); StepVerifier.create(this.credentials.findByPath("/spring-credhub/integration-test")) - .assertNext((response) -> assertThat(response).extracting("name").extracting("name").asString() - .contains(CREDENTIAL_NAME.getName())) - .verifyComplete(); + .assertNext((response) -> assertThat(response).extracting("name") + .extracting("name") + .asString() + .contains(CREDENTIAL_NAME.getName())) + .verifyComplete(); } @Test @@ -111,22 +122,24 @@ public void overwriteCredentialV2() { assumeTrue(serverApiIsV2()); StepVerifier - .create(this.credentials - .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build())) - .assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); - assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); - assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE); - assertThat(response.getId()).isNotNull(); - }).verifyComplete(); + .create(this.credentials + .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build())) + .assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); + assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); + assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE); + assertThat(response.getId()).isNotNull(); + }) + .verifyComplete(); StepVerifier - .create(this.credentials - .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value("new-value").build())) - .assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); - assertThat(response.getValue().getValue()).isEqualTo("new-value"); - }).verifyComplete(); + .create(this.credentials + .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value("new-value").build())) + .assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); + assertThat(response.getValue().getValue()).isEqualTo("new-value"); + }) + .verifyComplete(); verifyHistory(); } @@ -136,184 +149,201 @@ public void overwriteCredentialV1() { assumeTrue(serverApiIsV1()); StepVerifier - .create(this.credentials - .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build())) - .assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); - assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); - assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE); - assertThat(response.getId()).isNotNull(); - }).verifyComplete(); - - StepVerifier.create(this.credentials.write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME) - .value("new-value").mode(WriteMode.NO_OVERWRITE).build())).assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); - assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); - }).verifyComplete(); - - StepVerifier.create(this.credentials.write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME) - .value("new-value").mode(WriteMode.OVERWRITE).build())).assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); - assertThat(response.getValue().getValue()).isEqualTo("new-value"); - }).verifyComplete(); + .create(this.credentials + .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build())) + .assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); + assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); + assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE); + assertThat(response.getId()).isNotNull(); + }) + .verifyComplete(); + + StepVerifier.create(this.credentials.write(ValueCredentialRequest.builder() + .name(CREDENTIAL_NAME) + .value("new-value") + .mode(WriteMode.NO_OVERWRITE) + .build())).assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); + assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); + }).verifyComplete(); + + StepVerifier.create(this.credentials.write(ValueCredentialRequest.builder() + .name(CREDENTIAL_NAME) + .value("new-value") + .mode(WriteMode.OVERWRITE) + .build())).assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); + assertThat(response.getValue().getValue()).isEqualTo("new-value"); + }).verifyComplete(); verifyHistory(); } private void verifyHistory() { StepVerifier.create(this.credentials.getByNameWithHistory(CREDENTIAL_NAME, ValueCredential.class)) - .assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); - assertThat(response.getValue().getValue()).isEqualTo("new-value"); - assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE); - }).assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); - assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); - assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE); - }).verifyComplete(); + .assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); + assertThat(response.getValue().getValue()).isEqualTo("new-value"); + assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE); + }) + .assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); + assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); + assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE); + }) + .verifyComplete(); StepVerifier.create(this.credentials.getByNameWithHistory(CREDENTIAL_NAME, 2, ValueCredential.class)) - .assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); - assertThat(response.getValue().getValue()).isEqualTo("new-value"); - assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE); - }).assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); - assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); - assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE); - }).verifyComplete(); + .assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); + assertThat(response.getValue().getValue()).isEqualTo("new-value"); + assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE); + }) + .assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); + assertThat(response.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); + assertThat(response.getCredentialType()).isEqualTo(CredentialType.VALUE); + }) + .verifyComplete(); } @Test public void generateCredential() { AtomicReference> generated = new AtomicReference<>(); - StepVerifier.create(this.credentials.generate(UserParametersRequest.builder().name(CREDENTIAL_NAME) - .username("test-user").parameters(this.passwordParameters.build()).build(), UserCredential.class)) - .assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); - assertThat(response.getCredentialType()).isEqualTo(CredentialType.USER); - assertThat(response.getValue().getUsername()).isEqualTo("test-user"); - assertThat(response.getValue().getPassword()).matches("^[a-zA-Z0-9\\p{Punct}]{12}$"); - assertThat(response.getValue().getPasswordHash()).isNotNull(); + StepVerifier.create(this.credentials.generate(UserParametersRequest.builder() + .name(CREDENTIAL_NAME) + .username("test-user") + .parameters(this.passwordParameters.build()) + .build(), UserCredential.class)).assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); + assertThat(response.getCredentialType()).isEqualTo(CredentialType.USER); + assertThat(response.getValue().getUsername()).isEqualTo("test-user"); + assertThat(response.getValue().getPassword()).matches("^[a-zA-Z0-9\\p{Punct}]{12}$"); + assertThat(response.getValue().getPasswordHash()).isNotNull(); - generated.set(response); - }).verifyComplete(); + generated.set(response); + }).verifyComplete(); StepVerifier.create(this.credentials.getById(generated.get().getId(), UserCredential.class)) - .assertNext((response) -> assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName())) - .verifyComplete(); + .assertNext((response) -> assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName())) + .verifyComplete(); StepVerifier.create(this.credentials.regenerate(CREDENTIAL_NAME, UserCredential.class)) - .assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); - assertThat(response.getValue().getUsername()).isEqualTo("test-user"); - assertThat(response.getValue().getPassword()).matches("^[a-zA-Z0-9\\p{Punct}]{12}$"); - assertThat(response.getValue().getPassword()) - .isNotEqualTo(generated.get().getValue().getPassword()); - assertThat(response.getValue().getPasswordHash()) - .isNotEqualTo(generated.get().getValue().getPasswordHash()); - }).verifyComplete(); + .assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); + assertThat(response.getValue().getUsername()).isEqualTo("test-user"); + assertThat(response.getValue().getPassword()).matches("^[a-zA-Z0-9\\p{Punct}]{12}$"); + assertThat(response.getValue().getPassword()).isNotEqualTo(generated.get().getValue().getPassword()); + assertThat(response.getValue().getPasswordHash()) + .isNotEqualTo(generated.get().getValue().getPasswordHash()); + }) + .verifyComplete(); } @Test public void generateNoOverwriteCredential() { AtomicReference> generated = new AtomicReference<>(); - StepVerifier.create(this.credentials.generate(UserParametersRequest.builder().name(CREDENTIAL_NAME) - .username("test-user").parameters(this.passwordParameters.build()).build(), UserCredential.class)) - .assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); - assertThat(response.getValue().getUsername()).isEqualTo("test-user"); - assertThat(response.getValue().getPassword()).matches("^[a-zA-Z0-9\\p{Punct}]{12}$"); - assertThat(response.getValue().getPasswordHash()).isNotNull(); - - generated.set(response); - }).verifyComplete(); - - StepVerifier - .create(this.credentials.generate( - UserParametersRequest.builder().name(CREDENTIAL_NAME).mode(WriteMode.NO_OVERWRITE) - .username("test-user").parameters(this.passwordParameters.build()).build(), - UserCredential.class)) - .assertNext((response) -> { - assertThat(response.getValue().getUsername()).isEqualTo("test-user"); - assertThat(response.getValue().getPassword()).isEqualTo(generated.get().getValue().getPassword()); - assertThat(response.getValue().getPasswordHash()) - .isEqualTo(generated.get().getValue().getPasswordHash()); - }).verifyComplete(); + StepVerifier.create(this.credentials.generate(UserParametersRequest.builder() + .name(CREDENTIAL_NAME) + .username("test-user") + .parameters(this.passwordParameters.build()) + .build(), UserCredential.class)).assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); + assertThat(response.getValue().getUsername()).isEqualTo("test-user"); + assertThat(response.getValue().getPassword()).matches("^[a-zA-Z0-9\\p{Punct}]{12}$"); + assertThat(response.getValue().getPasswordHash()).isNotNull(); + + generated.set(response); + }).verifyComplete(); + + StepVerifier.create(this.credentials.generate(UserParametersRequest.builder() + .name(CREDENTIAL_NAME) + .mode(WriteMode.NO_OVERWRITE) + .username("test-user") + .parameters(this.passwordParameters.build()) + .build(), UserCredential.class)).assertNext((response) -> { + assertThat(response.getValue().getUsername()).isEqualTo("test-user"); + assertThat(response.getValue().getPassword()).isEqualTo(generated.get().getValue().getPassword()); + assertThat(response.getValue().getPasswordHash()) + .isEqualTo(generated.get().getValue().getPasswordHash()); + }).verifyComplete(); } @Test public void generateOverwriteCredential() { AtomicReference> generated = new AtomicReference<>(); - StepVerifier.create(this.credentials.generate(UserParametersRequest.builder().name(CREDENTIAL_NAME) - .username("test-user").parameters(this.passwordParameters.build()).build(), UserCredential.class)) - .assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); - assertThat(response.getValue().getUsername()).isEqualTo("test-user"); - assertThat(response.getValue().getPassword()).matches("^[a-zA-Z0-9\\p{Punct}]{12}$"); - assertThat(response.getValue().getPasswordHash()).isNotNull(); - - generated.set(response); - }).verifyComplete(); - - StepVerifier - .create(this.credentials.generate( - UserParametersRequest.builder().name(CREDENTIAL_NAME).mode(WriteMode.OVERWRITE) - .username("test-user").parameters(this.passwordParameters.build()).build(), - UserCredential.class)) - .assertNext((response) -> { - assertThat(response.getValue().getUsername()).isEqualTo("test-user"); - assertThat(response.getValue().getPassword()) - .isNotEqualTo(generated.get().getValue().getPassword()); - assertThat(response.getValue().getPasswordHash()) - .isNotEqualTo(generated.get().getValue().getPasswordHash()); - }).verifyComplete(); + StepVerifier.create(this.credentials.generate(UserParametersRequest.builder() + .name(CREDENTIAL_NAME) + .username("test-user") + .parameters(this.passwordParameters.build()) + .build(), UserCredential.class)).assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); + assertThat(response.getValue().getUsername()).isEqualTo("test-user"); + assertThat(response.getValue().getPassword()).matches("^[a-zA-Z0-9\\p{Punct}]{12}$"); + assertThat(response.getValue().getPasswordHash()).isNotNull(); + + generated.set(response); + }).verifyComplete(); + + StepVerifier.create(this.credentials.generate(UserParametersRequest.builder() + .name(CREDENTIAL_NAME) + .mode(WriteMode.OVERWRITE) + .username("test-user") + .parameters(this.passwordParameters.build()) + .build(), UserCredential.class)).assertNext((response) -> { + assertThat(response.getValue().getUsername()).isEqualTo("test-user"); + assertThat(response.getValue().getPassword()).isNotEqualTo(generated.get().getValue().getPassword()); + assertThat(response.getValue().getPasswordHash()) + .isNotEqualTo(generated.get().getValue().getPasswordHash()); + }).verifyComplete(); } @Test public void generateConvergeCredential() { AtomicReference> generated = new AtomicReference<>(); - StepVerifier.create(this.credentials.generate(UserParametersRequest.builder().name(CREDENTIAL_NAME) - .username("test-user").parameters(this.passwordParameters.build()).build(), UserCredential.class)) - .assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); - assertThat(response.getValue().getUsername()).isEqualTo("test-user"); - assertThat(response.getValue().getPassword()).matches("^[a-zA-Z0-9\\p{Punct}]{12}$"); - assertThat(response.getValue().getPasswordHash()).isNotNull(); - - generated.set(response); - }).verifyComplete(); - - StepVerifier - .create(this.credentials.generate( - UserParametersRequest.builder().name(CREDENTIAL_NAME).mode(WriteMode.CONVERGE) - .username("test-user").parameters(this.passwordParameters.build()).build(), - UserCredential.class)) - .assertNext((response) -> { - assertThat(response.getValue().getUsername()).isEqualTo("test-user"); - assertThat(response.getValue().getPassword()).isEqualTo(generated.get().getValue().getPassword()); - assertThat(response.getValue().getPasswordHash()) - .isEqualTo(generated.get().getValue().getPasswordHash()); - }).verifyComplete(); + StepVerifier.create(this.credentials.generate(UserParametersRequest.builder() + .name(CREDENTIAL_NAME) + .username("test-user") + .parameters(this.passwordParameters.build()) + .build(), UserCredential.class)).assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); + assertThat(response.getValue().getUsername()).isEqualTo("test-user"); + assertThat(response.getValue().getPassword()).matches("^[a-zA-Z0-9\\p{Punct}]{12}$"); + assertThat(response.getValue().getPasswordHash()).isNotNull(); + + generated.set(response); + }).verifyComplete(); + + StepVerifier.create(this.credentials.generate(UserParametersRequest.builder() + .name(CREDENTIAL_NAME) + .mode(WriteMode.CONVERGE) + .username("test-user") + .parameters(this.passwordParameters.build()) + .build(), UserCredential.class)).assertNext((response) -> { + assertThat(response.getValue().getUsername()).isEqualTo("test-user"); + assertThat(response.getValue().getPassword()).isEqualTo(generated.get().getValue().getPassword()); + assertThat(response.getValue().getPasswordHash()) + .isEqualTo(generated.get().getValue().getPasswordHash()); + }).verifyComplete(); this.passwordParameters.includeSpecial(false); - StepVerifier - .create(this.credentials.generate( - UserParametersRequest.builder().name(CREDENTIAL_NAME).mode(WriteMode.CONVERGE) - .username("test-user").parameters(this.passwordParameters.build()).build(), - UserCredential.class)) - .assertNext((response) -> { - assertThat(response.getValue().getUsername()).isEqualTo("test-user"); - assertThat(response.getValue().getPassword()) - .isNotEqualTo(generated.get().getValue().getPassword()); - assertThat(response.getValue().getPasswordHash()) - .isNotEqualTo(generated.get().getValue().getPasswordHash()); - }).verifyComplete(); + StepVerifier.create(this.credentials.generate(UserParametersRequest.builder() + .name(CREDENTIAL_NAME) + .mode(WriteMode.CONVERGE) + .username("test-user") + .parameters(this.passwordParameters.build()) + .build(), UserCredential.class)).assertNext((response) -> { + assertThat(response.getValue().getUsername()).isEqualTo("test-user"); + assertThat(response.getValue().getPassword()).isNotEqualTo(generated.get().getValue().getPassword()); + assertThat(response.getValue().getPasswordHash()) + .isNotEqualTo(generated.get().getValue().getPasswordHash()); + }).verifyComplete(); } } diff --git a/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactiveInfoIntegrationTests.java b/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactiveInfoIntegrationTests.java index ab15cace..009bab3b 100644 --- a/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactiveInfoIntegrationTests.java +++ b/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactiveInfoIntegrationTests.java @@ -35,8 +35,9 @@ public void setUp() { @Test public void getInfo() { - StepVerifier.create(this.info.version()).assertNext((response) -> assertThat(response.getVersion()).isNotNull()) - .verifyComplete(); + StepVerifier.create(this.info.version()) + .assertNext((response) -> assertThat(response.getVersion()).isNotNull()) + .verifyComplete(); } } diff --git a/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactiveInterpolationIntegrationTests.java b/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactiveInterpolationIntegrationTests.java index 086d60c2..1d882924 100644 --- a/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactiveInterpolationIntegrationTests.java +++ b/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactiveInterpolationIntegrationTests.java @@ -68,26 +68,29 @@ public void interpolate() throws IOException { }; StepVerifier - .create(this.credentials - .write(JsonCredentialRequest.builder().name(CREDENTIAL_NAME).value(json).build())) - .assertNext((response) -> { - assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); - assertThat(response.getValue()).isEqualTo(json); - assertThat(response.getCredentialType()).isEqualTo(CredentialType.JSON); - assertThat(response.getId()).isNotNull(); - }).verifyComplete(); + .create(this.credentials.write(JsonCredentialRequest.builder().name(CREDENTIAL_NAME).value(json).build())) + .assertNext((response) -> { + assertThat(response.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); + assertThat(response.getValue()).isEqualTo(json); + assertThat(response.getCredentialType()).isEqualTo(CredentialType.JSON); + assertThat(response.getId()).isNotNull(); + }) + .verifyComplete(); StepVerifier.create(this.interpolation.interpolateServiceData(buildVcapServices(CREDENTIAL_NAME.getName()))) - .assertNext((servicesData) -> { - assertThat(servicesData).containsKey("service-offering"); - assertThat(servicesData.get("service-offering")).hasSize(1); - assertThat(servicesData.get("service-offering").get(0)).containsKey("credentials"); - - Map credentials = (Map) servicesData.get("service-offering").get(0) - .get("credentials"); - assertThat(credentials).containsEntry("url", "https://example.com") - .containsEntry("username", "user").containsEntry("password", "secret"); - }).verifyComplete(); + .assertNext((servicesData) -> { + assertThat(servicesData).containsKey("service-offering"); + assertThat(servicesData.get("service-offering")).hasSize(1); + assertThat(servicesData.get("service-offering").get(0)).containsKey("credentials"); + + Map credentials = (Map) servicesData.get("service-offering") + .get(0) + .get("credentials"); + assertThat(credentials).containsEntry("url", "https://example.com") + .containsEntry("username", "user") + .containsEntry("password", "secret"); + }) + .verifyComplete(); } private ServicesData buildVcapServices(String credHubReferenceName) throws IOException { diff --git a/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactivePermissionIntegrationTests.java b/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactivePermissionIntegrationTests.java index b77d34e1..d107d78a 100644 --- a/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactivePermissionIntegrationTests.java +++ b/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactivePermissionIntegrationTests.java @@ -65,36 +65,41 @@ public void managePermissionsServerV1() { assumeTrue(serverApiIsV1()); StepVerifier - .create(this.credentials - .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build())) - .assertNext((response) -> { - assertThat(response.getName()).isEqualTo(CREDENTIAL_NAME); - assertThat(response.getId()).isNotNull(); - }).verifyComplete(); + .create(this.credentials + .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build())) + .assertNext((response) -> { + assertThat(response.getName()).isEqualTo(CREDENTIAL_NAME); + assertThat(response.getId()).isNotNull(); + }) + .verifyComplete(); Permission appPermission = Permission.builder().app("app1").operation(Operation.READ).build(); - Permission userPermission = Permission.builder().user("user1") - .operations(Operation.READ, Operation.WRITE, Operation.DELETE).build(); - Permission clientPermission = Permission.builder().client("client1") - .operations(Operation.READ_ACL, Operation.WRITE_ACL).build(); + Permission userPermission = Permission.builder() + .user("user1") + .operations(Operation.READ, Operation.WRITE, Operation.DELETE) + .build(); + Permission clientPermission = Permission.builder() + .client("client1") + .operations(Operation.READ_ACL, Operation.WRITE_ACL) + .build(); - StepVerifier.create( - this.permissions.addPermissions(CREDENTIAL_NAME, appPermission, userPermission, clientPermission)) - .expectComplete().verify(); + StepVerifier + .create(this.permissions.addPermissions(CREDENTIAL_NAME, appPermission, userPermission, clientPermission)) + .expectComplete() + .verify(); StepVerifier.create(this.permissions.getPermissions(CREDENTIAL_NAME)) - .assertNext( - (response) -> assertThat(response.getActor().getAuthType()).isEqualTo(ActorType.OAUTH_CLIENT)) - .assertNext((response) -> assertThat(response).isEqualTo(appPermission)) - .assertNext((response) -> assertThat(response).isEqualTo(userPermission)) - .assertNext((response) -> assertThat(response).isEqualTo(clientPermission)).verifyComplete(); + .assertNext((response) -> assertThat(response.getActor().getAuthType()).isEqualTo(ActorType.OAUTH_CLIENT)) + .assertNext((response) -> assertThat(response).isEqualTo(appPermission)) + .assertNext((response) -> assertThat(response).isEqualTo(userPermission)) + .assertNext((response) -> assertThat(response).isEqualTo(clientPermission)) + .verifyComplete(); deletePermissionsIfExist(); StepVerifier.create(this.permissions.getPermissions(CREDENTIAL_NAME)) - .assertNext( - (response) -> assertThat(response.getActor().getAuthType()).isEqualTo(ActorType.OAUTH_CLIENT)) - .verifyComplete(); + .assertNext((response) -> assertThat(response.getActor().getAuthType()).isEqualTo(ActorType.OAUTH_CLIENT)) + .verifyComplete(); } @Test @@ -102,27 +107,34 @@ public void managePermissionsServerV2() { assumeTrue(serverApiIsV2()); StepVerifier - .create(this.credentials - .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build())) - .assertNext((response) -> { - assertThat(response.getName()).isEqualTo(CREDENTIAL_NAME); - assertThat(response.getId()).isNotNull(); - }).verifyComplete(); + .create(this.credentials + .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build())) + .assertNext((response) -> { + assertThat(response.getName()).isEqualTo(CREDENTIAL_NAME); + assertThat(response.getId()).isNotNull(); + }) + .verifyComplete(); Permission appPermission = Permission.builder().app("app1").operation(Operation.READ).build(); - Permission userPermission = Permission.builder().user("user1") - .operations(Operation.READ, Operation.WRITE, Operation.DELETE).build(); - Permission clientPermission = Permission.builder().client("client1") - .operations(Operation.READ_ACL, Operation.WRITE_ACL).build(); + Permission userPermission = Permission.builder() + .user("user1") + .operations(Operation.READ, Operation.WRITE, Operation.DELETE) + .build(); + Permission clientPermission = Permission.builder() + .client("client1") + .operations(Operation.READ_ACL, Operation.WRITE_ACL) + .build(); - StepVerifier.create( - this.permissions.addPermissions(CREDENTIAL_NAME, appPermission, userPermission, clientPermission)) - .expectComplete().verify(); + StepVerifier + .create(this.permissions.addPermissions(CREDENTIAL_NAME, appPermission, userPermission, clientPermission)) + .expectComplete() + .verify(); StepVerifier.create(this.permissions.getPermissions(CREDENTIAL_NAME)) - .assertNext((response) -> assertThat(response).isEqualTo(appPermission)) - .assertNext((response) -> assertThat(response).isEqualTo(clientPermission)) - .assertNext((response) -> assertThat(response).isEqualTo(userPermission)).verifyComplete(); + .assertNext((response) -> assertThat(response).isEqualTo(appPermission)) + .assertNext((response) -> assertThat(response).isEqualTo(clientPermission)) + .assertNext((response) -> assertThat(response).isEqualTo(userPermission)) + .verifyComplete(); deletePermissionsIfExist(); @@ -130,12 +142,15 @@ public void managePermissionsServerV2() { } private void deletePermissionsIfExist() { - this.permissions.deletePermission(CREDENTIAL_NAME, Actor.app("app1")).onErrorResume((e) -> Mono.empty()) - .block(); - this.permissions.deletePermission(CREDENTIAL_NAME, Actor.user("user1")).onErrorResume((e) -> Mono.empty()) - .block(); - this.permissions.deletePermission(CREDENTIAL_NAME, Actor.client("client1")).onErrorResume((e) -> Mono.empty()) - .block(); + this.permissions.deletePermission(CREDENTIAL_NAME, Actor.app("app1")) + .onErrorResume((e) -> Mono.empty()) + .block(); + this.permissions.deletePermission(CREDENTIAL_NAME, Actor.user("user1")) + .onErrorResume((e) -> Mono.empty()) + .block(); + this.permissions.deletePermission(CREDENTIAL_NAME, Actor.client("client1")) + .onErrorResume((e) -> Mono.empty()) + .block(); } } diff --git a/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactivePermissionV2IntegrationTests.java b/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactivePermissionV2IntegrationTests.java index 59746cfd..f2f483bc 100644 --- a/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactivePermissionV2IntegrationTests.java +++ b/spring-credhub-reactive-integration-tests/src/test/java/org/springframework/credhub/integration/ReactivePermissionV2IntegrationTests.java @@ -68,25 +68,29 @@ public void managePermissions() { AtomicReference permissionId = new AtomicReference<>(); StepVerifier - .create(this.credentials - .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build())) - .assertNext((response) -> { - assertThat(response.getName()).isEqualTo(CREDENTIAL_NAME); - assertThat(response.getId()).isNotNull(); - }).verifyComplete(); - - Permission clientPermission = Permission.builder().client("client1") - .operations(Operation.READ, Operation.WRITE, Operation.DELETE).build(); + .create(this.credentials + .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build())) + .assertNext((response) -> { + assertThat(response.getName()).isEqualTo(CREDENTIAL_NAME); + assertThat(response.getId()).isNotNull(); + }) + .verifyComplete(); + + Permission clientPermission = Permission.builder() + .client("client1") + .operations(Operation.READ, Operation.WRITE, Operation.DELETE) + .build(); StepVerifier.create(this.permissions.addPermissions(CREDENTIAL_NAME, clientPermission)) - .assertNext((response) -> { - assertThat(response.getId()).isNotNull(); - assertThat(response.getPath()).isEqualTo(CREDENTIAL_NAME.getName()); - assertPermissions(response, ActorType.OAUTH_CLIENT, "client1", Operation.READ, Operation.WRITE, - Operation.DELETE); + .assertNext((response) -> { + assertThat(response.getId()).isNotNull(); + assertThat(response.getPath()).isEqualTo(CREDENTIAL_NAME.getName()); + assertPermissions(response, ActorType.OAUTH_CLIENT, "client1", Operation.READ, Operation.WRITE, + Operation.DELETE); - permissionId.set(response.getId()); - }).verifyComplete(); + permissionId.set(response.getId()); + }) + .verifyComplete(); StepVerifier.create(this.permissions.getPermissions(permissionId.get())).assertNext((response) -> { assertThat(response.getId()).isEqualTo(permissionId.get()); @@ -105,36 +109,42 @@ public void updatePermissions() { AtomicReference permissionId = new AtomicReference<>(); StepVerifier - .create(this.credentials - .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build())) - .assertNext((response) -> { - assertThat(response.getName()).isEqualTo(CREDENTIAL_NAME); - assertThat(response.getId()).isNotNull(); - }).verifyComplete(); - - Permission clientPermission = Permission.builder().client("client1") - .operations(Operation.READ, Operation.WRITE, Operation.DELETE).build(); + .create(this.credentials + .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build())) + .assertNext((response) -> { + assertThat(response.getName()).isEqualTo(CREDENTIAL_NAME); + assertThat(response.getId()).isNotNull(); + }) + .verifyComplete(); + + Permission clientPermission = Permission.builder() + .client("client1") + .operations(Operation.READ, Operation.WRITE, Operation.DELETE) + .build(); StepVerifier.create(this.permissions.addPermissions(CREDENTIAL_NAME, clientPermission)) - .assertNext((response) -> { - assertThat(response.getId()).isNotNull(); - assertThat(response.getPath()).isEqualTo(CREDENTIAL_NAME.getName()); - assertPermissions(response, ActorType.OAUTH_CLIENT, "client1", Operation.READ, Operation.WRITE, - Operation.DELETE); + .assertNext((response) -> { + assertThat(response.getId()).isNotNull(); + assertThat(response.getPath()).isEqualTo(CREDENTIAL_NAME.getName()); + assertPermissions(response, ActorType.OAUTH_CLIENT, "client1", Operation.READ, Operation.WRITE, + Operation.DELETE); - permissionId.set(response.getId()); - }).verifyComplete(); + permissionId.set(response.getId()); + }) + .verifyComplete(); - Permission newPermission = Permission.builder().client("client1") - .operations(Operation.READ_ACL, Operation.WRITE_ACL).build(); + Permission newPermission = Permission.builder() + .client("client1") + .operations(Operation.READ_ACL, Operation.WRITE_ACL) + .build(); StepVerifier.create(this.permissions.updatePermissions(permissionId.get(), CREDENTIAL_NAME, newPermission)) - .assertNext((response) -> { - assertThat(response.getId()).isEqualTo(permissionId.get()); - assertThat(response.getPath()).isEqualTo(CREDENTIAL_NAME.getName()); - assertPermissions(response, ActorType.OAUTH_CLIENT, "client1", Operation.READ_ACL, - Operation.WRITE_ACL); - }).verifyComplete(); + .assertNext((response) -> { + assertThat(response.getId()).isEqualTo(permissionId.get()); + assertThat(response.getPath()).isEqualTo(CREDENTIAL_NAME.getName()); + assertPermissions(response, ActorType.OAUTH_CLIENT, "client1", Operation.READ_ACL, Operation.WRITE_ACL); + }) + .verifyComplete(); StepVerifier.create(this.permissions.getPermissions(permissionId.get())).assertNext((response) -> { assertThat(response.getId()).isEqualTo(permissionId.get()); diff --git a/spring-credhub-starter/src/test/java/org/springframework/credhub/autoconfig/CredHubAutoConfigurationTests.java b/spring-credhub-starter/src/test/java/org/springframework/credhub/autoconfig/CredHubAutoConfigurationTests.java index 1bda35b0..75da551c 100644 --- a/spring-credhub-starter/src/test/java/org/springframework/credhub/autoconfig/CredHubAutoConfigurationTests.java +++ b/spring-credhub-starter/src/test/java/org/springframework/credhub/autoconfig/CredHubAutoConfigurationTests.java @@ -38,31 +38,33 @@ public class CredHubAutoConfigurationTests { private final ApplicationContextRunner context = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(CredHubAutoConfiguration.class)); + .withConfiguration(AutoConfigurations.of(CredHubAutoConfiguration.class)); @Test public void autoConfiguredWithDefaultProperties() { - this.context.withPropertyValues("spring.credhub.url=https://localhost", - "spring.credhub.oauth2.registration-id=test-client", "spring.credhub.connection-timeout=30", - "spring.credhub.read-timeout=60", "debug=true").run(this::assertPropertiesConfigured); + this.context + .withPropertyValues("spring.credhub.url=https://localhost", + "spring.credhub.oauth2.registration-id=test-client", "spring.credhub.connection-timeout=30", + "spring.credhub.read-timeout=60", "debug=true") + .run(this::assertPropertiesConfigured); } @Test public void autoConfiguredWithCustomProperties() { this.context.withConfiguration(AutoConfigurations.of(CustomPropertiesConfiguration.class)) - .withPropertyValues("my.custom.credhub.url=https://localhost", - "my.custom.credhub.oauth2.registration-id=test-client", - "my.custom.credhub.connection-timeout=30", "my.custom.credhub.read-timeout=60") - .run(this::assertPropertiesConfigured); + .withPropertyValues("my.custom.credhub.url=https://localhost", + "my.custom.credhub.oauth2.registration-id=test-client", "my.custom.credhub.connection-timeout=30", + "my.custom.credhub.read-timeout=60") + .run(this::assertPropertiesConfigured); } @Test public void webClientConnectorNotConfigured() { this.context.withClassLoader(new FilteredClassLoader(WebClient.class)) - .withPropertyValues("spring.credhub.url=https://localhost", - "spring.credhub.oauth2.registration-id=test-client", "spring.credhub.connection-timeout=30", - "spring.credhub.read-timeout=60") - .run((context) -> assertThat(context).doesNotHaveBean(ClientHttpConnector.class)); + .withPropertyValues("spring.credhub.url=https://localhost", + "spring.credhub.oauth2.registration-id=test-client", "spring.credhub.connection-timeout=30", + "spring.credhub.read-timeout=60") + .run((context) -> assertThat(context).doesNotHaveBean(ClientHttpConnector.class)); } private void assertPropertiesConfigured(AssertableApplicationContext context) { diff --git a/spring-credhub-starter/src/test/java/org/springframework/credhub/autoconfig/CredHubOAuth2AutoConfigurationTests.java b/spring-credhub-starter/src/test/java/org/springframework/credhub/autoconfig/CredHubOAuth2AutoConfigurationTests.java index d47ddcd4..70720490 100644 --- a/spring-credhub-starter/src/test/java/org/springframework/credhub/autoconfig/CredHubOAuth2AutoConfigurationTests.java +++ b/spring-credhub-starter/src/test/java/org/springframework/credhub/autoconfig/CredHubOAuth2AutoConfigurationTests.java @@ -42,7 +42,7 @@ public class CredHubOAuth2AutoConfigurationTests { "spring.security.oauth2.client.provider.uaa.token-uri=https://example.com/uaa/oauth/token" }; private final ApplicationContextRunner context = new ApplicationContextRunner().withPropertyValues("debug=true") - .withConfiguration(AutoConfigurations.of(this.configurations)); + .withConfiguration(AutoConfigurations.of(this.configurations)); @Test public void oauth2ContextConfigured() { @@ -55,38 +55,42 @@ public void oauth2ContextConfigured() { @Test public void oauth2ContextConfiguredWithoutWebClient() { this.context.withClassLoader(new FilteredClassLoader(WebClient.class)) - .withPropertyValues(this.oAuth2ClientProperties).run((context) -> { - assertServletOAuth2ContextConfigured(context); - assertReactiveOAuth2ContextNotConfigured(context); - }); + .withPropertyValues(this.oAuth2ClientProperties) + .run((context) -> { + assertServletOAuth2ContextConfigured(context); + assertReactiveOAuth2ContextNotConfigured(context); + }); } @Test public void oauth2ContextConfiguredWithWebApp() { new WebApplicationContextRunner().withConfiguration(AutoConfigurations.of(this.configurations)) - .withPropertyValues(this.oAuth2ClientProperties).run((context) -> { - assertServletOAuth2ContextConfigured(context); - assertReactiveOAuth2ContextConfigured(context); - }); + .withPropertyValues(this.oAuth2ClientProperties) + .run((context) -> { + assertServletOAuth2ContextConfigured(context); + assertReactiveOAuth2ContextConfigured(context); + }); } @Test public void oauth2ContextConfiguredWithReactiveWebApp() { new ReactiveWebApplicationContextRunner().withConfiguration(AutoConfigurations.of(this.configurations)) - .withPropertyValues(this.oAuth2ClientProperties).run((context) -> { - assertServletOAuth2ContextConfigured(context); - assertReactiveOAuth2ContextConfigured(context); - }); + .withPropertyValues(this.oAuth2ClientProperties) + .run((context) -> { + assertServletOAuth2ContextConfigured(context); + assertReactiveOAuth2ContextConfigured(context); + }); } @Test public void oauth2ContextConfiguredWithReactiveWebAppNoServlet() { new ReactiveWebApplicationContextRunner().withClassLoader(new FilteredClassLoader("jakarta.servlet")) - .withConfiguration(AutoConfigurations.of(this.configurations)) - .withPropertyValues(this.oAuth2ClientProperties).run((context) -> { - assertServletOAuth2ContextNotConfigured(context); - assertReactiveOAuth2ContextConfigured(context); - }); + .withConfiguration(AutoConfigurations.of(this.configurations)) + .withPropertyValues(this.oAuth2ClientProperties) + .run((context) -> { + assertServletOAuth2ContextNotConfigured(context); + assertReactiveOAuth2ContextConfigured(context); + }); } @Test @@ -97,7 +101,7 @@ public void oauth2ContextNotConfiguredWithoutProperties() { @Test public void oauth2ContextNotConfiguredWithoutSpringSecurity() { this.context.withClassLoader(new FilteredClassLoader(ClientRegistration.class)) - .run(this::assertOAuth2ContextNotConfigured); + .run(this::assertOAuth2ContextNotConfigured); } private void assertServletOAuth2ContextConfigured( diff --git a/spring-credhub-starter/src/test/java/org/springframework/credhub/autoconfig/CredHubTemplateAutoConfigurationTests.java b/spring-credhub-starter/src/test/java/org/springframework/credhub/autoconfig/CredHubTemplateAutoConfigurationTests.java index 782b2605..36272816 100644 --- a/spring-credhub-starter/src/test/java/org/springframework/credhub/autoconfig/CredHubTemplateAutoConfigurationTests.java +++ b/spring-credhub-starter/src/test/java/org/springframework/credhub/autoconfig/CredHubTemplateAutoConfigurationTests.java @@ -64,23 +64,24 @@ public class CredHubTemplateAutoConfigurationTests { "org.springframework.web.reactive.function.client", "org.springframework.security.oauth2.client"); private final ApplicationContextRunner context = new ApplicationContextRunner() - .withConfiguration( - AutoConfigurations.of(ReactiveOAuth2ClientAutoConfiguration.class, CredHubAutoConfiguration.class, - CredHubOAuth2AutoConfiguration.class, CredHubTemplateAutoConfiguration.class)) - .withInitializer(ConditionEvaluationReportLoggingListener.forLogLevel(LogLevel.INFO)); + .withConfiguration( + AutoConfigurations.of(ReactiveOAuth2ClientAutoConfiguration.class, CredHubAutoConfiguration.class, + CredHubOAuth2AutoConfiguration.class, CredHubTemplateAutoConfiguration.class)) + .withInitializer(ConditionEvaluationReportLoggingListener.forLogLevel(LogLevel.INFO)); @Test public void credHubTemplatesConfigured() { this.context.withPropertyValues("spring.credhub.url=https://localhost") - .withClassLoader(SPRING_SECURITY_FILTERED_CLASS_LOADER).run((context) -> { - assertThat(context).hasSingleBean(CredHubTemplate.class); - CredHubTemplate credHubTemplate = context.getBean(CredHubTemplate.class); - assertThat(credHubTemplate.isUsingOAuth2()).isFalse(); - - assertThat(context).hasSingleBean(ReactiveCredHubTemplate.class); - ReactiveCredHubTemplate reactiveCredHubTemplate = context.getBean(ReactiveCredHubTemplate.class); - assertThat(reactiveCredHubTemplate.isUsingOAuth2()).isFalse(); - }); + .withClassLoader(SPRING_SECURITY_FILTERED_CLASS_LOADER) + .run((context) -> { + assertThat(context).hasSingleBean(CredHubTemplate.class); + CredHubTemplate credHubTemplate = context.getBean(CredHubTemplate.class); + assertThat(credHubTemplate.isUsingOAuth2()).isFalse(); + + assertThat(context).hasSingleBean(ReactiveCredHubTemplate.class); + ReactiveCredHubTemplate reactiveCredHubTemplate = context.getBean(ReactiveCredHubTemplate.class); + assertThat(reactiveCredHubTemplate.isUsingOAuth2()).isFalse(); + }); } @Test @@ -99,13 +100,14 @@ public void credHubTemplatesConfiguredWithSpringSecurityWithoutClientId() { @Test public void reactiveCredHubTemplateNotConfiguredWithoutWebClient() { this.context.withPropertyValues("spring.credhub.url=https://localhost") - .withClassLoader(new FilteredClassLoader(WebClient.class)).run((context) -> { - assertThat(context).hasSingleBean(CredHubTemplate.class); - CredHubTemplate credHubTemplate = context.getBean(CredHubTemplate.class); - assertThat(credHubTemplate.isUsingOAuth2()).isFalse(); - - assertThat(context).doesNotHaveBean(ReactiveCredHubTemplate.class); - }); + .withClassLoader(new FilteredClassLoader(WebClient.class)) + .run((context) -> { + assertThat(context).hasSingleBean(CredHubTemplate.class); + CredHubTemplate credHubTemplate = context.getBean(CredHubTemplate.class); + assertThat(credHubTemplate.isUsingOAuth2()).isFalse(); + + assertThat(context).doesNotHaveBean(ReactiveCredHubTemplate.class); + }); } @Test @@ -118,21 +120,21 @@ public void credHubTemplatesConfiguredWithOAuth2() { "spring.security.oauth2.client.registration.credhub-client.client-secret=test-secret", "spring.security.oauth2.client.registration.credhub-client.authorization-grant-type=client_credentials", "spring.security.oauth2.client.provider.uaa.token-uri=https://example.com/uaa/oauth/token") - .run((context) -> { - assertThat(context).hasSingleBean(CredHubTemplate.class); - assertThat(context).hasSingleBean(ClientRegistrationRepository.class); - assertThat(context).hasSingleBean(OAuth2AuthorizedClientRepository.class); - assertThat(context).doesNotHaveBean(OAuth2AuthorizedClientManager.class); - CredHubTemplate credHubTemplate = context.getBean(CredHubTemplate.class); - assertThat(credHubTemplate.isUsingOAuth2()).isTrue(); - - assertThat(context).hasSingleBean(ReactiveCredHubTemplate.class); - assertThat(context).hasSingleBean(ReactiveClientRegistrationRepository.class); - assertThat(context).hasSingleBean(ServerOAuth2AuthorizedClientRepository.class); - assertThat(context).hasSingleBean(ReactiveOAuth2AuthorizedClientManager.class); - ReactiveCredHubTemplate reactiveCredHubTemplate = context.getBean(ReactiveCredHubTemplate.class); - assertThat(reactiveCredHubTemplate.isUsingOAuth2()).isTrue(); - }); + .run((context) -> { + assertThat(context).hasSingleBean(CredHubTemplate.class); + assertThat(context).hasSingleBean(ClientRegistrationRepository.class); + assertThat(context).hasSingleBean(OAuth2AuthorizedClientRepository.class); + assertThat(context).doesNotHaveBean(OAuth2AuthorizedClientManager.class); + CredHubTemplate credHubTemplate = context.getBean(CredHubTemplate.class); + assertThat(credHubTemplate.isUsingOAuth2()).isTrue(); + + assertThat(context).hasSingleBean(ReactiveCredHubTemplate.class); + assertThat(context).hasSingleBean(ReactiveClientRegistrationRepository.class); + assertThat(context).hasSingleBean(ServerOAuth2AuthorizedClientRepository.class); + assertThat(context).hasSingleBean(ReactiveOAuth2AuthorizedClientManager.class); + ReactiveCredHubTemplate reactiveCredHubTemplate = context.getBean(ReactiveCredHubTemplate.class); + assertThat(reactiveCredHubTemplate.isUsingOAuth2()).isTrue(); + }); } @Test @@ -145,22 +147,22 @@ public void credHubTemplatesConfiguredWithOAuth2AndCustomClientManager() { "spring.security.oauth2.client.registration.credhub-client.client-secret=test-secret", "spring.security.oauth2.client.registration.credhub-client.authorization-grant-type=client_credentials", "spring.security.oauth2.client.provider.uaa.token-uri=https://example.com/uaa/oauth/token") - .withUserConfiguration(ClientManagerConfiguration.class).run((context) -> { - assertThat(context).hasSingleBean(CredHubTemplate.class); - assertThat(context).hasSingleBean(ClientRegistrationRepository.class); - assertThat(context).hasSingleBean(OAuth2AuthorizedClientRepository.class); - assertThat(context).hasSingleBean(AuthorizedClientServiceOAuth2AuthorizedClientManager.class); - CredHubTemplate credHubTemplate = context.getBean(CredHubTemplate.class); - assertThat(credHubTemplate.isUsingOAuth2()).isTrue(); - - assertThat(context).hasSingleBean(ReactiveCredHubTemplate.class); - assertThat(context).hasSingleBean(ReactiveClientRegistrationRepository.class); - assertThat(context).hasSingleBean(ServerOAuth2AuthorizedClientRepository.class); - assertThat(context) - .hasSingleBean(AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager.class); - ReactiveCredHubTemplate reactiveCredHubTemplate = context.getBean(ReactiveCredHubTemplate.class); - assertThat(reactiveCredHubTemplate.isUsingOAuth2()).isTrue(); - }); + .withUserConfiguration(ClientManagerConfiguration.class) + .run((context) -> { + assertThat(context).hasSingleBean(CredHubTemplate.class); + assertThat(context).hasSingleBean(ClientRegistrationRepository.class); + assertThat(context).hasSingleBean(OAuth2AuthorizedClientRepository.class); + assertThat(context).hasSingleBean(AuthorizedClientServiceOAuth2AuthorizedClientManager.class); + CredHubTemplate credHubTemplate = context.getBean(CredHubTemplate.class); + assertThat(credHubTemplate.isUsingOAuth2()).isTrue(); + + assertThat(context).hasSingleBean(ReactiveCredHubTemplate.class); + assertThat(context).hasSingleBean(ReactiveClientRegistrationRepository.class); + assertThat(context).hasSingleBean(ServerOAuth2AuthorizedClientRepository.class); + assertThat(context).hasSingleBean(AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager.class); + ReactiveCredHubTemplate reactiveCredHubTemplate = context.getBean(ReactiveCredHubTemplate.class); + assertThat(reactiveCredHubTemplate.isUsingOAuth2()).isTrue(); + }); } @Test @@ -173,52 +175,54 @@ public void credHubTemplatesNotConfiguredWithInvalidClientRegistration() { "spring.security.oauth2.client.registration.credhub-client.client-secret=test-secret", "spring.security.oauth2.client.registration.credhub-client.authorization-grant-type=client_credentials", "spring.security.oauth2.client.provider.uaa.token-uri=https://example.com/uaa/oauth/token") - .run((context) -> assertThat(context).getFailure().hasMessageContaining( - "The CredHub OAuth2 client registration ID 'invalid-client' is not a valid")); + .run((context) -> assertThat(context).getFailure() + .hasMessageContaining("The CredHub OAuth2 client registration ID 'invalid-client' is not a valid")); } @Test public void credHubTemplateNotConfiguredWithMissingClientRegistration() { this.context.withClassLoader(WEB_CLIENT_AND_SECURITY_FILTERED_CLASS_LOADER) - .withPropertyValues("spring.credhub.url=https://localhost", - "spring.credhub.oauth2.registration-id=credhub-client") - .run((context) -> assertThat(context).getFailure() - .hasMessageMatching(noSuchBeanExceptionMessage("ClientRegistrationRepository"))); + .withPropertyValues("spring.credhub.url=https://localhost", + "spring.credhub.oauth2.registration-id=credhub-client") + .run((context) -> assertThat(context).getFailure() + .hasMessageMatching(noSuchBeanExceptionMessage("ClientRegistrationRepository"))); } @Test public void reactiveCredHubTemplateNotConfiguredWithMissingClientRegistration() { this.context.withClassLoader(SERVLET_AND_SECURITY_FILTERED_CLASS_LOADER) - .withPropertyValues("spring.credhub.url=https://localhost", - "spring.credhub.oauth2.registration-id=credhub-client") - .run((context) -> assertThat(context).getFailure() - .hasMessageMatching(noSuchBeanExceptionMessage("ReactiveClientRegistrationRepository"))); + .withPropertyValues("spring.credhub.url=https://localhost", + "spring.credhub.oauth2.registration-id=credhub-client") + .run((context) -> assertThat(context).getFailure() + .hasMessageMatching(noSuchBeanExceptionMessage("ReactiveClientRegistrationRepository"))); } @Test public void credHubTemplateNotConfiguredWithOAuth2ButMissingSpringSecurity() { - this.context.withClassLoader(WEB_CLIENT_AND_SECURITY_FILTERED_CLASS_LOADER).withPropertyValues( - "spring.credhub.url=https://localhost", "spring.credhub.oauth2.registration-id=credhub-client", - - "spring.security.oauth2.client.registration.credhub-client.provider=uaa", - "spring.security.oauth2.client.registration.credhub-client.client-id=test-client", - "spring.security.oauth2.client.registration.credhub-client.client-secret=test-secret", - "spring.security.oauth2.client.registration.credhub-client.authorization-grant-type=client_credentials", - "spring.security.oauth2.client.provider.uaa.token-uri=https://example.com/uaa/oauth/token") - .run((context) -> assertThat(context).hasFailed()); + this.context.withClassLoader(WEB_CLIENT_AND_SECURITY_FILTERED_CLASS_LOADER) + .withPropertyValues("spring.credhub.url=https://localhost", + "spring.credhub.oauth2.registration-id=credhub-client", + + "spring.security.oauth2.client.registration.credhub-client.provider=uaa", + "spring.security.oauth2.client.registration.credhub-client.client-id=test-client", + "spring.security.oauth2.client.registration.credhub-client.client-secret=test-secret", + "spring.security.oauth2.client.registration.credhub-client.authorization-grant-type=client_credentials", + "spring.security.oauth2.client.provider.uaa.token-uri=https://example.com/uaa/oauth/token") + .run((context) -> assertThat(context).hasFailed()); } @Test public void reactiveCredHubTemplateNotConfiguredWithOAuth2ButMissingSpringSecurity() { - this.context.withClassLoader(SERVLET_AND_SECURITY_FILTERED_CLASS_LOADER).withPropertyValues( - "spring.credhub.url=https://localhost", "spring.credhub.oauth2.registration-id=credhub-client", - - "spring.security.oauth2.client.registration.credhub-client.provider=uaa", - "spring.security.oauth2.client.registration.credhub-client.client-id=test-client", - "spring.security.oauth2.client.registration.credhub-client.client-secret=test-secret", - "spring.security.oauth2.client.registration.credhub-client.authorization-grant-type=client_credentials", - "spring.security.oauth2.client.provider.uaa.token-uri=https://example.com/uaa/oauth/token") - .run((context) -> assertThat(context).hasFailed()); + this.context.withClassLoader(SERVLET_AND_SECURITY_FILTERED_CLASS_LOADER) + .withPropertyValues("spring.credhub.url=https://localhost", + "spring.credhub.oauth2.registration-id=credhub-client", + + "spring.security.oauth2.client.registration.credhub-client.provider=uaa", + "spring.security.oauth2.client.registration.credhub-client.client-id=test-client", + "spring.security.oauth2.client.registration.credhub-client.client-secret=test-secret", + "spring.security.oauth2.client.registration.credhub-client.authorization-grant-type=client_credentials", + "spring.security.oauth2.client.provider.uaa.token-uri=https://example.com/uaa/oauth/token") + .run((context) -> assertThat(context).hasFailed()); } private String noSuchBeanExceptionMessage(final String className) {