Skip to content

Commit

Permalink
fix: fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelson Ochoa committed Sep 19, 2022
1 parent a0528e3 commit fa055d7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public class CustomCaConfigurationTest {

private CertificateManager certificateManager;
private CertificateStore certificateStore;
private Topics topics;


@BeforeEach
Expand All @@ -111,12 +112,15 @@ void beforeEach() {
certificateStore, mockConnectivityInformation,
mockCertExpiryMonitor, mockShadowMonitor, Clock.systemUTC(), clientFactoryMock);

topics = Topics.of(new Context(), CLIENT_DEVICES_AUTH_SERVICE_NAME, null);
topics.getContext().put(SecurityService.class, securityServiceMock);
topics.getContext().put(CertificateStore.class, certificateStore);
}

/**
* Simulates an external party configuring their custom CA.
*/
private X509Certificate[] arrangeCustomCertificateAuthority() throws NoSuchAlgorithmException, CertificateException,
private X509Certificate[] setupCustomCertificateAuthority() throws NoSuchAlgorithmException, CertificateException,
OperatorCreationException, CertIOException, URISyntaxException, KeyLoadingException,
ServiceUnavailableException, CertificateChainLoadingException, InvalidConfigurationException {
// Generate custom certificates
Expand All @@ -132,7 +136,6 @@ private X509Certificate[] arrangeCustomCertificateAuthority() throws NoSuchAlgor
URI privateKeyUri = new URI("file:///private.key");
URI certificateUri = new URI("file:///certificate.pem");

Topics topics = Topics.of(new Context(), CLIENT_DEVICES_AUTH_SERVICE_NAME, null);
topics.lookup(CONFIGURATION_CONFIG_KEY, CERTIFICATE_AUTHORITY_TOPIC, CA_PRIVATE_KEY_URI)
.withValue(privateKeyUri.toString());
topics.lookup(CONFIGURATION_CONFIG_KEY, CERTIFICATE_AUTHORITY_TOPIC, CA_CERTIFICATE_URI)
Expand Down Expand Up @@ -187,7 +190,7 @@ void Given_CustomCAConfiguration_WHEN_issuingAClientCertificate_THEN_itsSignedBy
URISyntaxException, ServiceUnavailableException, OperatorCreationException, CertIOException,
InvalidConfigurationException, CertificateGenerationException, ExecutionException, InterruptedException,
TimeoutException {
X509Certificate[] caCertificates = arrangeCustomCertificateAuthority();
X509Certificate[] caCertificates = setupCustomCertificateAuthority();
X509Certificate[] clientCertificateChain = arrangeClientComponentCertificateChain();

assertTrue(CertificateTestHelpers.wasCertificateIssuedBy(caCertificates[0], clientCertificateChain[0]));
Expand All @@ -199,7 +202,7 @@ void GIVEN_CustomCAConfiguration_WHEN_whenGeneratingClientCerts_THEN_GGComponent
URISyntaxException, InvalidConfigurationException, KeyLoadingException, ServiceUnavailableException,
CertificateChainLoadingException, CertificateGenerationException, ExecutionException, InterruptedException,
TimeoutException {
this.arrangeCustomCertificateAuthority();
this.setupCustomCertificateAuthority();
X509Certificate[] clientCertificateChain = arrangeClientComponentCertificateChain();

DeviceAuthClient deviceAuth = new DeviceAuthClient(sessionManagerMock, groupManagerMock, certificateStore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public Result apply(CDAConfiguration configuration) {

try {
Pair<PrivateKey, X509Certificate[]> result = getCertificateChain(privateKeyUri, certificateUri);
certificateStore.setCaPrivateKey(result.getA());
certificateStore.setCaCertificateChain(result.getB());
certificateStore.setCaPrivateKey(result.getLeft());
certificateStore.setCaCertificateChain(result.getRight());
configuration.updateCACertificates(
Collections.singletonList(CertificateHelper.toPem(certificateStore.getCaCertificateChain())));
} catch (CertificateEncodingException | InvalidCertificateAuthorityException | KeyStoreException
Expand Down

0 comments on commit fa055d7

Please sign in to comment.