Search in sources :

Example 21 with RenewalRequest

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

the class CloudConnectorTest method renewCertificateMultipleRequestIds.

@Test
@DisplayName("Renew a certificate with same fingerprint for multiple requests ids should fail")
void renewCertificateMultipleRequestIds() throws VCertException {
    final String apiKey = "12345678-1234-1234-1234-123456789012";
    final Authentication auth = new Authentication(null, null, apiKey);
    final String thumbprint = "52030990E3DC44199DA11C2D73E41EF8EAD8A4E1";
    final RenewalRequest renewalRequest = new RenewalRequest();
    final Cloud.CertificateSearchResponse searchResponse = mock(Cloud.CertificateSearchResponse.class);
    renewalRequest.thumbprint(thumbprint);
    when(cloud.searchCertificates(eq(apiKey), searchRequestArgumentCaptor.capture())).thenReturn(searchResponse);
    final Cloud.Certificate certificate1 = new Cloud.Certificate();
    certificate1.certificateRequestId("request_1");
    final Cloud.Certificate certificate2 = new Cloud.Certificate();
    certificate2.certificateRequestId("request_2");
    when(searchResponse.certificates()).thenReturn(Arrays.asList(certificate1, certificate2));
    classUnderTest.authenticate(auth);
    Throwable exception = assertThrows(VCertException.class, () -> classUnderTest.renewCertificate(renewalRequest));
    assertThat(exception.getMessage()).contains("More than one CertificateRequestId was found");
    assertThat(exception.getMessage()).contains(thumbprint);
}
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)

Example 22 with RenewalRequest

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

the class CloudConnectorTest method renewCertificateNotFound.

@Test
@DisplayName("Renew a certificate that do not exists in Cloud should fail")
void renewCertificateNotFound() throws VCertException {
    final String apiKey = "12345678-1234-1234-1234-123456789012";
    final Authentication auth = new Authentication(null, null, apiKey);
    final String thumbprint = "52030990E3DC44199DA11C2D73E41EF8EAD8A4E1";
    final RenewalRequest renewalRequest = new RenewalRequest();
    final Cloud.CertificateSearchResponse searchResponse = mock(Cloud.CertificateSearchResponse.class);
    renewalRequest.thumbprint(thumbprint);
    when(cloud.searchCertificates(eq(apiKey), searchRequestArgumentCaptor.capture())).thenReturn(searchResponse);
    classUnderTest.authenticate(auth);
    Throwable exception = assertThrows(VCertException.class, () -> classUnderTest.renewCertificate(renewalRequest));
    assertThat(exception.getMessage()).contains(thumbprint);
}
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)

Example 23 with RenewalRequest

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

the class VCertTknClientTest method renewCertificate.

@Test
@DisplayName("Renew certificate")
void renewCertificate() throws VCertException {
    final RenewalRequest renewalRequest = mock(RenewalRequest.class);
    classUnderTest.renewCertificate(renewalRequest);
    verify(connector).renewCertificate(renewalRequest);
}
Also used : 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