Search in sources :

Example 16 with RenewalRequest

use of com.venafi.vcert.sdk.certificate.RenewalRequest in project vcert-java by Venafi.

the class TppConnectorTest method renewCertificateWithDN.

@Test
@DisplayName("Renew Certificate with DN")
void renewCertificateWithDN() throws VCertException {
    final RenewalRequest renewalRequest = mock(RenewalRequest.class);
    final Tpp.CertificateRenewalResponse certificateRenewalResponse = mock(Tpp.CertificateRenewalResponse.class);
    when(renewalRequest.certificateDN()).thenReturn("certificateDN");
    when(tpp.renewCertificate(certificateRenewalRequestArgumentCaptor.capture(), any())).thenReturn(certificateRenewalResponse);
    when(certificateRenewalResponse.success()).thenReturn(true);
    String result = classUnderTest.renewCertificate(renewalRequest);
    assertThat(result).isEqualTo("certificateDN");
}
Also used : RenewalRequest(com.venafi.vcert.sdk.certificate.RenewalRequest) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 17 with RenewalRequest

use of com.venafi.vcert.sdk.certificate.RenewalRequest in project vcert-java by Venafi.

the class TppConnectorTest method renewCertificateWithFingeprintNoSearchResults.

@Test
@DisplayName("Renew Certificate with fingerprint not found")
void renewCertificateWithFingeprintNoSearchResults() throws VCertException {
    final RenewalRequest renewalRequest = mock(RenewalRequest.class);
    final Tpp.CertificateSearchResponse certificateSearchResponse = mock(Tpp.CertificateSearchResponse.class);
    when(renewalRequest.thumbprint()).thenReturn("1111:1111:1111:1111");
    when(tpp.searchCertificates(any(), eq(API_KEY))).thenReturn(certificateSearchResponse);
    final Throwable throwable = assertThrows(VCertException.class, () -> classUnderTest.renewCertificate(renewalRequest));
    assertThat(throwable instanceof CertificateNotFoundByThumbprintException);
}
Also used : CertificateNotFoundByThumbprintException(com.venafi.vcert.sdk.connectors.ConnectorException.CertificateNotFoundByThumbprintException) RenewalRequest(com.venafi.vcert.sdk.certificate.RenewalRequest) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 18 with RenewalRequest

use of com.venafi.vcert.sdk.certificate.RenewalRequest in project vcert-java by Venafi.

the class TppConnectorTest method renewCertificateWithFingerPrintMultipleCertificates.

@Test
@DisplayName("Renew Certificate multiple certificates for the fingerprint")
void renewCertificateWithFingerPrintMultipleCertificates() throws VCertException {
    final RenewalRequest renewalRequest = mock(RenewalRequest.class);
    final Tpp.CertificateSearchResponse certificateSearchResponse = mock(Tpp.CertificateSearchResponse.class);
    when(renewalRequest.thumbprint()).thenReturn("1111:1111:1111:1111");
    when(tpp.searchCertificates(any(), eq(API_KEY))).thenReturn(certificateSearchResponse);
    when(certificateSearchResponse.certificates()).thenReturn(Arrays.asList(new Tpp.Certificate(), new Tpp.Certificate()));
    final Throwable throwable = assertThrows(VCertException.class, () -> classUnderTest.renewCertificate(renewalRequest));
    // assertThat(throwable.getMessage()).contains("More than one certificate was found");
    assertThat(throwable instanceof MoreThanOneCertificateWithSameThumbprintException);
}
Also used : RenewalRequest(com.venafi.vcert.sdk.certificate.RenewalRequest) MoreThanOneCertificateWithSameThumbprintException(com.venafi.vcert.sdk.connectors.ConnectorException.MoreThanOneCertificateWithSameThumbprintException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 19 with RenewalRequest

use of com.venafi.vcert.sdk.certificate.RenewalRequest in project vcert-java by Venafi.

the class TppTokenConnectorCertAT method renewCertificate.

@Test
void renewCertificate() throws VCertException, UnknownHostException, SocketException, CertificateException, NoSuchAlgorithmException {
    TppTokenConnector connector = connectorResource.connector();
    ZoneConfiguration zoneConfiguration = connectorResource.zoneConfiguration();
    CertificateRequest certificateRequest = connector.generateRequest(zoneConfiguration, connectorResource.certificateRequest());
    String certificateId = connector.requestCertificate(certificateRequest, zoneConfiguration);
    assertThat(certificateId).isNotNull();
    PEMCollection pemCollection = connector.retrieveCertificate(certificateRequest);
    X509Certificate cert = (X509Certificate) pemCollection.certificate();
    String thumbprint = DigestUtils.sha1Hex(cert.getEncoded()).toUpperCase();
    CertificateRequest certificateRequestToRenew = new CertificateRequest().subject(certificateRequest.subject()).dnsNames(certificateRequest.dnsNames()).ipAddresses(certificateRequest.ipAddresses()).keyType(certificateRequest.keyType()).keyLength(certificateRequest.keyLength());
    connector.generateRequest(zoneConfiguration, certificateRequestToRenew);
    String renewRequestId = connector.renewCertificate(new RenewalRequest().request(certificateRequestToRenew).thumbprint(thumbprint));
    assertThat(renewRequestId).isNotNull();
}
Also used : PEMCollection(com.venafi.vcert.sdk.certificate.PEMCollection) RenewalRequest(com.venafi.vcert.sdk.certificate.RenewalRequest) ZoneConfiguration(com.venafi.vcert.sdk.connectors.ZoneConfiguration) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.jupiter.api.Test)

