use of org.cloudfoundry.credhub.credential.CertificateCredentialValue in project credhub by cloudfoundry-incubator.
the class CertificatesHandlerTest method handleRegenerate_passesOnTransitionalFlagWhenRegeneratingCertificate.
@Test
public void handleRegenerate_passesOnTransitionalFlagWhenRegeneratingCertificate() {
BaseCredentialGenerateRequest generateRequest = mock(BaseCredentialGenerateRequest.class);
CertificateCredentialVersion certificate = mock(CertificateCredentialVersion.class);
CertificateCredentialValue newValue = mock(CertificateCredentialValue.class);
when(certificate.getName()).thenReturn("test");
when(certificateService.findByCredentialUuid(eq(UUID_STRING), any())).thenReturn(certificate);
when(generationRequestGenerator.createGenerateRequest(eq(certificate), eq("test"), any())).thenReturn(generateRequest);
when(universalCredentialGenerator.generate(eq(generateRequest))).thenReturn(newValue);
when(permissionedCertificateService.save(eq(certificate), any(), any(), any())).thenReturn(mock(CertificateCredentialVersion.class));
CertificateRegenerateRequest regenerateRequest = new CertificateRegenerateRequest(true);
subject.handleRegenerate(UUID_STRING, Collections.emptyList(), regenerateRequest);
verify(newValue).setTransitional(true);
}
use of org.cloudfoundry.credhub.credential.CertificateCredentialValue in project credhub by cloudfoundry-incubator.
the class SetHandlerTest method handleSetRequest_withACertificateSetRequest_andNoCaName_usesCorrectParameters.
@Test
public void handleSetRequest_withACertificateSetRequest_andNoCaName_usesCorrectParameters() {
CertificateSetRequest setRequest = new CertificateSetRequest();
final CertificateCredentialValue certificateValue = new CertificateCredentialValue(null, "Picard", "Enterprise", null);
final ArrayList<EventAuditRecordParameters> eventAuditRecordParameters = new ArrayList<>();
setRequest.setType("certificate");
setRequest.setName("/captain");
setRequest.setAdditionalPermissions(accessControlEntries);
setRequest.setOverwrite(false);
setRequest.setCertificateValue(certificateValue);
subject.handle(setRequest, eventAuditRecordParameters);
verify(credentialService).save(null, certificateValue, setRequest, eventAuditRecordParameters);
verify(permissionService).savePermissions(credentialVersion, accessControlEntries, eventAuditRecordParameters, true, "/captain");
}
use of org.cloudfoundry.credhub.credential.CertificateCredentialValue in project credhub by cloudfoundry-incubator.
the class CredentialFactoryTest method makeCredentialFromRequest_givenCertificateType_andNoExisting_returnsCertificateCredential.
@Test
public void makeCredentialFromRequest_givenCertificateType_andNoExisting_returnsCertificateCredential() throws Exception {
CertificateCredentialValue certificateValue = new CertificateCredentialValue("ca-certificate", "certificate", PLAINTEXT_VALUE, "my-ca");
CertificateCredentialVersion credential = (CertificateCredentialVersion) subject.makeNewCredentialVersion(CredentialType.valueOf("certificate"), CREDENTIAL_NAME, certificateValue, null, null);
MatcherAssert.assertThat(credential.getCredential().getName(), equalTo(CREDENTIAL_NAME));
assertThat(credential.getCa(), equalTo("ca-certificate"));
assertThat(credential.getCertificate(), equalTo("certificate"));
assertThat(credential.getPrivateKey(), equalTo(PLAINTEXT_VALUE));
assertThat(credential.getCaName(), equalTo("/my-ca"));
}
use of org.cloudfoundry.credhub.credential.CertificateCredentialValue in project credhub by cloudfoundry-incubator.
the class CertificateGeneratorTest method whenCAExists_andItIsARootCA_aValidChildCertificateIsGeneratedWithTheProvidedKeyLength.
@Test
public void whenCAExists_andItIsARootCA_aValidChildCertificateIsGeneratedWithTheProvidedKeyLength() throws Exception {
final KeyPair childCertificateKeyPair = setupKeyPair();
setupMocksForRootCA(childCertificateKeyPair);
generationParameters.setKeyLength(4096);
CertificateGenerationParameters params = new CertificateGenerationParameters(generationParameters);
when(signedCertificateGenerator.getSignedByIssuer(childCertificateKeyPair, params, rootCaX509Certificate, rootCaKeyPair.getPrivate())).thenReturn(childX509Certificate);
CertificateCredentialValue certificate = subject.generateCredential(params);
assertThat(certificate, notNullValue());
verify(keyGenerator, times(1)).generateKeyPair(4096);
}
use of org.cloudfoundry.credhub.credential.CertificateCredentialValue in project credhub by cloudfoundry-incubator.
the class CertificateGeneratorTest method whenSelfSignIsTrue_itGeneratesAValidSelfSignedCertificate.
@Test
public void whenSelfSignIsTrue_itGeneratesAValidSelfSignedCertificate() throws Exception {
final X509Certificate certificate = new JcaX509CertificateConverter().setProvider(BouncyCastleProvider.PROVIDER_NAME).getCertificate(generateX509SelfSignedCert());
generationParameters.setCaName(null);
generationParameters.setSelfSigned(true);
inputParameters = new CertificateGenerationParameters(generationParameters);
when(keyGenerator.generateKeyPair(anyInt())).thenReturn(rootCaKeyPair);
when(signedCertificateGenerator.getSelfSigned(rootCaKeyPair, inputParameters)).thenReturn(certificate);
CertificateCredentialValue certificateCredential = subject.generateCredential(inputParameters);
assertThat(certificateCredential.getPrivateKey(), equalTo(CertificateFormatter.pemOf(rootCaKeyPair.getPrivate())));
assertThat(certificateCredential.getCertificate(), equalTo(CertificateFormatter.pemOf(certificate)));
assertThat(certificateCredential.getCa(), equalTo(CertificateFormatter.pemOf(certificate)));
verify(signedCertificateGenerator, times(1)).getSelfSigned(rootCaKeyPair, inputParameters);
}
Aggregations