use of org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateServiceTest method save_whenTransitionalIsFalse_delegatesToPermissionedCredentialService.
@Test
public void save_whenTransitionalIsFalse_delegatesToPermissionedCredentialService() throws Exception {
CertificateCredentialValue value = mock(CertificateCredentialValue.class);
when(value.isTransitional()).thenReturn(false);
BaseCredentialGenerateRequest generateRequest = mock(BaseCredentialGenerateRequest.class);
subject.save(mock(CredentialVersion.class), value, generateRequest, newArrayList());
Mockito.verify(generateRequest).setType(eq("certificate"));
Mockito.verify(permissionedCredentialService).save(any(), eq(value), eq(generateRequest), any());
}
use of org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateServiceTest method save_whenTransitionalIsTrue_andThereAreNoOtherTransitionalVersions_delegatesToPermissionedCredentialService.
@Test
public void save_whenTransitionalIsTrue_andThereAreNoOtherTransitionalVersions_delegatesToPermissionedCredentialService() throws Exception {
CertificateCredentialValue value = mock(CertificateCredentialValue.class);
when(value.isTransitional()).thenReturn(true);
BaseCredentialGenerateRequest generateRequest = mock(BaseCredentialGenerateRequest.class);
when(generateRequest.getName()).thenReturn("/some-name");
CertificateCredentialVersion previousVersion = mock(CertificateCredentialVersion.class);
when(previousVersion.isVersionTransitional()).thenReturn(false);
when(permissionedCredentialService.findAllByName(eq("/some-name"), any())).thenReturn(newArrayList(previousVersion));
subject.save(mock(CredentialVersion.class), value, generateRequest, newArrayList());
Mockito.verify(generateRequest).setType(eq("certificate"));
Mockito.verify(permissionedCredentialService).save(any(), eq(value), eq(generateRequest), any());
}
use of org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest in project credhub by cloudfoundry-incubator.
the class CertificatesHandler method handleRegenerate.
public CredentialView handleRegenerate(String credentialUuid, List<EventAuditRecordParameters> auditRecordParameters, CertificateRegenerateRequest request) {
CertificateCredentialVersion existingCredentialVersion = certificateService.findByCredentialUuid(credentialUuid, auditRecordParameters);
BaseCredentialGenerateRequest generateRequest = generationRequestGenerator.createGenerateRequest(existingCredentialVersion, existingCredentialVersion.getName(), auditRecordParameters);
CertificateCredentialValue credentialValue = (CertificateCredentialValue) credentialGenerator.generate(generateRequest);
credentialValue.setTransitional(request.isTransitional());
final CertificateCredentialVersion credentialVersion = (CertificateCredentialVersion) permissionedCertificateService.save(existingCredentialVersion, credentialValue, generateRequest, auditRecordParameters);
return new CertificateView(credentialVersion);
}
use of org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateServiceTest method save_whenTransitionalIsTrue_AndThereIsAnotherTransitionalVersion_throwsAnException.
@Test
public void save_whenTransitionalIsTrue_AndThereIsAnotherTransitionalVersion_throwsAnException() throws Exception {
CertificateCredentialValue value = mock(CertificateCredentialValue.class);
when(value.isTransitional()).thenReturn(true);
BaseCredentialGenerateRequest generateRequest = mock(BaseCredentialGenerateRequest.class);
when(generateRequest.getName()).thenReturn("/some-name");
CertificateCredentialVersion previousVersion = mock(CertificateCredentialVersion.class);
when(previousVersion.isVersionTransitional()).thenReturn(true);
when(permissionedCredentialService.findAllByName(eq("/some-name"), any())).thenReturn(newArrayList(previousVersion));
try {
subject.save(mock(CredentialVersion.class), value, generateRequest, newArrayList());
fail("should throw exception");
} catch (ParameterizedValidationException e) {
assertThat(e.getMessage(), equalTo("error.too_many_transitional_versions"));
}
}
use of org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest in project credhub by cloudfoundry-incubator.
the class LegacyGenerationHandler method handleGenerateRequest.
private CredentialView handleGenerateRequest(List<EventAuditRecordParameters> auditRecordParameters, String requestString) throws IOException {
BaseCredentialGenerateRequest requestBody = objectMapper.readValue(requestString, BaseCredentialGenerateRequest.class);
requestBody.validate();
return generateHandler.handle(requestBody, auditRecordParameters);
}
Aggregations