use of com.venafi.vcert.sdk.VCertException in project vcert-java by Venafi.
the class CloudConnectorTest method testExceptionValidatingPolicyOrgsWhenWildcards.
@Test
@DisplayName("Cloud - Testing Exception in Validation of Policy Orgs with wildcard value")
public void testExceptionValidatingPolicyOrgsWhenWildcards() throws VCertException {
classUnderTest.authenticate(new Authentication(null, null, "12345678-1234-1234-1234-123456789012"));
PolicySpecification policySpecification = CloudTestUtils.getPolicySpecification();
// setting the orgs to a list of values which contains ".*" to validate that the related VCertException is thrown
policySpecification.policy().subject().orgs(new String[] { PolicySpecificationConst.ALLOW_ALL, "org1" });
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_ORGS), exception.getMessage());
}
use of com.venafi.vcert.sdk.VCertException in project vcert-java by Venafi.
the class TppTokenConnectorTest method testExceptionValidatingDefaultLocality.
@Test
@DisplayName("TPP - Testing Exception in Validation of Defaults Locality not matching with the Policy Localities values")
public void testExceptionValidatingDefaultLocality() throws VCertException {
PolicySpecification policySpecification = TppTestUtils.getPolicySpecification();
// setting the Default Locality to a value which doesn't match with the values in the
// Policy Localities values to validate that the related VCertException is thrown
policySpecification.defaults().subject().locality("Mer");
Exception exception = assertThrows(VCertException.class, () -> classUnderTest.setPolicy(TppTestUtils.getRandomZone(), policySpecification));
Assertions.assertEquals(TppTestUtils.getVCertExceptionMessage(TPPPolicySpecificationValidator.DEFAULT_ATTRIBUTE_DOESNT_MATCH_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_DEFAULTS_SUBJECT_LOCALITY, PolicySpecificationConst.ATT_POLICY_SUBJECT_LOCALITIES), exception.getMessage());
}
use of com.venafi.vcert.sdk.VCertException in project vcert-java by Venafi.
the class TppTokenConnectorTest method testExceptionValidatingDefaultOrg.
@Test
@DisplayName("TPP - Testing Exception in Validation of Defaults Org not matching with the Policy Orgs values")
public void testExceptionValidatingDefaultOrg() throws VCertException {
PolicySpecification policySpecification = TppTestUtils.getPolicySpecification();
// setting the Default Org to a value which doesn't match with the values in the
// Policy Orgs values to validate that the related VCertException is thrown
policySpecification.defaults().subject().org("Ven");
Exception exception = assertThrows(VCertException.class, () -> classUnderTest.setPolicy(TppTestUtils.getRandomZone(), policySpecification));
Assertions.assertEquals(TppTestUtils.getVCertExceptionMessage(TPPPolicySpecificationValidator.DEFAULT_ATTRIBUTE_DOESNT_MATCH_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_DEFAULTS_SUBJECT_ORG, PolicySpecificationConst.ATT_POLICY_SUBJECT_ORGS), exception.getMessage());
}
use of com.venafi.vcert.sdk.VCertException in project vcert-java by Venafi.
the class CloudConnectorCertAT method privateKeyPKCSTest.
@Test
void privateKeyPKCSTest() throws VCertException, UnknownHostException, IOException {
CloudConnector connector = connectorResource.connector();
ZoneConfiguration zoneConfiguration = connectorResource.zoneConfiguration();
// By default the DataFormat of the CertificateRequest is PKCS8
CertificateRequest certificateRequest = connectorResource.certificateRequest().csrOrigin(CsrOriginOption.ServiceGeneratedCSR).keyPassword(TestUtils.KEY_PASSWORD);
certificateRequest = connector.generateRequest(zoneConfiguration, certificateRequest);
String pickupId = connector.requestCertificate(certificateRequest, zoneConfiguration);
assertThat(pickupId).isNotNull();
// Retrieving the PemCollection
PEMCollection pemCollectionRSAPrivateKeyPKCS8 = connector.retrieveCertificate(certificateRequest);
// getting the PrivateKey as PEM which should be a RSA Private Key in PKCS8 Encrypted
String privateKeyPKCS8AsEncryptedPem = pemCollectionRSAPrivateKeyPKCS8.pemPrivateKey();
PemObject privateKeyPKCS8AsPemObject = new PemReader(new StringReader(privateKeyPKCS8AsEncryptedPem)).readPemObject();
// evaluating that the private Key is in PKCS8 Encrypted
assertThat(pemCollectionRSAPrivateKeyPKCS8.privateKey()).isNotNull();
assertTrue(privateKeyPKCS8AsPemObject.getType().equals(TestUtils.PEM_HEADER_PKCS8_ENCRYPTED));
// changing to data format Legacy in order to get the PrivateKey in PKCS1
certificateRequest.dataFormat(DataFormat.LEGACY);
// Retrieving the PemCollection
PEMCollection pemCollectionRSAPrivateKey = connector.retrieveCertificate(certificateRequest);
// getting the PrivateKey as PEM which should be a RSA Private Key Encrypted
String privateKeyRSAAsEncryptedPem = pemCollectionRSAPrivateKey.pemPrivateKey();
PemObject privateKeyRSAAsPemObject = new PemReader(new StringReader(privateKeyRSAAsEncryptedPem)).readPemObject();
// evaluating that the private Key is in PKCS1 Encrypted
assertThat(pemCollectionRSAPrivateKey.privateKey()).isNotNull();
assertTrue(privateKeyRSAAsPemObject.getHeaders().stream().anyMatch(header -> TestUtils.PEM_RSA_PRIVATE_KEY_ENCRYPTED_HEADER_VALUE.equals(((PemHeader) header).getValue())));
}
use of com.venafi.vcert.sdk.VCertException in project vcert-java by Venafi.
the class CertificateRequestTest method checkCertificate.
// TODO rework
@ParameterizedTest
@MethodSource("provideCertificatedForCheckCertificate")
void checkCertificate(CertificateRequest certificateRequest, Certificate certificate, boolean isValid, String errorMessage) {
Security.addProvider(new BouncyCastleProvider());
boolean validCert;
try {
validCert = certificateRequest.checkCertificate(certificate);
if (!isValid && validCert) {
fail("certificate should failed but check returns that its valid");
}
assertThat(validCert).isTrue();
} catch (VCertException e) {
if (isValid) {
if (isNotBlank(errorMessage) && !e.getMessage().contains(errorMessage)) {
fail(format("unexpected error '%s' (should conatins %s)", e.getMessage(), errorMessage));
} else {
fail(format("cert should be valid but checker found error: %s", e.getMessage()));
}
}
}
}
Aggregations