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