Search in sources :

Example 31 with Authentication

use of com.venafi.vcert.sdk.endpoint.Authentication in project vcert-java by Venafi.

the class TppTokenConnectorAT method authenticateInvalid.

@Test
@Tag("InvalidAuthentication")
@DisplayName("Authenticate with invalid credentials")
void authenticateInvalid() throws VCertException {
    Authentication authentication = Authentication.builder().user("sample").password("password").scope("certificate:manage,revoke,discover").build();
    connectorResource.connector().credentials(authentication);
    TokenInfo info = connectorResource.connector().getAccessToken();
    assertThat(info).isNotNull();
    assertThat(info.authorized()).isFalse();
    assertThat(info.errorMessage()).isNotNull();
// After setting invalid credentials to TPP, setting variable <info> to null
// will allow for new token to be authorized
// connectorResource.info(null);
}
Also used : Authentication(com.venafi.vcert.sdk.endpoint.Authentication) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName) Tag(org.junit.jupiter.api.Tag)

Example 32 with Authentication

use of com.venafi.vcert.sdk.endpoint.Authentication in project vcert-java by Venafi.

the class TppTokenConnectorAT method revokeTokenInvalid.

@Test
@Tag("InvalidAuthentication")
void revokeTokenInvalid() throws VCertException {
    Authentication invalidCredentials = Authentication.builder().accessToken("abcde==").refreshToken("1234-1234-12345-123").build();
    connectorResource.connector().credentials(invalidCredentials);
    assertThrows(VCertException.class, () -> connectorResource.connector().revokeAccessToken());
// After setting invalid credentials to TPP, setting variable <info> to null
// will allow for new token to be authorized
// connectorResource.info(null);
}
Also used : Authentication(com.venafi.vcert.sdk.endpoint.Authentication) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 33 with Authentication

use of com.venafi.vcert.sdk.endpoint.Authentication in project vcert-java by Venafi.

the class CloudConnectorTest method testExceptionValidatingPolicyCountriesWithNot2Characters.

@Test
@DisplayName("Cloud - Testing Exception in Validation of Policy Countries with not 2 char values")
public void testExceptionValidatingPolicyCountriesWithNot2Characters() 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 a string with more than
    // 2 chars to validate that the related VCertException is thrown
    policySpecification.policy().subject().countries(new String[] { "US", "Mexico" });
    Exception exception = assertThrows(VCertException.class, () -> classUnderTest.setPolicy(CloudTestUtils.getRandomZone(), policySpecification));
    assertEquals(CloudTestUtils.getVCertExceptionMessage(CloudPolicySpecificationValidator.ATTRIBUTE_HAS_NOT_A_TWO_CHAR_STRING_VALUE_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_POLICY_SUBJECT_COUNTRIES), exception.getMessage());
}
Also used : PolicySpecification(com.venafi.vcert.sdk.policy.domain.PolicySpecification) Authentication(com.venafi.vcert.sdk.endpoint.Authentication) VCertException(com.venafi.vcert.sdk.VCertException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 34 with Authentication

use of com.venafi.vcert.sdk.endpoint.Authentication in project vcert-java by Venafi.

the class CloudConnectorTest method testExceptionValidatingDefaultKeySize.

@Test
@DisplayName("Cloud - Testing Exception in Validation of Default KeySize with a not supported value")
public void testExceptionValidatingDefaultKeySize() throws VCertException {
    classUnderTest.authenticate(new Authentication(null, null, "12345678-1234-1234-1234-123456789012"));
    PolicySpecification policySpecification = CloudTestUtils.getPolicySpecification();
    // setting the default keysize to a value which is not supported to
    // validate that the related VCertException is thrown
    policySpecification.defaults().keyPair().rsaKeySize(3072);
    Exception exception = assertThrows(VCertException.class, () -> classUnderTest.setPolicy(CloudTestUtils.getRandomZone(), policySpecification));
    assertEquals(CloudTestUtils.getVCertExceptionMessage(CloudPolicySpecificationValidator.DEFAULT_ATTRIBUTE_DOESNT_MATCH_WITH_ACCEPTED_VALUES_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_DEFAULTS_KEYPAIR_RSA_KEY_SIZE), exception.getMessage());
}
Also used : PolicySpecification(com.venafi.vcert.sdk.policy.domain.PolicySpecification) Authentication(com.venafi.vcert.sdk.endpoint.Authentication) VCertException(com.venafi.vcert.sdk.VCertException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 35 with Authentication

use of com.venafi.vcert.sdk.endpoint.Authentication in project vcert-java by Venafi.

the class CloudConnectorTest method testExceptionValidatingSANUriAllowed.

@Test
@DisplayName("Cloud - Testing Exception in Validation of Policy SAN UriAllowed")
public void testExceptionValidatingSANUriAllowed() throws VCertException {
    classUnderTest.authenticate(new Authentication(null, null, "12345678-1234-1234-1234-123456789012"));
    PolicySpecification policySpecification = CloudTestUtils.getPolicySpecification();
    // setting the uriAllowed to true to validate that the related VCertException is thrown
    policySpecification.policy().subjectAltNames().uriAllowed(true);
    Exception exception = assertThrows(VCertException.class, () -> classUnderTest.setPolicy(CloudTestUtils.getRandomZone(), policySpecification));
    assertEquals(CloudTestUtils.getVCertExceptionMessage(CloudPolicySpecificationValidator.SUBJECT_ALT_NAME_ATTRIBUTE_DOESNT_SUPPORTED_EXCEPTION_MESSAGE, PolicySpecificationConst.ATT_POLICY_SUBJECT_ALT_NAMES_URI_ALLOWED), exception.getMessage());
}
Also used : PolicySpecification(com.venafi.vcert.sdk.policy.domain.PolicySpecification) Authentication(com.venafi.vcert.sdk.endpoint.Authentication) VCertException(com.venafi.vcert.sdk.VCertException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

Authentication (com.venafi.vcert.sdk.endpoint.Authentication)57 Test (org.junit.jupiter.api.Test)36 DisplayName (org.junit.jupiter.api.DisplayName)31 PolicySpecification (com.venafi.vcert.sdk.policy.domain.PolicySpecification)24 VCertException (com.venafi.vcert.sdk.VCertException)22 IOException (java.io.IOException)22 Config (com.venafi.vcert.sdk.Config)9 CertificateRequest (com.venafi.vcert.sdk.certificate.CertificateRequest)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 VCertTknClient (com.venafi.vcert.sdk.VCertTknClient)5 PEMCollection (com.venafi.vcert.sdk.certificate.PEMCollection)5 RenewalRequest (com.venafi.vcert.sdk.certificate.RenewalRequest)5 ZoneConfiguration (com.venafi.vcert.sdk.connectors.ZoneConfiguration)5 VCertClient (com.venafi.vcert.sdk.VCertClient)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Tag (org.junit.jupiter.api.Tag)3 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)2 CertificateStatus (com.venafi.vcert.sdk.certificate.CertificateStatus)2