use of com.venafi.vcert.sdk.endpoint.Authentication in project vcert-java by Venafi.
the class CloudConnectorTest method retrieveCertificate.
@Test
void retrieveCertificate() throws VCertException, IOException {
Security.addProvider(new BouncyCastleProvider());
String apiKey = "12345678-1234-1234-1234-123456789012";
final Authentication auth = new Authentication(null, null, apiKey);
classUnderTest.authenticate(auth);
String body = readResourceAsString("certificates/certWithKey.pem");
PEMCollection pemCollection = PEMCollection.fromStringPEMCollection(body, ChainOption.ChainOptionIgnore, null, null);
CertificateRequest request = new CertificateRequest().subject(new CertificateRequest.PKIXName().commonName("random name").organization(singletonList("Venafi, Inc.")).organizationalUnit(singletonList("Automated Tests")));
request.pickupId("jackpot").keyType(KeyType.RSA).keyPair(new KeyPair(pemCollection.certificate().getPublicKey(), pemCollection.privateKey())).keyPassword(KEY_SECRET);
List<String> list = new ArrayList<String>();
list.add("jackpot");
CertificateStatus status = new CertificateStatus().status("ISSUED").certificateIds(list);
CertificateDetails certificateDetails = new CertificateDetails().dekHash("12345");
EdgeEncryptionKey edgeEncryptionKey = new EdgeEncryptionKey();
cloud.certificateDetails(eq("jackpot"), eq(apiKey));
when(cloud.certificateStatus(eq("jackpot"), eq(apiKey))).thenReturn(status);
when(cloud.retrieveCertificate(eq("jackpot"), eq(apiKey), eq("ROOT_FIRST"))).thenReturn(Response.builder().request(Request.create(Request.HttpMethod.GET, "http://localhost", new HashMap<String, Collection<String>>(), null, null)).status(200).body(body, Charset.forName("UTF-8")).build());
when(cloud.certificateDetails(eq("jackpot"), eq(apiKey))).thenReturn(certificateDetails);
when(cloud.retrieveEdgeEncryptionKey(eq("12345"), eq(apiKey))).thenReturn(edgeEncryptionKey);
PEMCollection pemCollection2 = classUnderTest.retrieveCertificate(request);
assertThat(pemCollection2).isNotNull();
assertThat(pemCollection2.certificate()).isNotNull();
assertThat(pemCollection2.privateKey()).isNotNull();
assertThat(pemCollection2.privateKeyPassword()).isEqualTo(KEY_SECRET);
}
use of com.venafi.vcert.sdk.endpoint.Authentication 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);
}
use of com.venafi.vcert.sdk.endpoint.Authentication in project vcert-java by Venafi.
the class CloudConnectorIT method setup.
@BeforeEach
void setup() throws VCertException {
serverMock.start();
Security.addProvider(new BouncyCastleProvider());
// todo
classUnderTest = new CloudConnector(Cloud.connect("http://localhost:" + serverMock.port()));
// String.format()
Authentication authentication = new Authentication(null, null, "12345678-1234-1234-1234-123456789012");
classUnderTest.authenticate(authentication);
}
use of com.venafi.vcert.sdk.endpoint.Authentication in project vcert-java by Venafi.
the class CloudConnectorTest method testExceptionValidatingPolicyCountriesWhenWildcards.
@Test
@DisplayName("Cloud - Testing Exception in Validation of Policy Countries with wildcard value")
public void testExceptionValidatingPolicyCountriesWhenWildcards() throws VCertException {
classUnderTest.authenticate(new Authentication(null, null, "12345678-1234-1234-1234-123456789012"));
PolicySpecification policySpecification = CloudTestUtils.getPolicySpecification();
// setting the Countries to a list of values which contains ".*" to validate that the related VCertException is thrown
policySpecification.policy().subject().countries(new String[] { PolicySpecificationConst.ALLOW_ALL, "Mexico" });
Exception exception = assertThrows(VCertException.class, () -> classUnderTest.setPolicy(CloudTestUtils.getRandomZone(), policySpecification));
assertEquals(CloudTestUtils.getVCertExceptionMessage(CloudPolicySpecificationValidator.ATTRIBUTE_HAS_MORE_THAN_ONE_VALUE_CONTAINING_ALLOW_ALL_STRING_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_POLICY_SUBJECT_COUNTRIES), exception.getMessage());
}
use of com.venafi.vcert.sdk.endpoint.Authentication 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);
}
Aggregations