use of com.venafi.vcert.sdk.connectors.cloud.domain.EdgeEncryptionKey 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);
}
Aggregations