Skip to content

Commit

Permalink
NIFI-13874 Refactored KeyStore and SSLContext Creation for Tests
Browse files Browse the repository at this point in the history
- Added EphemeralKeyStoreBuilder to nifi-security-ssl
- Removed nifi-security-utils
- Moved StandardTlsConfiguration to nifi-ssl-context-service
- Refactored tests to use EphemeralKeyStoreBuilder and nifi-security-cert-builder for TLS
  • Loading branch information
exceptionfactory committed Oct 15, 2024
1 parent cc5a363 commit bb7fab6
Show file tree
Hide file tree
Showing 65 changed files with 1,546 additions and 2,121 deletions.
11 changes: 0 additions & 11 deletions minifi/minifi-bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ limitations under the License.
<artifactId>nifi-utils</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-security-ssl</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>c2-protocol-api</artifactId>
Expand Down Expand Up @@ -125,12 +120,6 @@ limitations under the License.
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-security-utils</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
Expand Down

This file was deleted.

5 changes: 0 additions & 5 deletions minifi/minifi-nar-bundles/minifi-framework-bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ limitations under the License.
<artifactId>nifi-framework-nar-loading-utils</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-security-utils</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-security-utils-api</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions nifi-code-coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,6 @@
<artifactId>nifi-security-ssl</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-security-utils</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-security-utils-api</artifactId>
Expand Down
6 changes: 0 additions & 6 deletions nifi-commons/nifi-hashicorp-vault/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@
<version>2.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-security-utils</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
*/
package org.apache.nifi.vault.hashicorp;

import org.apache.nifi.security.util.TemporaryKeyStoreBuilder;
import org.apache.nifi.security.util.TlsConfiguration;
import org.apache.nifi.vault.hashicorp.config.HashiCorpVaultProperties;
import org.apache.nifi.vault.hashicorp.config.HashiCorpVaultSslProperties;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -28,30 +25,24 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Collectors;

import static org.mockito.Mockito.when;

public class TestStandardHashiCorpVaultCommunicationService {
public static final String URI_VALUE = "http://127.0.0.1:8200";
public static final String CIPHER_SUITE_VALUE = "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384";

private HashiCorpVaultProperties properties;
private HashiCorpVaultSslProperties sslProperties;
private File authProps;

@BeforeEach
public void init() throws IOException {
authProps = TestHashiCorpVaultConfiguration.writeBasicVaultAuthProperties();

properties = Mockito.mock(HashiCorpVaultProperties.class);
sslProperties = Mockito.mock(HashiCorpVaultSslProperties.class);

when(properties.getUri()).thenReturn(URI_VALUE);
when(properties.getAuthPropertiesFilename()).thenReturn(authProps.getAbsolutePath());
when(properties.getSsl()).thenReturn(sslProperties);
when(properties.getKvVersion()).thenReturn(1);
}

Expand All @@ -73,18 +64,6 @@ public void testBasicConfiguration() {

// Once to check if the property is set, and once to retrieve the value
Mockito.verify(properties, Mockito.times(2)).getAuthPropertiesFilename();

// These should not be called because TLS is not configured
this.ensureTlsPropertiesAccessed(0);
}

private void ensureTlsPropertiesAccessed(int numberOfTimes) {
Mockito.verify(sslProperties, Mockito.times(numberOfTimes)).getKeyStore();
Mockito.verify(sslProperties, Mockito.times(numberOfTimes)).getKeyStoreType();
Mockito.verify(sslProperties, Mockito.times(numberOfTimes)).getKeyStorePassword();
Mockito.verify(sslProperties, Mockito.times(numberOfTimes)).getTrustStore();
Mockito.verify(sslProperties, Mockito.times(numberOfTimes)).getTrustStoreType();
Mockito.verify(sslProperties, Mockito.times(numberOfTimes)).getTrustStorePassword();
}

@Test
Expand All @@ -93,26 +72,4 @@ public void testTimeouts() {
when(properties.getReadTimeout()).thenReturn(Optional.of("40 secs"));
this.configureService();
}

@Test
public void testTLS() {
TlsConfiguration tlsConfiguration = new TemporaryKeyStoreBuilder().build();

when(sslProperties.getKeyStore()).thenReturn(tlsConfiguration.getKeystorePath());
when(sslProperties.getKeyStorePassword()).thenReturn(tlsConfiguration.getKeystorePassword());
when(sslProperties.getKeyStoreType()).thenReturn(tlsConfiguration.getKeystoreType().getType());
when(sslProperties.getTrustStore()).thenReturn(tlsConfiguration.getTruststorePath());
when(sslProperties.getTrustStorePassword()).thenReturn(tlsConfiguration.getTruststorePassword());
when(sslProperties.getTrustStoreType()).thenReturn(tlsConfiguration.getTruststoreType().getType());
when(sslProperties.getEnabledProtocols()).thenReturn(Arrays.stream(tlsConfiguration.getEnabledProtocols())
.collect(Collectors.joining(",")));
when(sslProperties.getEnabledCipherSuites()).thenReturn(CIPHER_SUITE_VALUE);

when(properties.getUri()).thenReturn(URI_VALUE.replace("http", "https"));
this.configureService();

this.ensureTlsPropertiesAccessed(2);
Mockito.verify(sslProperties, Mockito.times(1)).getEnabledProtocols();
Mockito.verify(sslProperties, Mockito.times(1)).getEnabledCipherSuites();
}
}
Loading

0 comments on commit bb7fab6

Please sign in to comment.