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");
}
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);
}
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();
}
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));
}
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);
}
Aggregations