Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VCertTknClient read zone configuration issue 115 #116

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/com/venafi/vcert/sdk/VCertTknClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.venafi.vcert.sdk.connectors.Connector;
import com.venafi.vcert.sdk.connectors.TokenConnector;
import com.venafi.vcert.sdk.connectors.tpp.TokenInfo;
import com.venafi.vcert.sdk.connectors.tpp.Tpp;
import com.venafi.vcert.sdk.connectors.tpp.TppToken;
import com.venafi.vcert.sdk.connectors.tpp.TppTokenConnector;
import com.venafi.vcert.sdk.endpoint.Authentication;

Expand All @@ -22,7 +22,7 @@ protected Connector createConnector(Config config) throws VCertException {
Connector connector;
switch (config.connectorType()) {
case TPP_TOKEN:{
connector = new TppTokenConnector(Tpp.connect(config));
connector = new TppTokenConnector(TppToken.connect(config));
break;
}
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public ZoneConfiguration readZoneConfiguration(String zone) throws VCertExceptio
Policy policy = serverPolicy.toPolicy();
ZoneConfiguration zoneConfig = serverPolicy.toZoneConfig();
zoneConfig.policy(policy);
zoneConfig.zoneId(zone);
zoneConfig.zoneId(getPolicyDN(zone));
return zoneConfig;
}

Expand Down
3 changes: 3 additions & 0 deletions src/test/java/com/venafi/vcert/sdk/VCertTknClientTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.venafi.vcert.sdk;

import com.venafi.vcert.sdk.Config;
import com.venafi.vcert.sdk.VCertException;
import com.venafi.vcert.sdk.VCertTknClient;
import com.venafi.vcert.sdk.certificate.CertificateRequest;
import com.venafi.vcert.sdk.certificate.ImportRequest;
import com.venafi.vcert.sdk.certificate.RenewalRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.venafi.vcert.sdk.certificate.SshCertificateRequest;
import com.venafi.vcert.sdk.certificate.SshConfig;
import com.venafi.vcert.sdk.endpoint.Authentication;
import com.venafi.vcert.sdk.utils.TppTestUtils;

class TppConnectorATForSSH {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.venafi.vcert.sdk.connectors.ZoneConfiguration;
import com.venafi.vcert.sdk.endpoint.Authentication;
import com.venafi.vcert.sdk.policy.domain.PolicySpecification;
import com.venafi.vcert.sdk.utils.TppTestUtils;

import feign.FeignException;
import feign.FeignException.BadRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.venafi.vcert.sdk.certificate.SshCertificateRequest;
import com.venafi.vcert.sdk.certificate.SshConfig;
import com.venafi.vcert.sdk.endpoint.Authentication;
import com.venafi.vcert.sdk.utils.TppTestUtils;

class TppTokenConnectorATForSSH {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.venafi.vcert.sdk.connectors.tpp.endpoint.ValidateIdentityRequest;
import com.venafi.vcert.sdk.connectors.tpp.endpoint.ValidateIdentityResponse;
import com.venafi.vcert.sdk.policy.domain.PolicySpecification;
import com.venafi.vcert.sdk.utils.TppTestUtils;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.venafi.vcert.sdk.policy.converter.tpp.TPPPolicySpecificationValidator;
import com.venafi.vcert.sdk.policy.domain.PolicySpecification;
import com.venafi.vcert.sdk.policy.domain.PolicySpecificationConst;
import com.venafi.vcert.sdk.utils.TppTestUtils;

import feign.FeignException;
import feign.Request;
import feign.Response;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.venafi.vcert.sdk.connectors.tpp;
package com.venafi.vcert.sdk.utils;

import java.time.Instant;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.venafi.vcert.sdk.vcertTknClient;

import static com.venafi.vcert.sdk.TestUtils.getTestIps;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.IOException;
import java.io.StringReader;
import java.net.InetAddress;
import java.util.Arrays;
import java.util.Collections;

import org.bouncycastle.openssl.PEMParser;
import org.bouncycastle.pkcs.PKCS10CertificationRequest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import com.venafi.vcert.sdk.TestUtils;
import com.venafi.vcert.sdk.VCertException;
import com.venafi.vcert.sdk.certificate.CertificateRequest;
import com.venafi.vcert.sdk.certificate.KeyType;
import com.venafi.vcert.sdk.connectors.ZoneConfiguration;

import feign.FeignException;

class VCertTknClientAT {

@RegisterExtension
public static final VCertTknClientResource clientResource = new VCertTknClientResource();

@Test
void readZoneConfiguration() throws VCertException {
try {
clientResource.client().readZoneConfiguration(TestUtils.TPP_ZONE);
} catch (FeignException fe) {
throw VCertException.fromFeignException(fe);
}
}

@Test
void readZoneConfigurationInLongFormat() throws VCertException {
try {
clientResource.client().readZoneConfiguration("\\VED\\Policy\\"+TestUtils.TPP_ZONE);
} catch (FeignException fe) {
throw VCertException.fromFeignException(fe);
}
}

@Test
void ping() throws VCertException {
assertThatCode(() -> clientResource.client().ping()).doesNotThrowAnyException();
}

@Test
void generateRequest() throws VCertException, IOException {
String commonName = TestUtils.randomCN();
ZoneConfiguration zoneConfiguration = clientResource.client().readZoneConfiguration(TestUtils.TPP_ZONE);
CertificateRequest certificateRequest = new CertificateRequest()
.subject(new CertificateRequest.PKIXName().commonName(commonName)
.organization(Collections.singletonList("Venafi, Inc."))
.organizationalUnit(Arrays.asList("Engineering", "Automated Tests"))
.country(Collections.singletonList("US")).locality(Collections.singletonList("SLC"))
.province(Collections.singletonList("Utah")))
.dnsNames(Collections.singletonList(InetAddress.getLocalHost().getHostName()))
.ipAddresses(getTestIps()).keyType(KeyType.RSA).keyLength(2048);

certificateRequest = clientResource.client().generateRequest(zoneConfiguration, certificateRequest);

assertThat(certificateRequest.csr()).isNotEmpty();

PKCS10CertificationRequest request = (PKCS10CertificationRequest) new PEMParser(
new StringReader(new String(certificateRequest.csr()))).readObject();

// Values overridden by policy which is why they don't match the above values
String subject = request.getSubject().toString();

assertThat(subject).contains(format("CN=%s", commonName));
}

@Test
void readPolicyConfiguration() {
assertThrows(UnsupportedOperationException.class,
() -> clientResource.client().readPolicyConfiguration("zone"));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
*
*/
package com.venafi.vcert.sdk;
package com.venafi.vcert.sdk.vcertTknClient;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
Expand All @@ -12,6 +12,10 @@

import org.junit.jupiter.api.Test;

import com.venafi.vcert.sdk.Config;
import com.venafi.vcert.sdk.TestUtils;
import com.venafi.vcert.sdk.VCertException;
import com.venafi.vcert.sdk.VCertTknClient;
import com.venafi.vcert.sdk.connectors.ConnectorException.MissingCredentialsException;
import com.venafi.vcert.sdk.connectors.tpp.TokenInfo;
import com.venafi.vcert.sdk.endpoint.Authentication;
Expand Down
Loading