Search in sources :

Example 1 with RenewalRequest

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

the class CloudConnectorTest method renewCertificate.

@Test
@DisplayName("Renew a certificate with fingerprint")
void renewCertificate() throws VCertException {
    final String apiKey = "12345678-1234-1234-1234-123456789012";
    final Authentication auth = new Authentication(null, null, apiKey);
    String requestId = "request_1";
    final String thumbprint = "52030990E3DC44199DA11C2D73E41EF8EAD8A4E1";
    final RenewalRequest renewalRequest = new RenewalRequest();
    CertificateRequest request = mock(CertificateRequest.class);
    renewalRequest.request(request);
    final Cloud.CertificateSearchResponse searchResponse = mock(Cloud.CertificateSearchResponse.class);
    final CertificateStatus certificateStatus = mock(CertificateStatus.class);
    renewalRequest.thumbprint(thumbprint);
    final Cloud.Certificate certificate1 = new Cloud.Certificate();
    certificate1.certificateRequestId(requestId);
    final CloudConnector.CertificateRequestsResponse requestsResponse = mock(CloudConnector.CertificateRequestsResponse.class);
    final CloudConnector.CertificateRequestsResponseData requestsResponseData = mock(CloudConnector.CertificateRequestsResponseData.class);
    // CertificateDetails certDetails = cloud.certificateDetails(certificateId, auth.apiKey());
    CertificateDetails certDetails = new CertificateDetails();
    certDetails.id("007");
    certDetails.certificateRequestId(requestId);
    List<String> list = new ArrayList<String>();
    list.add(requestId);
    when(cloud.certificateDetails(eq(requestId), eq(apiKey))).thenReturn(certDetails);
    when(cloud.searchCertificates(eq(apiKey), searchRequestArgumentCaptor.capture())).thenReturn(searchResponse);
    when(searchResponse.certificates()).thenReturn(singletonList(certificate1));
    when(cloud.certificateStatus(requestId, apiKey)).thenReturn(certificateStatus);
    when(certificateStatus.certificateIds()).thenReturn(list);
    when(cloud.certificateRequest(eq(apiKey), any(CloudConnector.CertificateRequestsPayload.class))).thenReturn(requestsResponse);
    when(requestsResponse.certificateRequests()).thenReturn(singletonList(requestsResponseData));
    when(requestsResponseData.id()).thenReturn("certificate_result");
    String fakeCSR = "fake csr";
    byte[] bytes = fakeCSR.getBytes();
    when(renewalRequest.request().csr()).thenReturn(bytes);
    classUnderTest.authenticate(auth);
    assertThat(classUnderTest.renewCertificate(renewalRequest)).isEqualTo("certificate_result");
}
Also used : CertificateStatus(com.venafi.vcert.sdk.certificate.CertificateStatus) CertificateDetails(com.venafi.vcert.sdk.connectors.cloud.domain.CertificateDetails) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RenewalRequest(com.venafi.vcert.sdk.certificate.RenewalRequest) Authentication(com.venafi.vcert.sdk.endpoint.Authentication) CertificateRequest(com.venafi.vcert.sdk.certificate.CertificateRequest) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with RenewalRequest

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

the class TppConnectorTest method renewCertificateWithEmptyRequest.

@Test
@DisplayName("Renew Certificate with an empty request")
void renewCertificateWithEmptyRequest() throws VCertException {
    final RenewalRequest renewalRequest = mock(RenewalRequest.class);
    final Throwable throwable = assertThrows(VCertException.class, () -> classUnderTest.renewCertificate(renewalRequest));
    assertThat(throwable instanceof CertificateDNOrThumbprintWasNotProvidedException);
}
Also used : RenewalRequest(com.venafi.vcert.sdk.certificate.RenewalRequest) CertificateDNOrThumbprintWasNotProvidedException(com.venafi.vcert.sdk.connectors.ConnectorException.CertificateDNOrThumbprintWasNotProvidedException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with RenewalRequest

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

the class CloudConnectorCertAT method renewCertificate.

@Test
void renewCertificate() throws VCertException, UnknownHostException, CertificateException {
    CloudConnector 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());
    connector.generateRequest(zoneConfiguration, certificateRequestToRenew);
    String renewRequestId = null;
    try {
        renewRequestId = connector.renewCertificate(new RenewalRequest().request(certificateRequestToRenew).thumbprint(thumbprint));
    } catch (CertificateNotFoundByThumbprintException e) {
        // wait for 5 sec, it's very probably that the Certificate is not ready at this point
        logger.warn("Failed to renewCertificate, because it's very probably that the Certificate is not ready yet. Waiting 5 sec to attempt one more time...");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e1) {
            e1.printStackTrace();
        }
        renewRequestId = connector.renewCertificate(new RenewalRequest().request(certificateRequestToRenew).thumbprint(thumbprint));
    }
    assertThat(renewRequestId).isNotNull();
}
Also used : PEMCollection(com.venafi.vcert.sdk.certificate.PEMCollection) CertificateNotFoundByThumbprintException(com.venafi.vcert.sdk.connectors.ConnectorException.CertificateNotFoundByThumbprintException) 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 4 with RenewalRequest

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

the class VCertTknClientTest method renewCertificateWithServerError.

@Test
@DisplayName("Renew certificate with server error")
void renewCertificateWithServerError() throws VCertException {
    final RenewalRequest renewalRequest = mock(RenewalRequest.class);
    doThrow(new FeignException.InternalServerError("Error", request, "".getBytes())).when(connector).renewCertificate(renewalRequest);
    assertThrows(VCertException.class, () -> classUnderTest.renewCertificate(renewalRequest));
}
Also used : RenewalRequest(com.venafi.vcert.sdk.certificate.RenewalRequest) FeignException(feign.FeignException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with RenewalRequest

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

the class TppTokenConnectorTest 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.searchCertificatesToken(any(), eq(HEADER_AUTHORIZATION))).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)

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