Use Reactive Spring CredHub APIs
- Replace the use of the imperative Spring CredHub APIs in favor of the reactive alternatives. - Build against the latest Spring CredHub snapshots - Increase heap memory for component tests
This commit is contained in:
committed by
Roy Clarkson
parent
fd78298723
commit
171554905e
@@ -32,7 +32,7 @@ ext {
|
||||
springFrameworkVersion = project.findProperty("springFrameworkVersion") ?: "5.2.2.RELEASE"
|
||||
reactorVersion = project.findProperty("reactorVersion") ?: "Dysprosium-SR2"
|
||||
openServiceBrokerVersion = "3.1.0.RELEASE"
|
||||
springCredhubVersion = "2.0.1.RELEASE"
|
||||
springCredhubVersion = "2.1.0.BUILD-SNAPSHOT"
|
||||
cfJavaClientVersion = "4.2.0.RELEASE"
|
||||
blockHoundVersion = "1.0.1.RELEASE"
|
||||
junitPlatformLauncherVersion = "1.5.2"
|
||||
@@ -82,6 +82,7 @@ configure(allprojects) {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url "https://repo.spring.io/libs-release" }
|
||||
maven { url "https://repo.spring.io/libs-snapshot" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -40,6 +40,7 @@ dependencies {
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test") {
|
||||
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
|
||||
}
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-webflux")
|
||||
testImplementation("io.projectreactor.tools:blockhound-junit-platform:${blockHoundVersion}")
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.cloud.appbroker.workflow.binding.CredHubPersistingDel
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.credhub.autoconfig.CredHubTemplateAutoConfiguration;
|
||||
import org.springframework.credhub.core.CredHubOperations;
|
||||
import org.springframework.credhub.core.ReactiveCredHubOperations;
|
||||
|
||||
/**
|
||||
* CredHub auto-configuration
|
||||
@@ -37,8 +37,8 @@ import org.springframework.credhub.core.CredHubOperations;
|
||||
@Configuration
|
||||
@AutoConfigureBefore(AppBrokerAutoConfiguration.class)
|
||||
@AutoConfigureAfter(CredHubTemplateAutoConfiguration.class)
|
||||
@ConditionalOnClass(CredHubOperations.class)
|
||||
@ConditionalOnBean(CredHubOperations.class)
|
||||
@ConditionalOnClass(ReactiveCredHubOperations.class)
|
||||
@ConditionalOnBean(ReactiveCredHubOperations.class)
|
||||
public class CredHubAutoConfiguration {
|
||||
|
||||
@Value("${spring.application.name}")
|
||||
@@ -47,35 +47,35 @@ public class CredHubAutoConfiguration {
|
||||
/**
|
||||
* Provide a {@link CreateServiceInstanceAppBindingWorkflow} bean
|
||||
*
|
||||
* @param credHubOperations the CredHubOperations bean
|
||||
* @param credHubOperations the ReactiveCredHubOperations bean
|
||||
* @return the bean
|
||||
*/
|
||||
@Bean
|
||||
public CreateServiceInstanceAppBindingWorkflow credhubPersistingCreateServiceInstanceAppBindingWorkflow(
|
||||
CredHubOperations credHubOperations) {
|
||||
ReactiveCredHubOperations credHubOperations) {
|
||||
return new CredHubPersistingCreateServiceInstanceAppBindingWorkflow(credHubOperations, appName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a {@link DeleteServiceInstanceBindingWorkflow} bean
|
||||
*
|
||||
* @param credHubOperations the CredHubOperations bean
|
||||
* @param credHubOperations the ReactiveCredHubOperations bean
|
||||
* @return the bean
|
||||
*/
|
||||
@Bean
|
||||
public DeleteServiceInstanceBindingWorkflow credhubPersistingDeleteServiceInstanceAppBindingWorkflow(
|
||||
CredHubOperations credHubOperations) {
|
||||
ReactiveCredHubOperations credHubOperations) {
|
||||
return new CredHubPersistingDeleteServiceInstanceBindingWorkflow(credHubOperations, appName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a {@link CredHubCredentialsGenerator} bean
|
||||
*
|
||||
* @param credHubOperations the CredHubOperations bean
|
||||
* @param credHubOperations the ReactiveCredHubOperations bean
|
||||
* @return the bean
|
||||
*/
|
||||
@Bean
|
||||
public CredHubCredentialsGenerator credHubCredentialsGenerator(CredHubOperations credHubOperations) {
|
||||
public CredHubCredentialsGenerator credHubCredentialsGenerator(ReactiveCredHubOperations credHubOperations) {
|
||||
return new CredHubCredentialsGenerator(credHubOperations);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@ import org.springframework.cloud.appbroker.extensions.credentials.SimpleCredenti
|
||||
import org.springframework.cloud.appbroker.workflow.binding.CredHubPersistingCreateServiceInstanceAppBindingWorkflow;
|
||||
import org.springframework.cloud.appbroker.workflow.binding.CredHubPersistingDeleteServiceInstanceBindingWorkflow;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.credhub.core.CredHubOperations;
|
||||
import org.springframework.credhub.core.CredHubTemplate;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.credhub.core.ReactiveCredHubOperations;
|
||||
import org.springframework.credhub.core.ReactiveCredHubTemplate;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -52,7 +52,7 @@ class CredHubAutoConfigurationTest {
|
||||
@Test
|
||||
void servicesAreNotCreatedWithoutCredHubOnClasspath() {
|
||||
contextRunner
|
||||
.withClassLoader(new FilteredClassLoader(CredHubOperations.class))
|
||||
.withClassLoader(new FilteredClassLoader(ReactiveCredHubOperations.class))
|
||||
.run((context) -> {
|
||||
assertThat(context)
|
||||
.hasSingleBean(CredentialGenerator.class)
|
||||
@@ -84,8 +84,8 @@ class CredHubAutoConfigurationTest {
|
||||
public static class CredHubConfiguration {
|
||||
|
||||
@Bean
|
||||
public CredHubOperations credHubOperations() {
|
||||
return new CredHubTemplate(new RestTemplate());
|
||||
public ReactiveCredHubOperations credHubOperations() {
|
||||
return new ReactiveCredHubTemplate(WebClient.create());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,13 +22,11 @@ import reactor.util.function.Tuple2;
|
||||
public interface CredentialGenerator {
|
||||
|
||||
Mono<Tuple2<String, String>> generateUser(String applicationId, String serviceInstanceId, String descriptor,
|
||||
int length, boolean includeUppercaseAlpha,
|
||||
boolean includeLowercaseAlpha, boolean includeNumeric,
|
||||
int length, boolean includeUppercaseAlpha, boolean includeLowercaseAlpha, boolean includeNumeric,
|
||||
boolean includeSpecial);
|
||||
|
||||
Mono<String> generateString(String applicationId, String serviceInstanceId, String descriptor,
|
||||
int length, boolean includeUppercaseAlpha,
|
||||
boolean includeLowercaseAlpha, boolean includeNumeric,
|
||||
int length, boolean includeUppercaseAlpha, boolean includeLowercaseAlpha, boolean includeNumeric,
|
||||
boolean includeSpecial);
|
||||
|
||||
default Mono<Void> deleteUser(String applicationId, String serviceInstanceId, String descriptor) {
|
||||
|
||||
@@ -28,11 +28,14 @@ import com.github.tomakehurst.wiremock.stubbing.StubMapping;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.test.context.TestComponent;
|
||||
import org.springframework.cloud.appbroker.autoconfigure.CloudFoundryAppDeployerAutoConfiguration;
|
||||
|
||||
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@AutoConfigureBefore(CloudFoundryAppDeployerAutoConfiguration.class)
|
||||
@TestComponent
|
||||
public class WiremockServerFixture {
|
||||
|
||||
|
||||
@@ -25,12 +25,14 @@ dependencyManagement {
|
||||
dependencies {
|
||||
compile project(":spring-cloud-app-broker-core")
|
||||
compile("org.springframework.credhub:spring-credhub-starter:${springCredhubVersion}")
|
||||
compile("org.springframework.cloud:spring-cloud-open-service-broker-core:${openServiceBrokerVersion}")
|
||||
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test") {
|
||||
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
|
||||
}
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-webflux")
|
||||
testImplementation("io.projectreactor:reactor-test")
|
||||
testImplementation("io.projectreactor.tools:blockhound-junit-platform:${blockHoundVersion}")
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import reactor.core.publisher.Mono;
|
||||
import reactor.util.function.Tuple2;
|
||||
import reactor.util.function.Tuples;
|
||||
|
||||
import org.springframework.credhub.core.CredHubOperations;
|
||||
import org.springframework.credhub.core.ReactiveCredHubOperations;
|
||||
import org.springframework.credhub.support.CredentialDetails;
|
||||
import org.springframework.credhub.support.SimpleCredentialName;
|
||||
import org.springframework.credhub.support.password.PasswordCredential;
|
||||
@@ -31,23 +31,22 @@ import org.springframework.credhub.support.user.UserParametersRequest;
|
||||
|
||||
public class CredHubCredentialsGenerator implements CredentialGenerator {
|
||||
|
||||
private final CredHubOperations credHubOperations;
|
||||
private final ReactiveCredHubOperations credHubOperations;
|
||||
|
||||
public CredHubCredentialsGenerator(CredHubOperations credHubOperations) {
|
||||
public CredHubCredentialsGenerator(ReactiveCredHubOperations credHubOperations) {
|
||||
this.credHubOperations = credHubOperations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Tuple2<String, String>> generateUser(String applicationId, String serviceInstanceId, String descriptor,
|
||||
int length, boolean includeUppercaseAlpha, boolean includeLowercaseAlpha,
|
||||
boolean includeNumeric, boolean includeSpecial) {
|
||||
return Mono.fromCallable(() -> this.credHubOperations.credentials().generate(UserParametersRequest.builder()
|
||||
int length, boolean includeUppercaseAlpha, boolean includeLowercaseAlpha, boolean includeNumeric,
|
||||
boolean includeSpecial) {
|
||||
return credHubOperations.credentials().generate(UserParametersRequest.builder()
|
||||
.name(new SimpleCredentialName(applicationId, serviceInstanceId, descriptor))
|
||||
.parameters(passwordParameters(length, includeUppercaseAlpha, includeLowercaseAlpha, includeNumeric,
|
||||
includeSpecial))
|
||||
.build()))
|
||||
.build(), UserCredential.class)
|
||||
.map(CredentialDetails::getValue)
|
||||
.cast(UserCredential.class)
|
||||
.map(userCredential -> Tuples.of(userCredential.getUsername(), userCredential.getPassword()));
|
||||
}
|
||||
|
||||
@@ -55,39 +54,31 @@ public class CredHubCredentialsGenerator implements CredentialGenerator {
|
||||
public Mono<String> generateString(String applicationId, String serviceInstanceId, String descriptor, int length,
|
||||
boolean includeUppercaseAlpha, boolean includeLowercaseAlpha, boolean includeNumeric,
|
||||
boolean includeSpecial) {
|
||||
return Mono.fromCallable(() -> credHubOperations.credentials().generate(PasswordParametersRequest.builder()
|
||||
.name(new SimpleCredentialName(applicationId, serviceInstanceId, descriptor))
|
||||
.parameters(passwordParameters(length, includeUppercaseAlpha, includeLowercaseAlpha, includeNumeric,
|
||||
includeSpecial))
|
||||
.build()))
|
||||
return credHubOperations.credentials()
|
||||
.generate(PasswordParametersRequest.builder()
|
||||
.name(new SimpleCredentialName(applicationId, serviceInstanceId, descriptor))
|
||||
.parameters(passwordParameters(length, includeUppercaseAlpha, includeLowercaseAlpha, includeNumeric,
|
||||
includeSpecial))
|
||||
.build(), PasswordCredential.class)
|
||||
.map(CredentialDetails::getValue)
|
||||
.cast(PasswordCredential.class)
|
||||
.map(PasswordCredential::getPassword);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> deleteUser(String applicationId, String serviceInstanceId, String descriptor) {
|
||||
return Mono.fromCallable(() -> {
|
||||
this.credHubOperations.credentials()
|
||||
.deleteByName(new SimpleCredentialName(applicationId, serviceInstanceId, descriptor));
|
||||
return null;
|
||||
});
|
||||
return credHubOperations.credentials()
|
||||
.deleteByName(new SimpleCredentialName(applicationId, serviceInstanceId, descriptor));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> deleteString(String applicationId, String serviceInstanceId, String descriptor) {
|
||||
return Mono.fromCallable(() -> {
|
||||
this.credHubOperations.credentials()
|
||||
.deleteByName(new SimpleCredentialName(applicationId, serviceInstanceId, descriptor));
|
||||
return null;
|
||||
});
|
||||
return credHubOperations.credentials()
|
||||
.deleteByName(new SimpleCredentialName(applicationId, serviceInstanceId, descriptor));
|
||||
}
|
||||
|
||||
private PasswordParameters passwordParameters(int length, boolean includeUppercaseAlpha,
|
||||
boolean includeLowercaseAlpha,
|
||||
boolean includeNumeric, boolean includeSpecial) {
|
||||
return PasswordParameters
|
||||
.builder()
|
||||
boolean includeLowercaseAlpha, boolean includeNumeric, boolean includeSpecial) {
|
||||
return PasswordParameters.builder()
|
||||
.length(length)
|
||||
.excludeUpper(!includeUppercaseAlpha)
|
||||
.excludeLower(!includeLowercaseAlpha)
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.cloud.servicebroker.model.binding.CreateServiceInstan
|
||||
import org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceAppBindingResponse.CreateServiceInstanceAppBindingResponseBuilder;
|
||||
import org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingRequest;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.credhub.core.CredHubOperations;
|
||||
import org.springframework.credhub.core.ReactiveCredHubOperations;
|
||||
import org.springframework.credhub.support.CredentialName;
|
||||
import org.springframework.credhub.support.json.JsonCredentialRequest;
|
||||
import org.springframework.credhub.support.permissions.Operation;
|
||||
@@ -43,9 +43,9 @@ public class CredHubPersistingCreateServiceInstanceAppBindingWorkflow extends Cr
|
||||
|
||||
private static final String CREDENTIAL_CLIENT_ID = "credential_client_id";
|
||||
|
||||
private final CredHubOperations credHubOperations;
|
||||
private final ReactiveCredHubOperations credHubOperations;
|
||||
|
||||
public CredHubPersistingCreateServiceInstanceAppBindingWorkflow(CredHubOperations credHubOperations,
|
||||
public CredHubPersistingCreateServiceInstanceAppBindingWorkflow(ReactiveCredHubOperations credHubOperations,
|
||||
String appName) {
|
||||
super(appName);
|
||||
this.credHubOperations = credHubOperations;
|
||||
@@ -73,8 +73,7 @@ public class CredHubPersistingCreateServiceInstanceAppBindingWorkflow extends Cr
|
||||
}
|
||||
|
||||
private Mono<CreateServiceInstanceAppBindingResponseBuilder> persistBindingCredentials(
|
||||
CreateServiceInstanceBindingRequest request,
|
||||
CreateServiceInstanceAppBindingResponse response,
|
||||
CreateServiceInstanceBindingRequest request, CreateServiceInstanceAppBindingResponse response,
|
||||
CredentialName credentialName) {
|
||||
return writeCredential(response, credentialName)
|
||||
.then(writePermissions(request, credentialName))
|
||||
@@ -83,44 +82,40 @@ public class CredHubPersistingCreateServiceInstanceAppBindingWorkflow extends Cr
|
||||
|
||||
private Mono<Void> writeCredential(CreateServiceInstanceAppBindingResponse response,
|
||||
CredentialName credentialName) {
|
||||
return Mono.fromCallable(() -> {
|
||||
credHubOperations.credentials()
|
||||
return credHubOperations.credentials()
|
||||
.write(JsonCredentialRequest.builder()
|
||||
.name(credentialName)
|
||||
.value(response.getCredentials())
|
||||
.build());
|
||||
return null;
|
||||
});
|
||||
.build())
|
||||
.then();
|
||||
}
|
||||
|
||||
private Mono<Void> writePermissions(CreateServiceInstanceBindingRequest request,
|
||||
CredentialName credentialName) {
|
||||
return Mono.fromCallable(() -> {
|
||||
BindResource bindResource = request.getBindResource();
|
||||
|
||||
BindResource bindResource = request.getBindResource();
|
||||
return Mono.defer(() -> {
|
||||
if (bindResource.getAppGuid() != null) {
|
||||
Permission permission = Permission.builder()
|
||||
.app(bindResource.getAppGuid())
|
||||
.operation(Operation.READ)
|
||||
.build();
|
||||
credHubOperations.permissionsV2().addPermissions(credentialName, permission);
|
||||
return credHubOperations.permissionsV2()
|
||||
.addPermissions(credentialName, Permission.builder()
|
||||
.app(bindResource.getAppGuid())
|
||||
.operation(Operation.READ)
|
||||
.build())
|
||||
.then();
|
||||
}
|
||||
|
||||
if (bindResource.getProperty(CREDENTIAL_CLIENT_ID) != null) {
|
||||
Permission permission = Permission.builder()
|
||||
.client(bindResource.getProperty(CREDENTIAL_CLIENT_ID).toString())
|
||||
.operation(Operation.READ)
|
||||
.build();
|
||||
credHubOperations.permissionsV2().addPermissions(credentialName, permission);
|
||||
return credHubOperations.permissionsV2()
|
||||
.addPermissions(credentialName, Permission.builder()
|
||||
.client(bindResource.getProperty(CREDENTIAL_CLIENT_ID).toString())
|
||||
.operation(Operation.READ)
|
||||
.build())
|
||||
.then();
|
||||
}
|
||||
|
||||
return null;
|
||||
return Mono.empty();
|
||||
});
|
||||
}
|
||||
|
||||
private CreateServiceInstanceAppBindingResponseBuilder buildReplacementBindingResponse(
|
||||
CreateServiceInstanceAppBindingResponse response,
|
||||
CredentialName credentialName) {
|
||||
CreateServiceInstanceAppBindingResponse response, CredentialName credentialName) {
|
||||
return CreateServiceInstanceAppBindingResponse.builder()
|
||||
.async(response.isAsync())
|
||||
.bindingExisted(response.isBindingExisted())
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.cloud.appbroker.service.DeleteServiceInstanceBindingW
|
||||
import org.springframework.cloud.servicebroker.model.binding.DeleteServiceInstanceBindingRequest;
|
||||
import org.springframework.cloud.servicebroker.model.binding.DeleteServiceInstanceBindingResponse.DeleteServiceInstanceBindingResponseBuilder;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.credhub.core.CredHubOperations;
|
||||
import org.springframework.credhub.core.ReactiveCredHubOperations;
|
||||
import org.springframework.credhub.support.CredentialName;
|
||||
|
||||
@Order(50)
|
||||
@@ -34,9 +34,9 @@ public class CredHubPersistingDeleteServiceInstanceBindingWorkflow
|
||||
|
||||
private static final Logger LOG = Loggers.getLogger(CredHubPersistingDeleteServiceInstanceBindingWorkflow.class);
|
||||
|
||||
private final CredHubOperations credHubOperations;
|
||||
private final ReactiveCredHubOperations credHubOperations;
|
||||
|
||||
public CredHubPersistingDeleteServiceInstanceBindingWorkflow(CredHubOperations credHubOperations, String appName) {
|
||||
public CredHubPersistingDeleteServiceInstanceBindingWorkflow(ReactiveCredHubOperations credHubOperations, String appName) {
|
||||
super(appName);
|
||||
this.credHubOperations = credHubOperations;
|
||||
}
|
||||
@@ -45,8 +45,9 @@ public class CredHubPersistingDeleteServiceInstanceBindingWorkflow
|
||||
public Mono<DeleteServiceInstanceBindingResponseBuilder> buildResponse(DeleteServiceInstanceBindingRequest request,
|
||||
DeleteServiceInstanceBindingResponseBuilder responseBuilder) {
|
||||
return buildCredentialName(request.getServiceDefinitionId(), request.getBindingId())
|
||||
.filter(this::credentialExists)
|
||||
.flatMap(credentialName -> deleteBindingCredentials(credentialName)
|
||||
.filterWhen(this::credentialExists)
|
||||
.flatMap(credentialName -> credHubOperations.credentials()
|
||||
.deleteByName(credentialName)
|
||||
.doOnRequest(
|
||||
l -> LOG.debug("Deleting binding credentials with name '{}' in CredHub", credentialName.getName()))
|
||||
.doOnSuccess(r -> LOG
|
||||
@@ -57,15 +58,11 @@ public class CredHubPersistingDeleteServiceInstanceBindingWorkflow
|
||||
.thenReturn(responseBuilder);
|
||||
}
|
||||
|
||||
private boolean credentialExists(CredentialName credentialName) {
|
||||
return !credHubOperations.credentials().findByName(credentialName).isEmpty();
|
||||
}
|
||||
|
||||
private Mono<Void> deleteBindingCredentials(CredentialName credentialName) {
|
||||
return Mono.fromCallable(() -> {
|
||||
credHubOperations.credentials().deleteByName(credentialName);
|
||||
return null;
|
||||
});
|
||||
private Mono<Boolean> credentialExists(CredentialName credentialName) {
|
||||
return credHubOperations.credentials()
|
||||
.findByName(credentialName)
|
||||
.collectList()
|
||||
.map(credentialSummaries -> !credentialSummaries.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,10 +21,11 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.credhub.core.CredHubOperations;
|
||||
import org.springframework.credhub.core.credential.CredHubCredentialOperations;
|
||||
import org.springframework.credhub.core.ReactiveCredHubOperations;
|
||||
import org.springframework.credhub.core.credential.ReactiveCredHubCredentialOperations;
|
||||
import org.springframework.credhub.support.CredentialDetails;
|
||||
import org.springframework.credhub.support.CredentialType;
|
||||
import org.springframework.credhub.support.SimpleCredentialName;
|
||||
@@ -35,6 +36,7 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
@@ -43,10 +45,10 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
class CredHubCredentialsGeneratorTest {
|
||||
|
||||
@Mock
|
||||
private CredHubOperations credHubOperations;
|
||||
private ReactiveCredHubOperations credHubOperations;
|
||||
|
||||
@Mock
|
||||
private CredHubCredentialOperations credHubCredentialOperations;
|
||||
private ReactiveCredHubCredentialOperations credHubCredentialOperations;
|
||||
|
||||
private CredHubCredentialsGenerator generator;
|
||||
|
||||
@@ -68,14 +70,15 @@ class CredHubCredentialsGeneratorTest {
|
||||
|
||||
@Test
|
||||
void generateUser() {
|
||||
|
||||
given(this.credHubOperations.credentials())
|
||||
.willReturn(credHubCredentialOperations);
|
||||
|
||||
given(this.credHubCredentialOperations.generate(any()))
|
||||
.willReturn(new CredentialDetails<>("id",
|
||||
new SimpleCredentialName("app-service"), CredentialType.PASSWORD,
|
||||
new UserCredential("username", "password")));
|
||||
CredentialDetails<UserCredential> creds = new CredentialDetails<>("id",
|
||||
new SimpleCredentialName("app-service"), CredentialType.PASSWORD,
|
||||
new UserCredential("username", "password"));
|
||||
|
||||
given(this.credHubCredentialOperations.generate(any(), eq(UserCredential.class)))
|
||||
.willReturn(Mono.just(creds));
|
||||
|
||||
StepVerifier.create(generator.generateUser("foo", "bar", "hello", 12, false, false, false, false))
|
||||
.assertNext(tuple2 -> {
|
||||
@@ -87,14 +90,15 @@ class CredHubCredentialsGeneratorTest {
|
||||
|
||||
@Test
|
||||
void generateString() {
|
||||
|
||||
given(this.credHubOperations.credentials())
|
||||
.willReturn(credHubCredentialOperations);
|
||||
|
||||
given(this.credHubCredentialOperations.generate(any()))
|
||||
.willReturn(new CredentialDetails<>("id",
|
||||
new SimpleCredentialName("app-service"), CredentialType.PASSWORD,
|
||||
new PasswordCredential("password")));
|
||||
CredentialDetails<PasswordCredential> creds = new CredentialDetails<>("id",
|
||||
new SimpleCredentialName("app-service"), CredentialType.PASSWORD,
|
||||
new PasswordCredential("password"));
|
||||
|
||||
given(this.credHubCredentialOperations.generate(any(), eq(PasswordCredential.class)))
|
||||
.willReturn(Mono.just(creds));
|
||||
|
||||
StepVerifier.create(generator.generateString("foo", "bar", "hello", 12, false, false, false, false))
|
||||
.assertNext(password -> assertThat(password).isEqualTo("password"))
|
||||
@@ -106,6 +110,9 @@ class CredHubCredentialsGeneratorTest {
|
||||
given(this.credHubOperations.credentials())
|
||||
.willReturn(credHubCredentialOperations);
|
||||
|
||||
given(this.credHubCredentialOperations.deleteByName(any()))
|
||||
.willReturn(Mono.empty());
|
||||
|
||||
StepVerifier.create(generator.deleteUser("foo", "bar", "hello"))
|
||||
.verifyComplete();
|
||||
|
||||
@@ -119,6 +126,9 @@ class CredHubCredentialsGeneratorTest {
|
||||
given(this.credHubOperations.credentials())
|
||||
.willReturn(credHubCredentialOperations);
|
||||
|
||||
given(this.credHubCredentialOperations.deleteByName(any()))
|
||||
.willReturn(Mono.empty());
|
||||
|
||||
StepVerifier.create(generator.deleteString("foo", "bar", "hello"))
|
||||
.verifyComplete();
|
||||
|
||||
|
||||
@@ -24,7 +24,9 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.cloud.servicebroker.model.binding.BindResource;
|
||||
@@ -32,11 +34,12 @@ import org.springframework.cloud.servicebroker.model.binding.CreateServiceInstan
|
||||
import org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceAppBindingResponse.CreateServiceInstanceAppBindingResponseBuilder;
|
||||
import org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingRequest;
|
||||
import org.springframework.cloud.servicebroker.model.binding.VolumeMount;
|
||||
import org.springframework.credhub.core.CredHubOperations;
|
||||
import org.springframework.credhub.core.credential.CredHubCredentialOperations;
|
||||
import org.springframework.credhub.core.permissionV2.CredHubPermissionV2Operations;
|
||||
import org.springframework.credhub.core.ReactiveCredHubOperations;
|
||||
import org.springframework.credhub.core.credential.ReactiveCredHubCredentialOperations;
|
||||
import org.springframework.credhub.core.permissionV2.ReactiveCredHubPermissionV2Operations;
|
||||
import org.springframework.credhub.support.CredentialDetails;
|
||||
import org.springframework.credhub.support.CredentialName;
|
||||
import org.springframework.credhub.support.CredentialPermission;
|
||||
import org.springframework.credhub.support.ServiceInstanceCredentialName;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -51,13 +54,13 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
class CredHubPersistingCreateServiceInstanceAppBindingWorkflowTest {
|
||||
|
||||
@Mock
|
||||
private CredHubOperations credHubOperations;
|
||||
private ReactiveCredHubOperations credHubOperations;
|
||||
|
||||
@Mock
|
||||
private CredHubCredentialOperations credHubCredentialOperations;
|
||||
private ReactiveCredHubCredentialOperations credHubCredentialOperations;
|
||||
|
||||
@Mock
|
||||
private CredHubPermissionV2Operations credHubPermissionOperations;
|
||||
private ReactiveCredHubPermissionV2Operations credHubPermissionOperations;
|
||||
|
||||
private CredHubPersistingCreateServiceInstanceAppBindingWorkflow workflow;
|
||||
|
||||
@@ -150,7 +153,10 @@ class CredHubPersistingCreateServiceInstanceAppBindingWorkflowTest {
|
||||
.willReturn(credHubPermissionOperations);
|
||||
|
||||
given(this.credHubCredentialOperations.write(any()))
|
||||
.willReturn(new CredentialDetails<>());
|
||||
.willReturn(Mono.just(new CredentialDetails<>()));
|
||||
|
||||
given(this.credHubPermissionOperations.addPermissions(any(), any()))
|
||||
.willReturn(Mono.just(Mockito.mock(CredentialPermission.class)));
|
||||
|
||||
StepVerifier
|
||||
.create(this.workflow.buildResponse(request, responseBuilder))
|
||||
@@ -166,8 +172,10 @@ class CredHubPersistingCreateServiceInstanceAppBindingWorkflowTest {
|
||||
})
|
||||
.verifyComplete();
|
||||
|
||||
verify(this.credHubCredentialOperations).write(any());
|
||||
verify(this.credHubPermissionOperations, times(2)).addPermissions(any(), any());
|
||||
verify(this.credHubCredentialOperations, times(1))
|
||||
.write(any());
|
||||
verify(this.credHubPermissionOperations, times(1))
|
||||
.addPermissions(any(), any());
|
||||
verifyNoMoreInteractions(this.credHubCredentialOperations);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,13 +23,15 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.cloud.servicebroker.model.binding.DeleteServiceInstanceBindingRequest;
|
||||
import org.springframework.cloud.servicebroker.model.binding.DeleteServiceInstanceBindingResponse;
|
||||
import org.springframework.cloud.servicebroker.model.binding.DeleteServiceInstanceBindingResponse.DeleteServiceInstanceBindingResponseBuilder;
|
||||
import org.springframework.credhub.core.CredHubOperations;
|
||||
import org.springframework.credhub.core.credential.CredHubCredentialOperations;
|
||||
import org.springframework.credhub.core.ReactiveCredHubOperations;
|
||||
import org.springframework.credhub.core.credential.ReactiveCredHubCredentialOperations;
|
||||
import org.springframework.credhub.support.CredentialName;
|
||||
import org.springframework.credhub.support.CredentialSummary;
|
||||
import org.springframework.credhub.support.ServiceInstanceCredentialName;
|
||||
@@ -37,6 +39,7 @@ import org.springframework.credhub.support.ServiceInstanceCredentialName;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
@@ -44,10 +47,10 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
class CredHubPersistingDeleteServiceInstanceBindingWorkflowTest {
|
||||
|
||||
@Mock
|
||||
private CredHubOperations credHubOperations;
|
||||
private ReactiveCredHubOperations credHubOperations;
|
||||
|
||||
@Mock
|
||||
private CredHubCredentialOperations credHubCredentialOperations;
|
||||
private ReactiveCredHubCredentialOperations credHubCredentialOperations;
|
||||
|
||||
private CredHubPersistingDeleteServiceInstanceBindingWorkflow workflow;
|
||||
|
||||
@@ -79,14 +82,18 @@ class CredHubPersistingDeleteServiceInstanceBindingWorkflowTest {
|
||||
.willReturn(credHubCredentialOperations);
|
||||
|
||||
given(this.credHubCredentialOperations.findByName(credentialName))
|
||||
.willReturn(Collections.singletonList(new CredentialSummary(credentialName)));
|
||||
.willReturn(Flux.fromIterable(Collections.singletonList(new CredentialSummary(credentialName))));
|
||||
|
||||
given(this.credHubCredentialOperations.deleteByName(any()))
|
||||
.willReturn(Mono.empty());
|
||||
|
||||
StepVerifier
|
||||
.create(this.workflow.buildResponse(request, responseBuilder))
|
||||
.expectNext(responseBuilder)
|
||||
.verifyComplete();
|
||||
|
||||
verify(this.credHubCredentialOperations).deleteByName(eq(credentialName));
|
||||
verify(this.credHubCredentialOperations, times(1))
|
||||
.deleteByName(eq(credentialName));
|
||||
verifyNoMoreInteractions(this.credHubCredentialOperations);
|
||||
}
|
||||
|
||||
@@ -106,7 +113,7 @@ class CredHubPersistingDeleteServiceInstanceBindingWorkflowTest {
|
||||
.willReturn(credHubCredentialOperations);
|
||||
|
||||
given(this.credHubCredentialOperations.findByName(any()))
|
||||
.willReturn(Collections.emptyList());
|
||||
.willReturn(Flux.fromIterable(Collections.emptyList()));
|
||||
|
||||
StepVerifier
|
||||
.create(this.workflow.buildResponse(request, responseBuilder))
|
||||
|
||||
Reference in New Issue
Block a user