Search in sources :

Example 1 with BaseCredentialGenerateRequest

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());
}
Also used : BaseCredentialGenerateRequest(org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest) CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) Test(org.junit.Test)

Example 2 with BaseCredentialGenerateRequest

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());
}
Also used : BaseCredentialGenerateRequest(org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest) CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) Test(org.junit.Test)

Example 3 with BaseCredentialGenerateRequest

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);
}
Also used : BaseCredentialGenerateRequest(org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest) CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) CertificateView(org.cloudfoundry.credhub.view.CertificateView) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion)

Example 4 with BaseCredentialGenerateRequest

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"));
    }
}
Also used : BaseCredentialGenerateRequest(org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest) CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) ParameterizedValidationException(org.cloudfoundry.credhub.exceptions.ParameterizedValidationException) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) Test(org.junit.Test)

Example 5 with BaseCredentialGenerateRequest

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);
}
Also used : BaseCredentialGenerateRequest(org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest)

Aggregations

BaseCredentialGenerateRequest (org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest)7 CertificateCredentialValue (org.cloudfoundry.credhub.credential.CertificateCredentialValue)5 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)5 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)4 Test (org.junit.Test)4 CredentialValue (org.cloudfoundry.credhub.credential.CredentialValue)1 ParameterizedValidationException (org.cloudfoundry.credhub.exceptions.ParameterizedValidationException)1 CertificateRegenerateRequest (org.cloudfoundry.credhub.request.CertificateRegenerateRequest)1 CertificateView (org.cloudfoundry.credhub.view.CertificateView)1