Example 20 with RenewalRequest

use of com.venafi.vcert.sdk.certificate.RenewalRequest in project vcert-java by Venafi.

the class CloudConnectorTest method renewCertificateEmptyRequest.

@Test
@DisplayName("Renew a certificate without request details in cloud should fail")
void renewCertificateEmptyRequest() throws VCertException {
    final String apiKey = "12345678-1234-1234-1234-123456789012";
    final Authentication auth = new Authentication(null, null, apiKey);
    final RenewalRequest renewalRequest = new RenewalRequest();
    final Cloud.CertificateSearchResponse searchResponse = mock(Cloud.CertificateSearchResponse.class);
    classUnderTest.authenticate(auth);
    Throwable exception = assertThrows(VCertException.class, () -> classUnderTest.renewCertificate(renewalRequest));
    assertThat(exception.getMessage()).contains("CertificateDN or Thumbprint required");
}
Also used : RenewalRequest(com.venafi.vcert.sdk.certificate.RenewalRequest) Authentication(com.venafi.vcert.sdk.endpoint.Authentication) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

RenewalRequest (com.venafi.vcert.sdk.certificate.RenewalRequest)23 Test (org.junit.jupiter.api.Test)21 DisplayName (org.junit.jupiter.api.DisplayName)18 CertificateRequest (com.venafi.vcert.sdk.certificate.CertificateRequest)6 Authentication (com.venafi.vcert.sdk.endpoint.Authentication)6 PEMCollection (com.venafi.vcert.sdk.certificate.PEMCollection)5 ZoneConfiguration (com.venafi.vcert.sdk.connectors.ZoneConfiguration)5 X509Certificate (java.security.cert.X509Certificate)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 CertificateNotFoundByThumbprintException (com.venafi.vcert.sdk.connectors.ConnectorException.CertificateNotFoundByThumbprintException)3 CertificateStatus (com.venafi.vcert.sdk.certificate.CertificateStatus)2 CertificateDNOrThumbprintWasNotProvidedException (com.venafi.vcert.sdk.connectors.ConnectorException.CertificateDNOrThumbprintWasNotProvidedException)2 MoreThanOneCertificateWithSameThumbprintException (com.venafi.vcert.sdk.connectors.ConnectorException.MoreThanOneCertificateWithSameThumbprintException)2 FeignException (feign.FeignException)2 CharStreams (com.google.common.io.CharStreams)1 SerializedName (com.google.gson.annotations.SerializedName)1 VCertException (com.venafi.vcert.sdk.VCertException)1 CsrOriginOption (com.venafi.vcert.sdk.certificate.CsrOriginOption)1 ImportRequest (com.venafi.vcert.sdk.certificate.ImportRequest)1 ImportResponse (com.venafi.vcert.sdk.certificate.ImportResponse)1