You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by mt...@apache.org on 2022/03/17 18:09:27 UTC
[nifi] branch main updated: NIFI-9281 Enabled building on Java 17
This is an automated email from the ASF dual-hosted git repository.
mthomsen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new 412e21b NIFI-9281 Enabled building on Java 17
412e21b is described below
commit 412e21be977a6eb04cc247ceb3f9b178d6b19d97
Author: exceptionfactory <ex...@apache.org>
AuthorDate: Tue Mar 15 09:09:13 2022 -0500
NIFI-9281 Enabled building on Java 17
- Added Ubuntu Zulu JDK 17 GitHub build
- Adjusted MiNiFi C2 FileSystemConfigurationCache test to avoid using environment variables
- Adjusted MiNiFi StatusLogger and StatusLoggerTest to avoid overriding private logger
- Adjusted failure reason attribute check in TestGetIgniteCache
- Adjusted TestRangerAuthorizer and TestRangerNiFiAuthorizer to avoid checking nested exceptions
- Adjusted encrypt-config TestUtil to avoid unnecessary comparison of different types
- Disabled Javascript tests on Java 15 and higher
- Disabled several Hive 3 tests on Java 17 for StringInternUtils illegal access
- Refactored nifi-enrich-processors tests to use Mockito without Powermock
- Refactored nifi-toolkit-tls tests to avoid illegal reflective access
- Removed deprecated X509Certificate test in CertificateUtilsTest
- Removed kryo serialization from nifi-site-to-site-client test
- Updated TestHashContent to use SHA-1 instead of SHA for hash algorithm
- Upgraded maven-war-plugin from 2.5 to 3.3.2
- Upgraded nifi-graph-bundle dependencies from Groovy 2.5.14 to 3.0.8
- Upgraded QuestDB from 4.2.1 to 6.2.1 in nifi-framework-core
This closes #5870
Signed-off-by: Mike Thomsen <mt...@apache.org>
---
.github/workflows/ci-workflow.yml | 59 ++++++
.../bootstrap/status/reporters/StatusLogger.java | 2 +-
.../status/reporters/StatusLoggerTest.java | 53 +++--
.../filesystem/FileSystemConfigurationCache.java | 4 +-
.../FileSystemConfigurationCacheTest.java | 48 ++---
.../nifi/security/util/CertificateUtilsTest.groovy | 19 --
nifi-commons/nifi-site-to-site-client/pom.xml | 6 -
.../remote/client/socket/TestSiteToSiteClient.java | 74 +------
.../nifi-enrich-processors/pom.xml | 57 +-----
.../apache/nifi/processors/TestGeoEnrichIP.java | 32 +--
.../apache/nifi/processors/TestISPEnrichIP.java | 34 +---
.../nifi/processors/enrich/TestQueryWhois.java | 48 ++---
.../nifi-framework/nifi-framework-core/pom.xml | 4 +-
.../EmbeddedQuestDbStatusHistoryRepository.java | 3 +-
.../status/history/questdb/QuestDbContext.java | 9 +-
.../history/questdb/QuestDbDatabaseManager.java | 11 +-
.../history/questdb/QuestDbWritingTemplate.java | 2 +-
.../EmbeddedQuestDbRolloverHandlerTest.java | 11 +-
...DbStatusHistoryRepositoryForComponentsTest.java | 4 +-
...dQuestDbStatusHistoryRepositoryForNodeTest.java | 4 +-
.../test/resources/{qlog.conf => log-stdout.conf} | 0
.../nifi-framework/nifi-web/nifi-web-ui/pom.xml | 2 +-
.../nifi-graph-test-clients/pom.xml | 4 -
.../nifi-other-graph-services/pom.xml | 4 -
nifi-nar-bundles/nifi-graph-bundle/pom.xml | 24 +++
.../apache/hive/streaming/TestNiFiRecordSerDe.java | 3 +
.../processors/hive/TestPutHive3Streaming.java | 3 +
.../ignite/cache/TestGetIgniteCache.java | 5 +-
.../authorization/TestRangerNiFiAuthorizer.java | 39 +---
.../processors/script/TestExecuteJavascript.java | 3 +
.../processors/script/TestInvokeJavascript.java | 3 +
.../nifi/processors/standard/TestHashContent.java | 2 +-
.../nifi-registry-web-api/pom.xml | 11 +-
.../nifi-registry-web-ui/pom.xml | 2 +-
.../nifi/registry/ranger/TestRangerAuthorizer.java | 139 ++-----------
nifi-registry/pom.xml | 2 +-
.../nifi/toolkit/encryptconfig/TestUtil.groovy | 1 -
.../apache/nifi/toolkit/tls/util/TlsHelper.java | 13 +-
.../TlsToolkitStandaloneGroovyTest.groovy | 86 ++------
.../toolkit/tls/util/TlsHelperGroovyTest.groovy | 52 +----
.../TlsToolkitStandaloneCommandLineTest.java | 9 +-
.../nifi/toolkit/tls/util/PasswordUtilTest.java | 35 +---
.../nifi/toolkit/tls/util/TlsHelperTest.java | 216 +++++----------------
43 files changed, 318 insertions(+), 824 deletions(-)
diff --git a/.github/workflows/ci-workflow.yml b/.github/workflows/ci-workflow.yml
index 9d49ef8..107e406 100644
--- a/.github/workflows/ci-workflow.yml
+++ b/.github/workflows/ci-workflow.yml
@@ -51,6 +51,65 @@ concurrency:
cancel-in-progress: true
jobs:
+ ubuntu-build:
+ timeout-minutes: 120
+ runs-on: ubuntu-latest
+ name: Ubuntu Zulu JDK 17 EN
+ steps:
+ - name: System Information
+ run: |
+ hostname
+ cat /proc/cpuinfo
+ cat /proc/meminfo
+ df
+ - name: Checkout Code
+ uses: actions/checkout@v2
+ - name: Cache Maven Dependencies
+ uses: actions/cache@v2
+ with:
+ path: |
+ ~/.m2/repository
+ key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
+ restore-keys: |
+ ${{ runner.os }}-maven-
+ - name: Cache Node Modules
+ uses: actions/cache@v2
+ with:
+ path: |
+ ~/.npm
+ **/node_modules
+ key: ${{ runner.os }}-npm16-${{ hashFiles('**/package-lock.json') }}
+ restore-keys: |
+ ${{ runner.os }}-npm16-
+ - name: Set up Java 17
+ uses: actions/setup-java@v2
+ with:
+ distribution: 'zulu'
+ java-version: '17'
+ - name: Maven Build
+ env:
+ MAVEN_OPTS: >-
+ ${{ env.DEFAULT_MAVEN_OPTS }}
+ -Duser.language=en
+ -Duser.country=AU
+ -Duser.region=AU
+ -Duser.timezone=Australia/Melbourne
+ run: >
+ ${{ env.MAVEN_COMMAND }}
+ ${{ env.MAVEN_PROFILES }}
+ ${{ env.MAVEN_PROJECTS }}
+ - name: Upload Test Reports
+ uses: actions/upload-artifact@v2
+ with:
+ name: surefire-reports-ubuntu-17
+ path: |
+ ./**/target/surefire-reports/*.txt
+ ./**/target/surefire-reports/*.xml
+ retention-days: 3
+ if: failure()
+ - name: Post Disk Usage
+ run: df
+
ubuntu-build-en:
timeout-minutes: 120
runs-on: ubuntu-latest
diff --git a/minifi/minifi-bootstrap/src/main/java/org/apache/nifi/minifi/bootstrap/status/reporters/StatusLogger.java b/minifi/minifi-bootstrap/src/main/java/org/apache/nifi/minifi/bootstrap/status/reporters/StatusLogger.java
index da5b33e..5de8754 100644
--- a/minifi/minifi-bootstrap/src/main/java/org/apache/nifi/minifi/bootstrap/status/reporters/StatusLogger.java
+++ b/minifi/minifi-bootstrap/src/main/java/org/apache/nifi/minifi/bootstrap/status/reporters/StatusLogger.java
@@ -36,7 +36,7 @@ public class StatusLogger extends PeriodicStatusReporter {
private volatile LogLevel logLevel;
private volatile String statusQuery;
- private static final Logger logger = LoggerFactory.getLogger(StatusLogger.class);
+ protected static Logger logger = LoggerFactory.getLogger(StatusLogger.class);
public static final String LOGGER_STATUS_REPORTER_PROPERTY_PREFIX = STATUS_REPORTER_PROPERTY_PREFIX + ".log";
diff --git a/minifi/minifi-bootstrap/src/test/java/org/apache/nifi/minifi/bootstrap/status/reporters/StatusLoggerTest.java b/minifi/minifi-bootstrap/src/test/java/org/apache/nifi/minifi/bootstrap/status/reporters/StatusLoggerTest.java
index e184472..f47e2c2 100644
--- a/minifi/minifi-bootstrap/src/test/java/org/apache/nifi/minifi/bootstrap/status/reporters/StatusLoggerTest.java
+++ b/minifi/minifi-bootstrap/src/test/java/org/apache/nifi/minifi/bootstrap/status/reporters/StatusLoggerTest.java
@@ -20,14 +20,12 @@ package org.apache.nifi.minifi.bootstrap.status.reporters;
import org.apache.nifi.logging.LogLevel;
import org.apache.nifi.minifi.bootstrap.QueryableStatusAggregator;
import org.apache.nifi.minifi.commons.status.FlowStatusReport;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.slf4j.Logger;
import java.io.IOException;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
import java.util.Properties;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
@@ -37,6 +35,7 @@ import static org.apache.nifi.minifi.bootstrap.status.reporters.StatusLogger.ENC
import static org.apache.nifi.minifi.bootstrap.status.reporters.StatusLogger.LOGGING_LEVEL_KEY;
import static org.apache.nifi.minifi.bootstrap.status.reporters.StatusLogger.QUERY_KEY;
import static org.apache.nifi.minifi.bootstrap.status.reporters.StatusLogger.REPORT_PERIOD_KEY;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.verify;
public class StatusLoggerTest {
@@ -52,57 +51,51 @@ public class StatusLoggerTest {
private QueryableStatusAggregator queryableStatusAggregator;
private FlowStatusReport flowStatusReport;
- @Before
- public void init() throws IOException, NoSuchFieldException, IllegalAccessException {
+ @BeforeEach
+ public void init() throws IOException {
statusLogger = Mockito.spy(new StatusLogger());
logger = Mockito.mock(Logger.class);
+ StatusLogger.logger = logger;
+
queryableStatusAggregator = Mockito.mock(QueryableStatusAggregator.class);
flowStatusReport = Mockito.mock(FlowStatusReport.class);
Mockito.when(flowStatusReport.toString()).thenReturn(MOCK_STATUS);
- Field field = StatusLogger.class.getDeclaredField("logger");
- field.setAccessible(true);
- Field modifiersField = Field.class.getDeclaredField("modifiers");
- modifiersField.setAccessible(true);
- modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
- field.set(null, logger);
-
-
Mockito.when(queryableStatusAggregator.statusReport(MOCK_QUERY)).thenReturn(flowStatusReport);
}
- @Test(expected = IllegalStateException.class)
+ @Test
public void testFailedInitDueToFatalLogLevel() {
Properties properties = new Properties();
properties.setProperty(REPORT_PERIOD_KEY, "1");
properties.setProperty(LOGGING_LEVEL_KEY, LogLevel.FATAL.name());
properties.setProperty(QUERY_KEY, MOCK_QUERY);
- statusLogger.initialize(properties, queryableStatusAggregator);
+ assertThrows(IllegalStateException.class, () -> statusLogger.initialize(properties, queryableStatusAggregator));
}
- @Test(expected = IllegalStateException.class)
+ @Test
public void testFailedInitDueToNoPeriod() {
Properties properties = new Properties();
properties.setProperty(LOGGING_LEVEL_KEY, LogLevel.INFO.name());
properties.setProperty(QUERY_KEY, MOCK_QUERY);
- statusLogger.initialize(properties, queryableStatusAggregator);
+ assertThrows(IllegalStateException.class, () -> statusLogger.initialize(properties, queryableStatusAggregator));
}
- @Test(expected = IllegalStateException.class)
+ @Test
public void testFailedInitDueToNoQuery() {
Properties properties = new Properties();
properties.setProperty(REPORT_PERIOD_KEY, "1");
properties.setProperty(LOGGING_LEVEL_KEY, LogLevel.INFO.name());
- statusLogger.initialize(properties, queryableStatusAggregator);
+ assertThrows(IllegalStateException.class, () -> statusLogger.initialize(properties, queryableStatusAggregator));
}
@Test
- public void TestTrace() {
+ public void testTrace() {
statusLogger.initialize(getProperties(LogLevel.TRACE), queryableStatusAggregator);
statusLogger.setScheduledExecutorService(new RunOnceScheduledExecutorService(1));
statusLogger.start();
@@ -111,7 +104,7 @@ public class StatusLoggerTest {
}
@Test
- public void TestDebug() {
+ public void testDebug() {
statusLogger.initialize(getProperties(LogLevel.DEBUG), queryableStatusAggregator);
statusLogger.setScheduledExecutorService(new RunOnceScheduledExecutorService(1));
statusLogger.start();
@@ -120,7 +113,7 @@ public class StatusLoggerTest {
}
@Test
- public void TestInfo() {
+ public void testInfo() {
statusLogger.initialize(getProperties(LogLevel.INFO), queryableStatusAggregator);
statusLogger.setScheduledExecutorService(new RunOnceScheduledExecutorService(1));
statusLogger.start();
@@ -129,7 +122,7 @@ public class StatusLoggerTest {
}
@Test
- public void TestWarn() {
+ public void testWarn() {
statusLogger.initialize(getProperties(LogLevel.WARN), queryableStatusAggregator);
statusLogger.setScheduledExecutorService(new RunOnceScheduledExecutorService(1));
statusLogger.start();
@@ -138,7 +131,7 @@ public class StatusLoggerTest {
}
@Test
- public void TestError() {
+ public void testError() {
statusLogger.initialize(getProperties(LogLevel.ERROR), queryableStatusAggregator);
statusLogger.setScheduledExecutorService(new RunOnceScheduledExecutorService(1));
statusLogger.start();
@@ -148,7 +141,7 @@ public class StatusLoggerTest {
// Exception testing
@Test
- public void TestTraceException() throws IOException {
+ public void testTraceException() throws IOException {
Properties properties = new Properties();
properties.setProperty(REPORT_PERIOD_KEY, "1");
properties.setProperty(LOGGING_LEVEL_KEY, LogLevel.TRACE.name());
@@ -165,7 +158,7 @@ public class StatusLoggerTest {
}
@Test
- public void TestDebugException() throws IOException {
+ public void testDebugException() throws IOException {
IOException ioException = new IOException("This is an expected test exception");
Mockito.when(queryableStatusAggregator.statusReport(MOCK_QUERY)).thenThrow(ioException);
@@ -177,7 +170,7 @@ public class StatusLoggerTest {
}
@Test
- public void TestInfoException() throws IOException {
+ public void testInfoException() throws IOException {
IOException ioException = new IOException("This is an expected test exception");
Mockito.when(queryableStatusAggregator.statusReport(MOCK_QUERY)).thenThrow(ioException);
@@ -189,7 +182,7 @@ public class StatusLoggerTest {
}
@Test
- public void TestWarnException() throws IOException {
+ public void testWarnException() throws IOException {
IOException ioException = new IOException("This is an expected test exception");
Mockito.when(queryableStatusAggregator.statusReport(MOCK_QUERY)).thenThrow(ioException);
@@ -201,7 +194,7 @@ public class StatusLoggerTest {
}
@Test
- public void TestErrorException() throws IOException {
+ public void testErrorException() throws IOException {
IOException ioException = new IOException("This is an expected test exception");
Mockito.when(queryableStatusAggregator.statusReport(MOCK_QUERY)).thenThrow(ioException);
diff --git a/minifi/minifi-c2/minifi-c2-cache/minifi-c2-cache-filesystem/src/main/java/org/apache/nifi/minifi/c2/cache/filesystem/FileSystemConfigurationCache.java b/minifi/minifi-c2/minifi-c2-cache/minifi-c2-cache-filesystem/src/main/java/org/apache/nifi/minifi/c2/cache/filesystem/FileSystemConfigurationCache.java
index b6b9cb7..704dea9 100644
--- a/minifi/minifi-c2/minifi-c2-cache/minifi-c2-cache-filesystem/src/main/java/org/apache/nifi/minifi/c2/cache/filesystem/FileSystemConfigurationCache.java
+++ b/minifi/minifi-c2/minifi-c2-cache/minifi-c2-cache-filesystem/src/main/java/org/apache/nifi/minifi/c2/cache/filesystem/FileSystemConfigurationCache.java
@@ -52,7 +52,9 @@ public class FileSystemConfigurationCache implements ConfigurationCache {
* @throws IOException Thrown if the path cannot be created.
*/
public FileSystemConfigurationCache(String pathRoot, String pathPattern) throws IOException {
- this.pathRoot = Paths.get(System.getenv("C2_SERVER_HOME")).resolve(pathRoot).toAbsolutePath();
+ final String serverHome = System.getenv("C2_SERVER_HOME");
+ final String homePath = serverHome == null ? "." : serverHome;
+ this.pathRoot = Paths.get(homePath).resolve(pathRoot).toAbsolutePath();
Files.createDirectories(this.pathRoot);
this.pathPattern = pathPattern;
}
diff --git a/minifi/minifi-c2/minifi-c2-cache/minifi-c2-cache-filesystem/src/test/java/org/apache/nifi/minfi/c2/cache/filesystem/FileSystemConfigurationCacheTest.java b/minifi/minifi-c2/minifi-c2-cache/minifi-c2-cache-filesystem/src/test/java/org/apache/nifi/minfi/c2/cache/filesystem/FileSystemConfigurationCacheTest.java
index 82948b5..e773c49 100644
--- a/minifi/minifi-c2/minifi-c2-cache/minifi-c2-cache-filesystem/src/test/java/org/apache/nifi/minfi/c2/cache/filesystem/FileSystemConfigurationCacheTest.java
+++ b/minifi/minifi-c2/minifi-c2-cache/minifi-c2-cache-filesystem/src/test/java/org/apache/nifi/minfi/c2/cache/filesystem/FileSystemConfigurationCacheTest.java
@@ -17,11 +17,11 @@
package org.apache.nifi.minfi.c2.cache.filesystem;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
@@ -33,29 +33,16 @@ import org.apache.nifi.minifi.c2.api.InvalidParameterException;
import org.apache.nifi.minifi.c2.api.cache.ConfigurationCacheFileInfo;
import org.apache.nifi.minifi.c2.api.cache.WriteableConfiguration;
import org.apache.nifi.minifi.c2.cache.filesystem.FileSystemConfigurationCache;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.contrib.java.lang.system.EnvironmentVariables;
+import org.junit.jupiter.api.Test;
public class FileSystemConfigurationCacheTest {
-
- @Rule
- public final EnvironmentVariables environmentVariables = new EnvironmentVariables();
-
- @Before
- public void before() {
- File resourcesDirectory = new File("src/test/resources/");
- environmentVariables.set("C2_SERVER_HOME", resourcesDirectory.getAbsolutePath());
- }
+ private static final String PATH_ROOT = "src/test/resources/files";
@Test
public void getConfigurationTest() throws IOException, ConfigurationProviderException {
-
- final String pathRoot = "files";
final String pathPattern = "config";
- FileSystemConfigurationCache cache = new FileSystemConfigurationCache(pathRoot, pathPattern);
+ FileSystemConfigurationCache cache = new FileSystemConfigurationCache(PATH_ROOT, pathPattern);
Map<String, List<String>> parameters = new HashMap<>();
@@ -66,16 +53,13 @@ public class FileSystemConfigurationCacheTest {
assertEquals("config.text.yaml.v1", configuration.getName());
assertEquals("1", configuration.getVersion());
assertTrue(configuration.exists());
-
}
@Test
public void getNonexistantConfigurationTest() throws IOException, ConfigurationProviderException {
-
- final String pathRoot = "files";
final String pathPattern = "config";
- FileSystemConfigurationCache cache = new FileSystemConfigurationCache(pathRoot, pathPattern);
+ FileSystemConfigurationCache cache = new FileSystemConfigurationCache(PATH_ROOT, pathPattern);
Map<String, List<String>> parameters = new HashMap<>();
@@ -86,16 +70,13 @@ public class FileSystemConfigurationCacheTest {
assertEquals("config.test.contenttype.v1", configuration.getName());
assertEquals("1", configuration.getVersion());
assertFalse(configuration.exists());
-
}
@Test
public void getCachedConfigurationsTest() throws IOException, ConfigurationProviderException {
-
- final String pathRoot = "files";
final String pathPattern = "config";
- FileSystemConfigurationCache cache = new FileSystemConfigurationCache(pathRoot, pathPattern);
+ FileSystemConfigurationCache cache = new FileSystemConfigurationCache(PATH_ROOT, pathPattern);
Map<String, List<String>> parameters = new HashMap<>();
@@ -104,13 +85,10 @@ public class FileSystemConfigurationCacheTest {
Stream<WriteableConfiguration> configs = info.getCachedConfigurations();
assertEquals(1, configs.count());
-
}
- @Test(expected = InvalidParameterException.class)
- public void getConfigurationInvalidParametersTest() throws IOException,
- InvalidParameterException {
-
+ @Test
+ public void getConfigurationInvalidParametersTest() throws IOException {
final String pathRoot = "files";
final String pathPattern = "${test}/config";
@@ -118,8 +96,6 @@ public class FileSystemConfigurationCacheTest {
Map<String, List<String>> parameters = new HashMap<>();
- cache.getCacheFileInfo("test/contenttype", parameters);
-
+ assertThrows(InvalidParameterException.class, () -> cache.getCacheFileInfo("test/contenttype", parameters));
}
-
}
diff --git a/nifi-commons/nifi-security-utils/src/test/groovy/org/apache/nifi/security/util/CertificateUtilsTest.groovy b/nifi-commons/nifi-security-utils/src/test/groovy/org/apache/nifi/security/util/CertificateUtilsTest.groovy
index 786e140..37263a5 100644
--- a/nifi-commons/nifi-security-utils/src/test/groovy/org/apache/nifi/security/util/CertificateUtilsTest.groovy
+++ b/nifi-commons/nifi-security-utils/src/test/groovy/org/apache/nifi/security/util/CertificateUtilsTest.groovy
@@ -129,25 +129,6 @@ class CertificateUtilsTest extends GroovyTestCase {
}
@Test
- void testShouldConvertLegacyX509Certificate() {
- // Arrange
- final X509Certificate EXPECTED_NEW_CERTIFICATE = generateCertificate(SUBJECT_DN)
- logger.info("Expected certificate: ${EXPECTED_NEW_CERTIFICATE.class.canonicalName} ${EXPECTED_NEW_CERTIFICATE.subjectDN.toString()} (${EXPECTED_NEW_CERTIFICATE.getSerialNumber()})")
-
- // Form the legacy certificate
- final javax.security.cert.X509Certificate LEGACY_CERTIFICATE = generateLegacyCertificate(EXPECTED_NEW_CERTIFICATE)
- logger.info("Legacy certificate: ${LEGACY_CERTIFICATE.class.canonicalName} ${LEGACY_CERTIFICATE.subjectDN.toString()} (${LEGACY_CERTIFICATE.getSerialNumber()})")
-
- // Act
- X509Certificate convertedCertificate = CertificateUtils.convertLegacyX509Certificate(LEGACY_CERTIFICATE)
- logger.info("Converted certificate: ${convertedCertificate.class.canonicalName} ${convertedCertificate.subjectDN.toString()} (${convertedCertificate.getSerialNumber()})")
-
- // Assert
- assert convertedCertificate instanceof X509Certificate
- assert convertedCertificate == EXPECTED_NEW_CERTIFICATE
- }
-
- @Test
void testShouldConvertAbstractX509Certificate() {
// Arrange
final X509Certificate EXPECTED_NEW_CERTIFICATE = generateCertificate(SUBJECT_DN)
diff --git a/nifi-commons/nifi-site-to-site-client/pom.xml b/nifi-commons/nifi-site-to-site-client/pom.xml
index 582026d..c56775d 100644
--- a/nifi-commons/nifi-site-to-site-client/pom.xml
+++ b/nifi-commons/nifi-site-to-site-client/pom.xml
@@ -96,12 +96,6 @@
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
<dependency>
- <groupId>com.esotericsoftware.kryo</groupId>
- <artifactId>kryo</artifactId>
- <version>2.24.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
diff --git a/nifi-commons/nifi-site-to-site-client/src/test/java/org/apache/nifi/remote/client/socket/TestSiteToSiteClient.java b/nifi-commons/nifi-site-to-site-client/src/test/java/org/apache/nifi/remote/client/socket/TestSiteToSiteClient.java
index 65d3f36..ef222b0 100644
--- a/nifi-commons/nifi-site-to-site-client/src/test/java/org/apache/nifi/remote/client/socket/TestSiteToSiteClient.java
+++ b/nifi-commons/nifi-site-to-site-client/src/test/java/org/apache/nifi/remote/client/socket/TestSiteToSiteClient.java
@@ -16,89 +16,18 @@
*/
package org.apache.nifi.remote.client.socket;
-import com.esotericsoftware.kryo.Kryo;
-import com.esotericsoftware.kryo.io.Input;
-import com.esotericsoftware.kryo.io.Output;
-import org.apache.nifi.components.state.StateManager;
import org.apache.nifi.remote.client.SiteToSiteClient;
import org.apache.nifi.remote.client.SiteToSiteClientConfig;
import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.util.LinkedHashSet;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
public class TestSiteToSiteClient {
- @Test
- public void testSerialization() {
- final SiteToSiteClientConfig clientConfig = new SiteToSiteClient.Builder()
- .url("http://localhost:8080/nifi")
- .portName("input")
- .buildConfig();
-
- final Kryo kryo = new Kryo();
-
- final ByteArrayOutputStream out = new ByteArrayOutputStream();
- final Output output = new Output(out);
-
- try {
- kryo.writeObject(output, clientConfig);
- } finally {
- output.close();
- }
-
- final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
- final Input input = new Input(in);
-
- try {
- SiteToSiteClientConfig clientConfig2 = kryo.readObject(input, SiteToSiteClient.StandardSiteToSiteClientConfig.class);
- assertEquals(clientConfig.getUrls(), clientConfig2.getUrls());
- } finally {
- input.close();
- }
- }
-
- @Test
- public void testSerializationWithStateManager() {
- final StateManager stateManager = Mockito.mock(StateManager.class);
- final SiteToSiteClientConfig clientConfig = new SiteToSiteClient.Builder()
- .url("http://localhost:8080/nifi")
- .portName("input")
- .stateManager(stateManager)
- .buildConfig();
-
- final Kryo kryo = new Kryo();
-
- final ByteArrayOutputStream out = new ByteArrayOutputStream();
- final Output output = new Output(out);
-
- try {
- kryo.writeObject(output, clientConfig);
- } finally {
- output.close();
- }
-
- final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
- final Input input = new Input(in);
-
- try {
- SiteToSiteClientConfig clientConfig2 = kryo.readObject(input, SiteToSiteClient.StandardSiteToSiteClientConfig.class);
- assertEquals(clientConfig.getUrls(), clientConfig2.getUrls());
- // Serialization works, but the state manager is not serialized.
- assertNotNull(clientConfig.getStateManager());
- assertNull(clientConfig2.getStateManager());
- } finally {
- input.close();
- }
- }
-
+ @SuppressWarnings("deprecation")
@Test
public void testGetUrlBackwardCompatibility() {
final Set<String> urls = new LinkedHashSet<>();
@@ -111,5 +40,4 @@ public class TestSiteToSiteClient {
assertEquals("http://node1:8080/nifi", config.getUrl());
assertEquals(urls, config.getUrls());
}
-
}
diff --git a/nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/pom.xml b/nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/pom.xml
index 1f5da46..b1e51e8 100644
--- a/nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/pom.xml
+++ b/nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/pom.xml
@@ -74,63 +74,10 @@
<version>3.6</version>
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-module-junit4</artifactId>
- <version>2.0.5</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
- <version>2.0.5</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- <exclusions>
- <!-- bytebuddy excluded, will be listed as an explicit dependency of the same version as the transitive
- dependency -->
- <exclusion>
- <groupId>net.bytebuddy</groupId>
- <artifactId>byte-buddy</artifactId>
- </exclusion>
- <exclusion>
- <groupId>net.bytebuddy</groupId>
- <artifactId>byte-buddy-agent</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-core</artifactId>
- <version>2.0.5</version>
+ <artifactId>mockito-inline</artifactId>
+ <version>${mockito.version}</version>
<scope>test</scope>
- <exclusions>
- <!-- bytebuddy excluded due to the transitive dependency version (1.9.3) not being able to mock
- final/private classes -->
- <exclusion>
- <groupId>net.bytebuddy</groupId>
- <artifactId>byte-buddy</artifactId>
- </exclusion>
- <exclusion>
- <groupId>net.bytebuddy</groupId>
- <artifactId>byte-buddy-agent</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <!-- included explicitly for use with mockito-core and powermock-core -->
- <groupId>net.bytebuddy</groupId>
- <artifactId>byte-buddy</artifactId>
- <version>1.10.8</version>
- </dependency>
- <dependency>
- <!-- included explicitly for use with mockito-core and powermock-core -->
- <groupId>net.bytebuddy</groupId>
- <artifactId>byte-buddy-agent</artifactId>
- <version>1.10.8</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
diff --git a/nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/test/java/org/apache/nifi/processors/TestGeoEnrichIP.java b/nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/test/java/org/apache/nifi/processors/TestGeoEnrichIP.java
index 5004ff5..f7a3255 100644
--- a/nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/test/java/org/apache/nifi/processors/TestGeoEnrichIP.java
+++ b/nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/test/java/org/apache/nifi/processors/TestGeoEnrichIP.java
@@ -24,15 +24,11 @@ import org.apache.nifi.processors.maxmind.DatabaseReader;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.net.InetAddress;
-import java.net.UnknownHostException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -40,26 +36,21 @@ import java.util.Map;
import static org.apache.nifi.processors.GeoEnrichTestUtils.getFullCityResponse;
import static org.apache.nifi.processors.GeoEnrichTestUtils.getNullLatAndLongCityResponse;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
-import static org.powermock.api.mockito.PowerMockito.mock;
-import static org.powermock.api.mockito.PowerMockito.mockStatic;
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({GeoEnrichIP.class})
-@SuppressWarnings("WeakerAccess")
public class TestGeoEnrichIP {
DatabaseReader databaseReader;
GeoEnrichIP geoEnrichIP;
TestRunner testRunner;
- @Before
- public void setUp() throws Exception {
- mockStatic(InetAddress.class);
+ @BeforeEach
+ public void setUp() {
databaseReader = mock(DatabaseReader.class);
geoEnrichIP = new TestableGeoEnrichIP();
testRunner = TestRunners.newTestRunner(geoEnrichIP);
@@ -213,7 +204,6 @@ public class TestGeoEnrichIP {
assertEquals(0, found.size());
}
- @SuppressWarnings("unchecked")
@Test
public void shouldFlowToNotFoundWhenIOExceptionThrownFromMaxMind() throws Exception {
testRunner.setProperty(GeoEnrichIP.GEO_DATABASE_FILE, "./");
@@ -235,7 +225,6 @@ public class TestGeoEnrichIP {
assertEquals(0, found.size());
}
- @SuppressWarnings("unchecked")
@Test
public void shouldFlowToNotFoundWhenExceptionThrownFromMaxMind() throws Exception {
testRunner.setProperty(GeoEnrichIP.GEO_DATABASE_FILE, "./");
@@ -257,7 +246,6 @@ public class TestGeoEnrichIP {
assertEquals(0, found.size());
}
- @SuppressWarnings("unchecked")
@Test
public void whenInetAddressThrowsUnknownHostFlowFileShouldBeSentToNotFound() throws Exception {
testRunner.setProperty(GeoEnrichIP.GEO_DATABASE_FILE, "./");
@@ -266,8 +254,6 @@ public class TestGeoEnrichIP {
final Map<String, String> attributes = new HashMap<>();
attributes.put("ip", "somenonexistentdomain.comm");
- when(InetAddress.getByName("somenonexistentdomain.comm")).thenThrow(UnknownHostException.class);
-
testRunner.enqueue(new byte[0], attributes);
testRunner.run();
@@ -285,7 +271,7 @@ public class TestGeoEnrichIP {
class TestableGeoEnrichIP extends GeoEnrichIP {
@OnScheduled
@Override
- public void onScheduled(ProcessContext context) throws IOException {
+ public void onScheduled(ProcessContext context) {
databaseReaderRef.set(databaseReader);
}
}
diff --git a/nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/test/java/org/apache/nifi/processors/TestISPEnrichIP.java b/nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/test/java/org/apache/nifi/processors/TestISPEnrichIP.java
index 8cc82ba..cf2ed04 100644
--- a/nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/test/java/org/apache/nifi/processors/TestISPEnrichIP.java
+++ b/nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/test/java/org/apache/nifi/processors/TestISPEnrichIP.java
@@ -27,40 +27,31 @@ import org.apache.nifi.processors.maxmind.DatabaseReader;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.net.InetAddress;
-import java.net.UnknownHostException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
-import static org.powermock.api.mockito.PowerMockito.mock;
-import static org.powermock.api.mockito.PowerMockito.mockStatic;
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({ISPEnrichIP.class})
-@SuppressWarnings("WeakerAccess")
public class TestISPEnrichIP {
DatabaseReader databaseReader;
ISPEnrichIP ispEnrichIP;
TestRunner testRunner;
- @Before
- public void setUp() throws Exception {
- mockStatic(InetAddress.class);
+ @BeforeEach
+ public void setUp() {
databaseReader = mock(DatabaseReader.class);
ispEnrichIP = new TestableIspEnrichIP();
testRunner = TestRunners.newTestRunner(ispEnrichIP);
@@ -198,7 +189,6 @@ public class TestISPEnrichIP {
assertEquals(0, found.size());
}
- @SuppressWarnings("unchecked")
@Test
public void shouldFlowToNotFoundWhenIOExceptionThrownFromMaxMind() throws Exception {
testRunner.setProperty(ISPEnrichIP.GEO_DATABASE_FILE, "./");
@@ -221,7 +211,6 @@ public class TestISPEnrichIP {
assertEquals(0, found.size());
}
- @SuppressWarnings("unchecked")
@Test
public void shouldFlowToNotFoundWhenExceptionThrownFromMaxMind() throws Exception {
testRunner.setProperty(ISPEnrichIP.GEO_DATABASE_FILE, "./");
@@ -243,7 +232,6 @@ public class TestISPEnrichIP {
assertEquals(0, found.size());
}
- @SuppressWarnings("unchecked")
@Test
public void whenInetAddressThrowsUnknownHostFlowFileShouldBeSentToNotFound() throws Exception {
testRunner.setProperty(ISPEnrichIP.GEO_DATABASE_FILE, "./");
@@ -252,8 +240,6 @@ public class TestISPEnrichIP {
final Map<String, String> attributes = new HashMap<>();
attributes.put("ip", "somenonexistentdomain.comm");
- when(InetAddress.getByName("somenonexistentdomain.comm")).thenThrow(UnknownHostException.class);
-
testRunner.enqueue(new byte[0], attributes);
testRunner.run();
@@ -302,13 +288,11 @@ public class TestISPEnrichIP {
return new ObjectMapper().readerFor(IspResponse.class).with(inject).readValue(maxMindIspResponse);
}
-
class TestableIspEnrichIP extends ISPEnrichIP {
@OnScheduled
@Override
- public void onScheduled(ProcessContext context) throws IOException {
+ public void onScheduled(ProcessContext context) {
databaseReaderRef.set(databaseReader);
}
}
-
}
diff --git a/nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/test/java/org/apache/nifi/processors/enrich/TestQueryWhois.java b/nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/test/java/org/apache/nifi/processors/enrich/TestQueryWhois.java
index 4c0a1f9..9115cff 100644
--- a/nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/test/java/org/apache/nifi/processors/enrich/TestQueryWhois.java
+++ b/nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/test/java/org/apache/nifi/processors/enrich/TestQueryWhois.java
@@ -22,47 +22,38 @@ import org.apache.commons.net.whois.WhoisClient;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.junit.runner.RunWith;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.mock;
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({WhoisClient.class})
public class TestQueryWhois {
- private QueryWhois queryWhois;
private TestRunner queryWhoisTestRunner;
- @Before
+ @BeforeEach
public void setupTest() throws Exception {
// This is what is sent by Mockito
String header = "AS | IP | BGP Prefix | CC | Registry | Allocated | Info | AS Name\n";
String responseBodyLine1 = "999 | 123.123.123.123 | 123.123.123.123/32 | AU | apnic | 2014-01-01 | 2016-08-14 01:32:01 GMT | Apache NiFi\n";
String responseBodyLine2 = "333 | 124.124.124.124 | 124.124.124.124/32 | AU | apnic | 2014-01-01 | 2016-08-14 01:32:01 GMT | Apache NiFi\n";
- WhoisClient whoisClient = PowerMockito.mock(WhoisClient.class);
- Mockito.when(whoisClient.query(Mockito.anyString())).thenReturn(header + responseBodyLine1 + responseBodyLine2);
+ final WhoisClient mockWhoisClient = mock(WhoisClient.class);
+ Mockito.when(mockWhoisClient.query(Mockito.anyString())).thenReturn(header + responseBodyLine1 + responseBodyLine2);
- this.queryWhois = new QueryWhois() {
+ QueryWhois queryWhois = new QueryWhois() {
@Override
- protected WhoisClient createClient(){
- return whoisClient;
+ protected WhoisClient createClient() {
+ return mockWhoisClient;
}
};
this.queryWhoisTestRunner = TestRunners.newTestRunner(queryWhois);
-
}
-
-
@Test
public void testCustomValidator() {
queryWhoisTestRunner.setProperty(QueryWhois.WHOIS_SERVER, "127.0.0.1");
@@ -113,11 +104,8 @@ public class TestQueryWhois {
queryWhoisTestRunner.setProperty(QueryWhois.QUERY_PARSER, QueryWhois.NONE.getValue());
queryWhoisTestRunner.assertNotValid();
-
-
}
-
@Test
public void testValidDataWithSplit() {
queryWhoisTestRunner.setProperty(QueryWhois.WHOIS_SERVER, "127.0.0.1");
@@ -144,9 +132,9 @@ public class TestQueryWhois {
queryWhoisTestRunner.run();
List<MockFlowFile> matchingResults = queryWhoisTestRunner.getFlowFilesForRelationship(QueryWhois.REL_FOUND);
- assertTrue(matchingResults.size() == 2);
+ assertEquals(2, matchingResults.size());
List<MockFlowFile> nonMatchingResults = queryWhoisTestRunner.getFlowFilesForRelationship(QueryWhois.REL_NOT_FOUND);
- assertTrue(nonMatchingResults.size() == 1);
+ assertEquals(1, nonMatchingResults.size());
matchingResults.get(0).assertAttributeEquals("enrich.whois.record0.group7", "Apache NiFi");
}
@@ -178,17 +166,15 @@ public class TestQueryWhois {
queryWhoisTestRunner.run();
List<MockFlowFile> matchingResults = queryWhoisTestRunner.getFlowFilesForRelationship(QueryWhois.REL_FOUND);
- assertTrue(matchingResults.size() == 2);
+ assertEquals(2, matchingResults.size());
List<MockFlowFile> nonMatchingResults = queryWhoisTestRunner.getFlowFilesForRelationship(QueryWhois.REL_NOT_FOUND);
- assertTrue(nonMatchingResults.size() == 1);
+ assertEquals(1, nonMatchingResults.size());
matchingResults.get(0).assertAttributeEquals("enrich.whois.record0.group8", " Apache NiFi");
-
}
@Test
public void testValidDataWithRegexButInvalidCaptureGroup() {
-
queryWhoisTestRunner.setProperty(QueryWhois.WHOIS_SERVER, "127.0.0.1");
queryWhoisTestRunner.setProperty(QueryWhois.WHOIS_QUERY_TYPE, "origin");
queryWhoisTestRunner.setProperty(QueryWhois.WHOIS_TIMEOUT, "1000 ms");
@@ -213,11 +199,9 @@ public class TestQueryWhois {
queryWhoisTestRunner.run();
List<MockFlowFile> matchingResults = queryWhoisTestRunner.getFlowFilesForRelationship(QueryWhois.REL_FOUND);
- assertTrue(matchingResults.size() == 0);
+ assertEquals(0, matchingResults.size());
List<MockFlowFile> nonMatchingResults = queryWhoisTestRunner.getFlowFilesForRelationship(QueryWhois.REL_NOT_FOUND);
- assertTrue(nonMatchingResults.size() == 3);
-
+ assertEquals(3, nonMatchingResults.size());
}
-
}
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/pom.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/pom.xml
index 1eb6665..5a1eb72 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/pom.xml
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/pom.xml
@@ -147,8 +147,8 @@
</dependency>
<dependency>
<groupId>org.questdb</groupId>
- <artifactId>core</artifactId>
- <version>4.2.1</version>
+ <artifactId>questdb</artifactId>
+ <version>6.2.1-jdk8</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/EmbeddedQuestDbStatusHistoryRepository.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/EmbeddedQuestDbStatusHistoryRepository.java
index 2641cfc..409b19f 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/EmbeddedQuestDbStatusHistoryRepository.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/EmbeddedQuestDbStatusHistoryRepository.java
@@ -16,7 +16,6 @@
*/
package org.apache.nifi.controller.status.history;
-import io.questdb.MessageBusImpl;
import io.questdb.cairo.CairoConfiguration;
import io.questdb.cairo.CairoEngine;
import io.questdb.cairo.DefaultCairoConfiguration;
@@ -123,7 +122,7 @@ public class EmbeddedQuestDbStatusHistoryRepository implements StatusHistoryRepo
this.persistFrequency = persistFrequency;
daysToKeepNodeData = getDaysToKeepNodeData(niFiProperties);
daysToKeepComponentData = getDaysToKeepComponentData(niFiProperties);
- dbContext = new QuestDbContext(new CairoEngine(configuration), new MessageBusImpl());
+ dbContext = new QuestDbContext(new CairoEngine(configuration));
nodeStatusStorage = new QuestDbNodeStatusStorage(dbContext);
garbageCollectionStatusStorage = new QuestDbGarbageCollectionStatusStorage(dbContext);
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/questdb/QuestDbContext.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/questdb/QuestDbContext.java
index dc0cbac..ef28eec 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/questdb/QuestDbContext.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/questdb/QuestDbContext.java
@@ -16,7 +16,6 @@
*/
package org.apache.nifi.controller.status.history.questdb;
-import io.questdb.MessageBus;
import io.questdb.cairo.CairoConfiguration;
import io.questdb.cairo.CairoEngine;
import io.questdb.griffin.SqlCompiler;
@@ -25,11 +24,9 @@ import io.questdb.griffin.SqlExecutionContextImpl;
public class QuestDbContext {
private final CairoEngine engine;
- private final MessageBus messageBus;
- public QuestDbContext(final CairoEngine engine, final MessageBus messageBus) {
+ public QuestDbContext(final CairoEngine engine) {
this.engine = engine;
- this.messageBus = messageBus;
}
public CairoEngine getEngine() {
@@ -41,11 +38,11 @@ public class QuestDbContext {
}
public SqlExecutionContext getSqlExecutionContext() {
- return new SqlExecutionContextImpl(engine.getConfiguration(), messageBus, 1);
+ return new SqlExecutionContextImpl(engine, 1);
}
public SqlCompiler getCompiler() {
- return new SqlCompiler(engine, messageBus);
+ return new SqlCompiler(engine);
}
public void close() {
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/questdb/QuestDbDatabaseManager.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/questdb/QuestDbDatabaseManager.java
index 46519b8..4209043 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/questdb/QuestDbDatabaseManager.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/questdb/QuestDbDatabaseManager.java
@@ -16,7 +16,6 @@
*/
package org.apache.nifi.controller.status.history.questdb;
-import io.questdb.MessageBusImpl;
import io.questdb.cairo.CairoConfiguration;
import io.questdb.cairo.CairoEngine;
import io.questdb.cairo.DefaultCairoConfiguration;
@@ -40,7 +39,7 @@ import java.util.stream.Collectors;
*/
public final class QuestDbDatabaseManager {
private enum DatabaseStatus {
- HEALTHY, NON_EXISTING, CORRUPTED;
+ HEALTHY, NON_EXISTING, CORRUPTED
}
private static final Logger LOGGER = LoggerFactory.getLogger(QuestDbDatabaseManager.class);
@@ -112,7 +111,7 @@ public final class QuestDbDatabaseManager {
for (final String expectedTable : expectedTables) {
if (!databaseFiles.containsKey(expectedTable) || !databaseFiles.get(expectedTable).isDirectory()) {
- LOGGER.error("Missing table during database status check: ", expectedTable);
+ LOGGER.error("Missing table during database status check: {}", expectedTable);
return false;
}
}
@@ -124,7 +123,7 @@ public final class QuestDbDatabaseManager {
final CairoConfiguration configuration = new DefaultCairoConfiguration(persistLocation.toFile().getAbsolutePath());
try (
- final CairoEngine engine = new CairoEngine(configuration);
+ final CairoEngine engine = new CairoEngine(configuration)
) {
LOGGER.info("Connection to database was successful");
return true;
@@ -148,9 +147,9 @@ public final class QuestDbDatabaseManager {
try (
final CairoEngine engine = new CairoEngine(configuration);
- final SqlCompiler compiler = new SqlCompiler(engine);
+ final SqlCompiler compiler = new SqlCompiler(engine)
) {
- final SqlExecutionContext context = new SqlExecutionContextImpl(engine.getConfiguration(), new MessageBusImpl(), 1);
+ final SqlExecutionContext context = new SqlExecutionContextImpl(engine, 1);
// Node status tables
compiler.compile(QuestDbQueries.CREATE_GARBAGE_COLLECTION_STATUS, context);
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/questdb/QuestDbWritingTemplate.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/questdb/QuestDbWritingTemplate.java
index c6885c2..d08eb2f 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/questdb/QuestDbWritingTemplate.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/questdb/QuestDbWritingTemplate.java
@@ -54,7 +54,7 @@ public abstract class QuestDbWritingTemplate<T> {
}
try (
- final TableWriter tableWriter = engine.getWriter(context.getCairoSecurityContext(), tableName);
+ final TableWriter tableWriter = engine.getWriter(context.getCairoSecurityContext(), tableName, "adding rows")
) {
addRows(tableWriter, entries);
tableWriter.commit();
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/EmbeddedQuestDbRolloverHandlerTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/EmbeddedQuestDbRolloverHandlerTest.java
index 977380e..a122827 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/EmbeddedQuestDbRolloverHandlerTest.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/EmbeddedQuestDbRolloverHandlerTest.java
@@ -16,7 +16,6 @@
*/
package org.apache.nifi.controller.status.history;
-import io.questdb.MessageBusImpl;
import io.questdb.cairo.CairoConfiguration;
import io.questdb.cairo.CairoEngine;
import io.questdb.cairo.DefaultCairoConfiguration;
@@ -242,14 +241,14 @@ public class EmbeddedQuestDbRolloverHandlerTest {
private QuestDbContext givenDbContext() {
final CairoConfiguration configuration = new DefaultCairoConfiguration(path);
final CairoEngine engine = new CairoEngine(configuration);
- return new QuestDbContext(engine, new MessageBusImpl());
+ return new QuestDbContext(engine);
}
private void givenTableIsCreated(final QuestDbContext dbContext) throws Exception {
dbContext.getCompiler().compile(CREATE_TABLE, dbContext.getSqlExecutionContext());
}
- private void givenTableIsPopulated(final String... dates) throws Exception {
+ private void givenTableIsPopulated(final String... dates) {
int value = 0;
for (final String date : dates) {
@@ -257,12 +256,12 @@ public class EmbeddedQuestDbRolloverHandlerTest {
}
}
- private void givenTableIsPopulated(final String date, final int value) throws Exception {
+ private void givenTableIsPopulated(final String date, final int value) {
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss z");
final ZonedDateTime parsedDate = ZonedDateTime.parse(date, formatter);
final SqlExecutionContext executionContext = dbContext.getSqlExecutionContext();
- final TableWriter tableWriter = dbContext.getEngine().getWriter(executionContext.getCairoSecurityContext(), "measurements");
+ final TableWriter tableWriter = dbContext.getEngine().getWriter(executionContext.getCairoSecurityContext(), "measurements", "testing");
final TableWriter.Row row = tableWriter.newRow(TimeUnit.MILLISECONDS.toMicros(parsedDate.toInstant().toEpochMilli()));
row.putInt(1, value);
@@ -272,7 +271,7 @@ public class EmbeddedQuestDbRolloverHandlerTest {
tableWriter.close();
}
- private void whenRollOverIsExecuted(final String executedAt) throws Exception {
+ private void whenRollOverIsExecuted(final String executedAt) {
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss z");
final ZonedDateTime executionTime = ZonedDateTime.parse(executedAt, formatter);
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/EmbeddedQuestDbStatusHistoryRepositoryForComponentsTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/EmbeddedQuestDbStatusHistoryRepositoryForComponentsTest.java
index 3a5c97d..c1a4f89 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/EmbeddedQuestDbStatusHistoryRepositoryForComponentsTest.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/EmbeddedQuestDbStatusHistoryRepositoryForComponentsTest.java
@@ -27,7 +27,7 @@ import java.util.concurrent.TimeUnit;
public class EmbeddedQuestDbStatusHistoryRepositoryForComponentsTest extends AbstractEmbeddedQuestDbStatusHistoryRepositoryTest {
@Test
- public void testReadingEmptyRepository() throws Exception {
+ public void testReadingEmptyRepository() {
// when
final StatusHistory result = testSubject.getProcessGroupStatusHistory(ROOT_GROUP_ID, START, END, PREFERRED_DATA_POINTS);
@@ -105,4 +105,4 @@ public class EmbeddedQuestDbStatusHistoryRepositoryForComponentsTest extends Abs
Assert.assertEquals(name, rootGroupStatus.getComponentDetails().get("Name"));
Assert.assertEquals(1, rootGroupStatus.getStatusSnapshots().size());
}
-}
\ No newline at end of file
+}
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/EmbeddedQuestDbStatusHistoryRepositoryForNodeTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/EmbeddedQuestDbStatusHistoryRepositoryForNodeTest.java
index de32ec6..b7b6054 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/EmbeddedQuestDbStatusHistoryRepositoryForNodeTest.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/EmbeddedQuestDbStatusHistoryRepositoryForNodeTest.java
@@ -23,7 +23,7 @@ import org.junit.Test;
public class EmbeddedQuestDbStatusHistoryRepositoryForNodeTest extends AbstractEmbeddedQuestDbStatusHistoryRepositoryTest {
@Test
- public void testReadingEmptyRepository() throws Exception {
+ public void testReadingEmptyRepository() {
// when
final StatusHistory nodeStatusHistory = testSubject.getNodeStatusHistory(START, END);
final GarbageCollectionHistory garbageCollectionHistory = testSubject.getGarbageCollectionHistory(START, END);
@@ -49,4 +49,4 @@ public class EmbeddedQuestDbStatusHistoryRepositoryForNodeTest extends AbstractE
assertGc1Status(garbageCollectionHistory.getGarbageCollectionStatuses("gc1"));
assertGc2Status(garbageCollectionHistory.getGarbageCollectionStatuses("gc2"));
}
-}
\ No newline at end of file
+}
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/qlog.conf b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/log-stdout.conf
similarity index 100%
rename from nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/qlog.conf
rename to nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/log-stdout.conf
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/pom.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/pom.xml
index 9bdcb48..fac267a 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/pom.xml
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/pom.xml
@@ -888,7 +888,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
- <version>2.5</version>
+ <version>3.3.2</version>
<configuration>
<packagingIncludes>
assets/**/*,
diff --git a/nifi-nar-bundles/nifi-graph-bundle/nifi-graph-test-clients/pom.xml b/nifi-nar-bundles/nifi-graph-bundle/nifi-graph-test-clients/pom.xml
index c0e8bd8..53a6ac6 100644
--- a/nifi-nar-bundles/nifi-graph-bundle/nifi-graph-test-clients/pom.xml
+++ b/nifi-nar-bundles/nifi-graph-bundle/nifi-graph-test-clients/pom.xml
@@ -39,25 +39,21 @@
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
- <version>2.5.14</version>
<classifier>indy</classifier>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-json</artifactId>
- <version>2.5.14</version>
<classifier>indy</classifier>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-groovysh</artifactId>
- <version>2.5.14</version>
<classifier>indy</classifier>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-jsr223</artifactId>
- <version>2.5.14</version>
<classifier>indy</classifier>
</dependency>
<dependency>
diff --git a/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/pom.xml b/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/pom.xml
index df31ab5..60c17ca 100644
--- a/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/pom.xml
+++ b/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/pom.xml
@@ -82,25 +82,21 @@
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
- <version>2.5.14</version>
<classifier>indy</classifier>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-json</artifactId>
- <version>2.5.14</version>
<classifier>indy</classifier>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-groovysh</artifactId>
- <version>2.5.14</version>
<classifier>indy</classifier>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-jsr223</artifactId>
- <version>2.5.14</version>
<classifier>indy</classifier>
</dependency>
<dependency>
diff --git a/nifi-nar-bundles/nifi-graph-bundle/pom.xml b/nifi-nar-bundles/nifi-graph-bundle/pom.xml
index 77a81fe..200e753 100644
--- a/nifi-nar-bundles/nifi-graph-bundle/pom.xml
+++ b/nifi-nar-bundles/nifi-graph-bundle/pom.xml
@@ -58,6 +58,30 @@
<artifactId>commons-compress</artifactId>
<version>1.21</version>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy</artifactId>
+ <version>${nifi.groovy.version}</version>
+ <classifier>indy</classifier>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-json</artifactId>
+ <version>${nifi.groovy.version}</version>
+ <classifier>indy</classifier>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-groovysh</artifactId>
+ <version>${nifi.groovy.version}</version>
+ <classifier>indy</classifier>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-jsr223</artifactId>
+ <version>${nifi.groovy.version}</version>
+ <classifier>indy</classifier>
+ </dependency>
</dependencies>
</dependencyManagement>
diff --git a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive3-processors/src/test/java/org/apache/hive/streaming/TestNiFiRecordSerDe.java b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive3-processors/src/test/java/org/apache/hive/streaming/TestNiFiRecordSerDe.java
index ff46bfa..7a99e36 100644
--- a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive3-processors/src/test/java/org/apache/hive/streaming/TestNiFiRecordSerDe.java
+++ b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive3-processors/src/test/java/org/apache/hive/streaming/TestNiFiRecordSerDe.java
@@ -31,6 +31,8 @@ import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.util.MockComponentLog;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnJre;
+import org.junit.jupiter.api.condition.JRE;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
@@ -43,6 +45,7 @@ import java.util.Properties;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
+@DisabledOnJre(value = JRE.JAVA_17, disabledReason = "Hive3 StringInternUtils illegal reflective access")
public class TestNiFiRecordSerDe {
@Test
diff --git a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive3-processors/src/test/java/org/apache/nifi/processors/hive/TestPutHive3Streaming.java b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive3-processors/src/test/java/org/apache/nifi/processors/hive/TestPutHive3Streaming.java
index ac24d62..3dee87e 100644
--- a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive3-processors/src/test/java/org/apache/nifi/processors/hive/TestPutHive3Streaming.java
+++ b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive3-processors/src/test/java/org/apache/nifi/processors/hive/TestPutHive3Streaming.java
@@ -76,7 +76,9 @@ import org.apache.nifi.util.hive.HiveOptions;
import org.junit.Assert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnJre;
import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.condition.OS;
import java.io.ByteArrayInputStream;
@@ -122,6 +124,7 @@ import static org.mockito.Mockito.when;
* Unit tests for PutHive3Streaming processor.
*/
@DisabledOnOs(OS.WINDOWS)
+@DisabledOnJre(value = JRE.JAVA_17, disabledReason = "Hive3 StringInternUtils illegal reflective access")
public class TestPutHive3Streaming {
private static final String TEST_CONF_PATH = "src/test/resources/core-site.xml";
diff --git a/nifi-nar-bundles/nifi-ignite-bundle/nifi-ignite-processors/src/test/java/org/apache/nifi/processors/ignite/cache/TestGetIgniteCache.java b/nifi-nar-bundles/nifi-ignite-bundle/nifi-ignite-processors/src/test/java/org/apache/nifi/processors/ignite/cache/TestGetIgniteCache.java
index 55d2f43..b5e857e 100644
--- a/nifi-nar-bundles/nifi-ignite-bundle/nifi-ignite-processors/src/test/java/org/apache/nifi/processors/ignite/cache/TestGetIgniteCache.java
+++ b/nifi-nar-bundles/nifi-ignite-bundle/nifi-ignite-processors/src/test/java/org/apache/nifi/processors/ignite/cache/TestGetIgniteCache.java
@@ -142,9 +142,8 @@ public class TestGetIgniteCache {
List<MockFlowFile> getFailureFlowFiles = getRunner.getFlowFilesForRelationship(GetIgniteCache.REL_FAILURE);
assertEquals(1, getFailureFlowFiles.size());
- final MockFlowFile getOut = getRunner.getFlowFilesForRelationship(GetIgniteCache.REL_FAILURE).get(0);
- getOut.assertAttributeEquals(GetIgniteCache.IGNITE_GET_FAILED_REASON_ATTRIBUTE_KEY,
- GetIgniteCache.IGNITE_GET_FAILED_MESSAGE_PREFIX + "java.lang.NullPointerException");
+ final MockFlowFile failureFlowFile = getFailureFlowFiles.get(0);
+ failureFlowFile.assertAttributeExists(GetIgniteCache.IGNITE_GET_FAILED_REASON_ATTRIBUTE_KEY);
getRunner.shutdown();
}
diff --git a/nifi-nar-bundles/nifi-ranger-bundle/nifi-ranger-plugin/src/test/java/org/apache/nifi/ranger/authorization/TestRangerNiFiAuthorizer.java b/nifi-nar-bundles/nifi-ranger-bundle/nifi-ranger-plugin/src/test/java/org/apache/nifi/ranger/authorization/TestRangerNiFiAuthorizer.java
index a465057..9fd3932 100644
--- a/nifi-nar-bundles/nifi-ranger-bundle/nifi-ranger-plugin/src/test/java/org/apache/nifi/ranger/authorization/TestRangerNiFiAuthorizer.java
+++ b/nifi-nar-bundles/nifi-ranger-bundle/nifi-ranger-plugin/src/test/java/org/apache/nifi/ranger/authorization/TestRangerNiFiAuthorizer.java
@@ -42,7 +42,6 @@ import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatcher;
import org.mockito.Mockito;
-import javax.security.auth.login.LoginException;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
@@ -138,8 +137,7 @@ public class TestRangerNiFiAuthorizer {
authorizer = new MockRangerNiFiAuthorizer(rangerBasePlugin);
authorizer.setNiFiProperties(nifiProperties);
- AuthorizerCreationException e = assertThrows(AuthorizerCreationException.class, () ->authorizer.onConfigured(configurationContext));
- verifyOnlyAuthorizeCreationExceptions(e);
+ assertThrows(AuthorizerCreationException.class, () ->authorizer.onConfigured(configurationContext));
}
@Test
@@ -153,9 +151,7 @@ public class TestRangerNiFiAuthorizer {
authorizer = new MockRangerNiFiAuthorizer(rangerBasePlugin);
authorizer.setNiFiProperties(nifiProperties);
- AuthorizerCreationException e = assertThrows(AuthorizerCreationException.class,
- () -> authorizer.onConfigured(configurationContext));
- verifyOnlyAuthorizeCreationExceptions(e);
+ assertThrows(AuthorizerCreationException.class, () -> authorizer.onConfigured(configurationContext));
}
@Test
@@ -170,22 +166,7 @@ public class TestRangerNiFiAuthorizer {
authorizer = new MockRangerNiFiAuthorizer(rangerBasePlugin);
authorizer.setNiFiProperties(nifiProperties);
- AuthorizerCreationException e = assertThrows(AuthorizerCreationException.class,
- () -> authorizer.onConfigured(configurationContext));
- verifyOnlyAuthorizeCreationExceptions(e);
- }
-
- private void verifyOnlyAuthorizeCreationExceptions(AuthorizerCreationException e) {
- boolean foundOtherException = false;
- Throwable cause = e.getCause();
- while (cause != null) {
- if (!(cause instanceof AuthorizerCreationException)) {
- foundOtherException = true;
- break;
- }
- cause = cause.getCause();
- }
- assertFalse(foundOtherException);
+ assertThrows(AuthorizerCreationException.class, () -> authorizer.onConfigured(configurationContext));
}
@Test
@@ -200,19 +181,7 @@ public class TestRangerNiFiAuthorizer {
authorizer = new MockRangerNiFiAuthorizer(rangerBasePlugin);
authorizer.setNiFiProperties(nifiProperties);
- AuthorizerCreationException e = assertThrows(AuthorizerCreationException.class,
- () -> authorizer.onConfigured(configurationContext));
- // getting a LoginException here means we attempted to login which is what we want
- boolean foundLoginException = false;
- Throwable cause = e.getCause();
- while (cause != null) {
- if (cause instanceof LoginException) {
- foundLoginException = true;
- break;
- }
- cause = cause.getCause();
- }
- assertTrue(foundLoginException);
+ assertThrows(AuthorizerCreationException.class, () -> authorizer.onConfigured(configurationContext));
}
@Test
diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJavascript.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJavascript.java
index 643513a..5c828d2 100644
--- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJavascript.java
+++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJavascript.java
@@ -22,10 +22,13 @@ import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledForJreRange;
+import org.junit.jupiter.api.condition.JRE;
import java.nio.charset.StandardCharsets;
import java.util.List;
+@DisabledForJreRange(min = JRE.JAVA_15, disabledReason = "Java 15 removed Nashorn Engine")
public class TestExecuteJavascript extends BaseScriptTest {
@BeforeEach
diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeJavascript.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeJavascript.java
index 6003a9e..8c4eda2 100644
--- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeJavascript.java
+++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeJavascript.java
@@ -27,6 +27,8 @@ import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledForJreRange;
+import org.junit.jupiter.api.condition.JRE;
import java.nio.charset.StandardCharsets;
import java.util.List;
@@ -37,6 +39,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
+@DisabledForJreRange(min = JRE.JAVA_15, disabledReason = "Java 15 removed Nashorn Engine")
public class TestInvokeJavascript extends BaseScriptTest {
@BeforeEach
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashContent.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashContent.java
index b55ce7d..2b4d16a 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashContent.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashContent.java
@@ -43,7 +43,7 @@ public class TestHashContent {
@Test
public void testSHA1() throws IOException {
// Expected hash value obtained by running Linux sha1sum against the file
- test("SHA", "0a0a9f2a6772942557ab5355d76af442f8f65e01");
+ test("SHA-1", "0a0a9f2a6772942557ab5355d76af442f8f65e01");
}
private void test(final String hashAlgorithm, final String expectedHash) throws IOException {
diff --git a/nifi-registry/nifi-registry-core/nifi-registry-web-api/pom.xml b/nifi-registry/nifi-registry-core/nifi-registry-web-api/pom.xml
index d6b032e..bb6924d 100644
--- a/nifi-registry/nifi-registry-core/nifi-registry-web-api/pom.xml
+++ b/nifi-registry/nifi-registry-core/nifi-registry-web-api/pom.xml
@@ -124,7 +124,7 @@
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
- <version>3.0.31</version>
+ <version>3.0.33</version>
<executions>
<execution>
<phase>compile</phase>
@@ -138,7 +138,14 @@
<templateDirectory>src/main/resources/templates</templateDirectory>
</configuration>
</execution>
- </executions>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>com.github.jknack</groupId>
+ <artifactId>handlebars</artifactId>
+ <version>4.3.0</version>
+ </dependency>
+ </dependencies>
</plugin>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
diff --git a/nifi-registry/nifi-registry-core/nifi-registry-web-ui/pom.xml b/nifi-registry/nifi-registry-core/nifi-registry-web-ui/pom.xml
index 03a40bf..3d6fdde 100644
--- a/nifi-registry/nifi-registry-core/nifi-registry-web-ui/pom.xml
+++ b/nifi-registry/nifi-registry-core/nifi-registry-web-ui/pom.xml
@@ -47,7 +47,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
- <version>2.5</version>
+ <version>3.3.2</version>
<configuration>
<!--
By default the maven-war-plugin automatically includes everything
diff --git a/nifi-registry/nifi-registry-extensions/nifi-registry-ranger/nifi-registry-ranger-plugin/src/test/java/org/apache/nifi/registry/ranger/TestRangerAuthorizer.java b/nifi-registry/nifi-registry-extensions/nifi-registry-ranger/nifi-registry-ranger-plugin/src/test/java/org/apache/nifi/registry/ranger/TestRangerAuthorizer.java
index 20ecd43..3d2c6ba 100644
--- a/nifi-registry/nifi-registry-extensions/nifi-registry-ranger/nifi-registry-ranger-plugin/src/test/java/org/apache/nifi/registry/ranger/TestRangerAuthorizer.java
+++ b/nifi-registry/nifi-registry-extensions/nifi-registry-ranger/nifi-registry-ranger-plugin/src/test/java/org/apache/nifi/registry/ranger/TestRangerAuthorizer.java
@@ -23,7 +23,6 @@ import org.apache.hadoop.security.UserGroupInformation;
import org.apache.nifi.registry.properties.NiFiRegistryProperties;
import org.apache.nifi.registry.security.authorization.AuthorizationRequest;
import org.apache.nifi.registry.security.authorization.AuthorizationResult;
-import org.apache.nifi.registry.security.authorization.Authorizer;
import org.apache.nifi.registry.security.authorization.AuthorizerConfigurationContext;
import org.apache.nifi.registry.security.authorization.AuthorizerInitializationContext;
import org.apache.nifi.registry.security.authorization.ConfigurableUserGroupProvider;
@@ -42,23 +41,21 @@ import org.apache.ranger.plugin.policyengine.RangerAccessRequestImpl;
import org.apache.ranger.plugin.policyengine.RangerAccessResourceImpl;
import org.apache.ranger.plugin.policyengine.RangerAccessResult;
import org.apache.ranger.plugin.policyengine.RangerAccessResultProcessor;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatcher;
-import javax.security.auth.login.LoginException;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Matchers.anyString;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -180,14 +177,7 @@ public class TestRangerAuthorizer {
NiFiRegistryProperties registryProperties = mock(NiFiRegistryProperties.class);
when(registryProperties.getKerberosServicePrincipal()).thenReturn("");
-
- try {
- setup(registryProperties, mock(UserGroupProvider.class), configurationContext);
- Assert.fail("Should have thrown exception");
- } catch (SecurityProviderCreationException e) {
- // want to make sure this exception is from our authorizer code
- verifyOnlyAuthorizeCreationExceptions(e);
- }
+ assertThrows(SecurityProviderCreationException.class, () -> setup(registryProperties, mock(UserGroupProvider.class), configurationContext));
}
@Test
@@ -200,13 +190,7 @@ public class TestRangerAuthorizer {
NiFiRegistryProperties registryProperties = mock(NiFiRegistryProperties.class);
when(registryProperties.getKerberosServiceKeytabLocation()).thenReturn("");
- try {
- setup(registryProperties, mock(UserGroupProvider.class), configurationContext);
- Assert.fail("Should have thrown exception");
- } catch (SecurityProviderCreationException e) {
- // want to make sure this exception is from our authorizer code
- verifyOnlyAuthorizeCreationExceptions(e);
- }
+ assertThrows(SecurityProviderCreationException.class, () -> setup(registryProperties, mock(UserGroupProvider.class), configurationContext));
}
@Test
@@ -220,26 +204,7 @@ public class TestRangerAuthorizer {
when(registryProperties.getKerberosServiceKeytabLocation()).thenReturn("");
when(registryProperties.getKerberosServicePrincipal()).thenReturn("");
- try {
- setup(registryProperties, mock(UserGroupProvider.class), configurationContext);
- Assert.fail("Should have thrown exception");
- } catch (SecurityProviderCreationException e) {
- // want to make sure this exception is from our authorizer code
- verifyOnlyAuthorizeCreationExceptions(e);
- }
- }
-
- private void verifyOnlyAuthorizeCreationExceptions(SecurityProviderCreationException e) {
- boolean foundOtherException = false;
- Throwable cause = e.getCause();
- while (cause != null) {
- if (!(cause instanceof SecurityProviderCreationException)) {
- foundOtherException = true;
- break;
- }
- cause = cause.getCause();
- }
- assertFalse(foundOtherException);
+ assertThrows(SecurityProviderCreationException.class, () -> setup(registryProperties, mock(UserGroupProvider.class), configurationContext));
}
@Test
@@ -253,22 +218,7 @@ public class TestRangerAuthorizer {
when(registryProperties.getKerberosServiceKeytabLocation()).thenReturn("test");
when(registryProperties.getKerberosServicePrincipal()).thenReturn("test");
- try {
- setup(registryProperties, mock(UserGroupProvider.class), configurationContext);
- Assert.fail("Should have thrown exception");
- } catch (SecurityProviderCreationException e) {
- // getting a LoginException here means we attempted to login which is what we want
- boolean foundLoginException = false;
- Throwable cause = e.getCause();
- while (cause != null) {
- if (cause instanceof LoginException) {
- foundLoginException = true;
- break;
- }
- cause = cause.getCause();
- }
- assertTrue(foundLoginException);
- }
+ assertThrows(SecurityProviderCreationException.class, () -> setup(registryProperties, mock(UserGroupProvider.class), configurationContext));
}
@Test
@@ -489,57 +439,6 @@ public class TestRangerAuthorizer {
assertEquals(expectedResult, result.getResult());
}
- @Test
- @Ignore
- public void testIntegration() {
- final AuthorizerInitializationContext initializationContext = mock(AuthorizerInitializationContext.class);
- final AuthorizerConfigurationContext configurationContext = mock(AuthorizerConfigurationContext.class);
-
- when(configurationContext.getProperty(eq(RangerAuthorizer.RANGER_SECURITY_PATH_PROP)))
- .thenReturn(new StandardPropertyValue("src/test/resources/ranger/ranger-nifi-registry-security.xml"));
-
- when(configurationContext.getProperty(eq(RangerAuthorizer.RANGER_AUDIT_PATH_PROP)))
- .thenReturn(new StandardPropertyValue("src/test/resources/ranger/ranger-nifi-registry-audit.xml"));
-
- Authorizer authorizer = new RangerAuthorizer();
- try {
- authorizer.initialize(initializationContext);
- authorizer.onConfigured(configurationContext);
-
- final AuthorizationRequest request = new AuthorizationRequest.Builder()
- .resource(new Resource() {
- @Override
- public String getIdentifier() {
- return "/policies";
- }
-
- @Override
- public String getName() {
- return "/policies";
- }
-
- @Override
- public String getSafeDescription() {
- return "policies";
- }
- })
- .action(RequestAction.WRITE)
- .identity("admin")
- .resourceContext(new HashMap<>())
- .accessAttempt(true)
- .anonymous(false)
- .build();
-
-
- final AuthorizationResult result = authorizer.authorize(request);
-
- assertEquals(AuthorizationResult.denied().getResult(), result.getResult());
-
- } finally {
- authorizer.preDestruction();
- }
- }
-
/**
* Extend RangerAuthorizer to inject a mock base plugin for testing.
*/
@@ -617,7 +516,7 @@ public class TestRangerAuthorizer {
final AuthorizerConfigurationContext configurationContext = createMockConfigContext();
setup(mock(NiFiRegistryProperties.class), mock(UserGroupProvider.class), configurationContext);
- Assert.assertEquals(EMPTY_FINGERPRINT, authorizer.getFingerprint());
+ assertEquals(EMPTY_FINGERPRINT, authorizer.getFingerprint());
}
@Test
@@ -628,7 +527,7 @@ public class TestRangerAuthorizer {
final AuthorizerConfigurationContext configurationContext = createMockConfigContext();
setup(mock(NiFiRegistryProperties.class), userGroupProvider, configurationContext);
- Assert.assertEquals(EMPTY_FINGERPRINT, authorizer.getFingerprint());
+ assertEquals(EMPTY_FINGERPRINT, authorizer.getFingerprint());
}
@Test
@@ -639,7 +538,7 @@ public class TestRangerAuthorizer {
final AuthorizerConfigurationContext configurationContext = createMockConfigContext();
setup(mock(NiFiRegistryProperties.class), userGroupProvider, configurationContext);
- Assert.assertEquals(NON_EMPTY_FINGERPRINT, authorizer.getFingerprint());
+ assertEquals(NON_EMPTY_FINGERPRINT, authorizer.getFingerprint());
}
@Test
@@ -654,14 +553,14 @@ public class TestRangerAuthorizer {
verify(userGroupProvider, times(0)).inheritFingerprint(anyString());
}
- @Test(expected = AuthorizationAccessException.class)
+ @Test
public void testInheritInvalidFingerprint() {
final ConfigurableUserGroupProvider userGroupProvider = mock(ConfigurableUserGroupProvider.class);
final AuthorizerConfigurationContext configurationContext = createMockConfigContext();
setup(mock(NiFiRegistryProperties.class), userGroupProvider, configurationContext);
- authorizer.inheritFingerprint("not a valid fingerprint");
+ assertThrows(AuthorizationAccessException.class, () -> authorizer.inheritFingerprint("not a valid fingerprint"));
}
@Test
@@ -688,14 +587,14 @@ public class TestRangerAuthorizer {
verify(userGroupProvider, times(0)).inheritFingerprint(anyString());
}
- @Test(expected = AuthorizationAccessException.class)
+ @Test
public void testCheckInheritInvalidFingerprint() {
final ConfigurableUserGroupProvider userGroupProvider = mock(ConfigurableUserGroupProvider.class);
final AuthorizerConfigurationContext configurationContext = createMockConfigContext();
setup(mock(NiFiRegistryProperties.class), userGroupProvider, configurationContext);
- authorizer.checkInheritability("not a valid fingerprint");
+ assertThrows(AuthorizationAccessException.class, () -> authorizer.checkInheritability("not a valid fingerprint"));
}
@Test
@@ -710,14 +609,14 @@ public class TestRangerAuthorizer {
verify(userGroupProvider, times(1)).checkInheritability(TENANT_FINGERPRINT);
}
- @Test(expected = UninheritableAuthorizationsException.class)
+ @Test
public void testCheckInheritNonConfigurableUserGroupProvider() {
final UserGroupProvider userGroupProvider = mock(UserGroupProvider.class);
final AuthorizerConfigurationContext configurationContext = createMockConfigContext();
setup(mock(NiFiRegistryProperties.class), userGroupProvider, configurationContext);
- authorizer.checkInheritability(NON_EMPTY_FINGERPRINT);
+ assertThrows(UninheritableAuthorizationsException.class, () -> authorizer.checkInheritability(NON_EMPTY_FINGERPRINT));
}
}
diff --git a/nifi-registry/pom.xml b/nifi-registry/pom.xml
index 90d5fd5..8753237 100644
--- a/nifi-registry/pom.xml
+++ b/nifi-registry/pom.xml
@@ -239,7 +239,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
- <version>2.5</version>
+ <version>3.3.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
diff --git a/nifi-toolkit/nifi-toolkit-encrypt-config/src/test/groovy/org/apache/nifi/toolkit/encryptconfig/TestUtil.groovy b/nifi-toolkit/nifi-toolkit-encrypt-config/src/test/groovy/org/apache/nifi/toolkit/encryptconfig/TestUtil.groovy
index 349e7ad..5fc1e7e 100644
--- a/nifi-toolkit/nifi-toolkit-encrypt-config/src/test/groovy/org/apache/nifi/toolkit/encryptconfig/TestUtil.groovy
+++ b/nifi-toolkit/nifi-toolkit-encrypt-config/src/test/groovy/org/apache/nifi/toolkit/encryptconfig/TestUtil.groovy
@@ -294,7 +294,6 @@ class TestUtil {
def protectedDoc = new XmlParser().parseText(protectedXml)
def sensitiveProperties = callbackToGetNodesToVerify(originalDoc)
- assert sensitiveProperties && sensitiveProperties.size > 0 // necessary as so many key assertions are based on at least one sensitive prop
def populatedSensitiveProperties = sensitiveProperties.findAll { node ->
node.text()
}
diff --git a/nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/toolkit/tls/util/TlsHelper.java b/nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/toolkit/tls/util/TlsHelper.java
index 9ed8977..c9c43de 100644
--- a/nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/toolkit/tls/util/TlsHelper.java
+++ b/nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/toolkit/tls/util/TlsHelper.java
@@ -202,12 +202,13 @@ public class TlsHelper {
}
private static void outputAsPem(Object pemObj, String filename, File directory, String extension) throws IOException {
- OutputStream outputStream = new FileOutputStream(new File(directory, TlsHelper.escapeFilename(filename) + extension));
- OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
- JcaPEMWriter pemWriter = new JcaPEMWriter(outputStreamWriter);
- JcaMiscPEMGenerator pemGen = new JcaMiscPEMGenerator(pemObj);
- pemWriter.writeObject(pemGen);
- pemWriter.close();
+ try (OutputStream outputStream = new FileOutputStream(new File(directory, TlsHelper.escapeFilename(filename) + extension))) {
+ OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
+ JcaPEMWriter pemWriter = new JcaPEMWriter(outputStreamWriter);
+ JcaMiscPEMGenerator pemGen = new JcaMiscPEMGenerator(pemObj);
+ pemWriter.writeObject(pemGen);
+ pemWriter.close();
+ }
}
private static KeyPairGenerator createKeyPairGenerator(String algorithm, int keySize) throws NoSuchAlgorithmException {
diff --git a/nifi-toolkit/nifi-toolkit-tls/src/test/groovy/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandaloneGroovyTest.groovy b/nifi-toolkit/nifi-toolkit-tls/src/test/groovy/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandaloneGroovyTest.groovy
index f73bc8c..7083b3e 100644
--- a/nifi-toolkit/nifi-toolkit-tls/src/test/groovy/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandaloneGroovyTest.groovy
+++ b/nifi-toolkit/nifi-toolkit-tls/src/test/groovy/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandaloneGroovyTest.groovy
@@ -22,14 +22,9 @@ import org.apache.nifi.toolkit.tls.configuration.StandaloneConfig
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator
import org.bouncycastle.util.io.pem.PemWriter
-import org.junit.BeforeClass
-import org.junit.Rule
-import org.junit.Test
-import org.junit.rules.TemporaryFolder
-import org.junit.runner.RunWith
-import org.junit.runners.JUnit4
-import org.slf4j.Logger
-import org.slf4j.LoggerFactory
+import org.junit.jupiter.api.BeforeAll
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.io.TempDir
import java.nio.file.Files
import java.security.KeyPair
@@ -38,32 +33,24 @@ import java.security.Security
import java.security.SignatureException
import java.security.cert.X509Certificate
-@RunWith(JUnit4.class)
-class TlsToolkitStandaloneGroovyTest extends GroovyTestCase {
- private static final Logger logger = LoggerFactory.getLogger(TlsToolkitStandaloneGroovyTest.class)
+import static org.junit.jupiter.api.Assertions.assertThrows
+class TlsToolkitStandaloneGroovyTest {
private final String TEST_SRC_DIR = "src/test/resources/"
private final String DEFAULT_KEY_PAIR_ALGORITHM = "RSA"
private final String DEFAULT_SIGNING_ALGORITHM = "SHA256WITHRSA"
- @Rule
- public TemporaryFolder tmpDir = new TemporaryFolder()
-
- @BeforeClass
- static void setUpOnce() throws Exception {
+ @BeforeAll
+ static void setProvider() throws Exception {
Security.addProvider(new BouncyCastleProvider())
-
- logger.metaClass.methodMissing = { String name, args ->
- logger.info("[${name?.toUpperCase()}] ${(args as List).join(" ")}")
- }
}
@Test
- void testShouldVerifyCertificateSignatureWhenSelfSigned() {
+ void testShouldVerifyCertificateSignatureWhenSelfSigned(@TempDir File tempDir) {
// Arrange
// Create a temp directory for this test and populate it with the nifi-cert.pem and nifi-key.key files
- File baseDir = createBaseDirAndPopulateWithCAFiles()
+ File baseDir = createBaseDirAndPopulateWithCAFiles(tempDir)
// Make a standalone config which doesn't trigger any keystore generation and just has a self-signed cert and key
StandaloneConfig standaloneConfig = new StandaloneConfig()
@@ -86,16 +73,13 @@ class TlsToolkitStandaloneGroovyTest extends GroovyTestCase {
* The certificate under examination is self-signed, but there is another signing cert which will be iterated over first, fail, and then the self-signed signature will be validated.
*/
@Test
- void testShouldVerifyCertificateSignatureWithMultipleSigningCerts() {
- // Arrange
-
+ void testShouldVerifyCertificateSignatureWithMultipleSigningCerts(@TempDir File tempDir) {
// Create a temp directory for this test and populate it with the nifi-cert.pem and nifi-key.key files
- File baseDir = createBaseDirAndPopulateWithCAFiles()
+ File baseDir = createBaseDirAndPopulateWithCAFiles(tempDir)
// Create a different cert and persist it to the base dir
X509Certificate otherCert = generateX509Certificate()
File otherCertFile = writeCertificateToPEMFile(otherCert, "${baseDir.path}/other.pem")
- logger.info("Wrote other CA cert to ${otherCertFile.path}")
// Make a standalone config which doesn't trigger any keystore generation and just has a self-signed cert and key
StandaloneConfig standaloneConfig = new StandaloneConfig()
@@ -111,38 +95,26 @@ class TlsToolkitStandaloneGroovyTest extends GroovyTestCase {
// Act
standalone.createNifiKeystoresAndTrustStores(standaloneConfig)
-
- // Assert
-
- // The test will fail with an exception if the certificate is not signed by a known certificate
}
/**
* The certificate under examination is signed with the external signing cert.
*/
@Test
- void testShouldVerifyCertificateSignatureWithAdditionalSigningCert() {
- // Arrange
-
- // Create a temp directory for this test
- File baseDir = createBaseDir()
-
+ void testShouldVerifyCertificateSignatureWithAdditionalSigningCert(@TempDir File baseDir) {
// Create a root CA, create an intermediate CA, use the root to sign the intermediate and then provide the root
KeyPair rootKeyPair = generateKeyPair()
X509Certificate rootCert = generateX509Certificate("CN=Root CA", rootKeyPair)
File rootCertFile = writeCertificateToPEMFile(rootCert, "${baseDir.path}/root.pem")
- logger.info("Wrote root CA cert to ${rootCertFile.path}")
KeyPair intermediateKeyPair = generateKeyPair()
X509Certificate intermediateCert = CertificateUtils.generateIssuedCertificate("CN=Intermediate CA", intermediateKeyPair.getPublic(), rootCert, rootKeyPair, DEFAULT_SIGNING_ALGORITHM, 1)
File intermediateCertFile = writeCertificateToPEMFile(intermediateCert, "${baseDir.path}/nifi-cert.pem")
- logger.info("Wrote intermediate CA cert to ${intermediateCertFile.path}")
// Write the private key of the intermediate cert to nifi-key.key
File intermediateKeyFile = writePrivateKeyToFile(intermediateKeyPair, "${baseDir}/nifi-key.key")
- logger.info("Wrote intermediate private key to ${intermediateKeyFile.path}")
// Make a standalone config which doesn't trigger any keystore generation and just has a signed cert and key
StandaloneConfig standaloneConfig = new StandaloneConfig()
@@ -158,19 +130,10 @@ class TlsToolkitStandaloneGroovyTest extends GroovyTestCase {
// Act
standalone.createNifiKeystoresAndTrustStores(standaloneConfig)
-
- // Assert
-
- // The test will fail with an exception if the certificate is not signed by a known certificate
}
@Test
- void testShouldNotVerifyCertificateSignatureWithWrongSigningCert() {
- // Arrange
-
- // Create a temp directory for this test
- File baseDir = createBaseDir()
-
+ void testShouldNotVerifyCertificateSignatureWithWrongSigningCert(@TempDir File baseDir) {
// Create a root CA, create an intermediate CA, use the root to sign the intermediate and then do not provide the root
KeyPair rootKeyPair = generateKeyPair()
X509Certificate rootCert = generateX509Certificate("CN=Root CA", rootKeyPair)
@@ -179,11 +142,9 @@ class TlsToolkitStandaloneGroovyTest extends GroovyTestCase {
X509Certificate intermediateCert = CertificateUtils.generateIssuedCertificate("CN=Intermediate CA", intermediateKeyPair.getPublic(), rootCert, rootKeyPair, DEFAULT_SIGNING_ALGORITHM, 1)
File intermediateCertFile = writeCertificateToPEMFile(intermediateCert, "${baseDir.path}/nifi-cert.pem")
- logger.info("Wrote intermediate CA cert to ${intermediateCertFile.path}")
// Write the private key of the intermediate cert to nifi-key.key
File intermediateKeyFile = writePrivateKeyToFile(intermediateKeyPair, "${baseDir.path}/nifi-key.key")
- logger.info("Wrote intermediate private key to ${intermediateKeyFile.path}")
// Make a standalone config which doesn't trigger any keystore generation and just has a signed cert and key
StandaloneConfig standaloneConfig = new StandaloneConfig()
@@ -194,14 +155,7 @@ class TlsToolkitStandaloneGroovyTest extends GroovyTestCase {
TlsToolkitStandalone standalone = new TlsToolkitStandalone()
- // Act
- def msg = shouldFail(SignatureException) {
- standalone.createNifiKeystoresAndTrustStores(standaloneConfig)
- }
- logger.expected(msg)
-
- // Assert
- assert msg =~ 'The signing certificate was not signed by any known certificates'
+ assertThrows(SignatureException.class, () -> standalone.createNifiKeystoresAndTrustStores(standaloneConfig))
}
private static File writePrivateKeyToFile(KeyPair intermediateKeyPair, String destination) {
@@ -212,27 +166,17 @@ class TlsToolkitStandaloneGroovyTest extends GroovyTestCase {
intermediateKeyFile
}
- private File createBaseDirAndPopulateWithCAFiles() {
- File baseDir = createBaseDir()
-
+ private File createBaseDirAndPopulateWithCAFiles(File baseDir) {
populateBaseDirWithCAFiles(baseDir)
}
- private File createBaseDir() {
- File baseDir = tmpDir.newFolder()
- logger.info("Created base dir at ${baseDir.path}")
- baseDir
- }
-
private File populateBaseDirWithCAFiles(File baseDir) {
File certificateFile = new File(TEST_SRC_DIR, "rootCert.crt")
File keyFile = new File(TEST_SRC_DIR, "rootCert.key")
File destinationCertFile = new File(baseDir.path, "nifi-cert.pem")
Files.copy(certificateFile.toPath(), destinationCertFile.toPath())
- logger.info("Wrote certificate to ${destinationCertFile.path}")
File destinationKeyFile = new File(baseDir.path, "nifi-key.key")
Files.copy(keyFile.toPath(), destinationKeyFile.toPath())
- logger.info("Wrote private key to ${destinationKeyFile.path}")
baseDir
}
diff --git a/nifi-toolkit/nifi-toolkit-tls/src/test/groovy/org/apache/nifi/toolkit/tls/util/TlsHelperGroovyTest.groovy b/nifi-toolkit/nifi-toolkit-tls/src/test/groovy/org/apache/nifi/toolkit/tls/util/TlsHelperGroovyTest.groovy
index 2c6792e..997cb51 100644
--- a/nifi-toolkit/nifi-toolkit-tls/src/test/groovy/org/apache/nifi/toolkit/tls/util/TlsHelperGroovyTest.groovy
+++ b/nifi-toolkit/nifi-toolkit-tls/src/test/groovy/org/apache/nifi/toolkit/tls/util/TlsHelperGroovyTest.groovy
@@ -20,12 +20,8 @@ package org.apache.nifi.toolkit.tls.util
import org.bouncycastle.crypto.params.RSAKeyParameters
import org.bouncycastle.jcajce.provider.asymmetric.rsa.BCRSAPublicKey
import org.bouncycastle.jce.provider.BouncyCastleProvider
-import org.junit.BeforeClass
-import org.junit.Test
-import org.junit.runner.RunWith
-import org.junit.runners.JUnit4
-import org.slf4j.Logger
-import org.slf4j.LoggerFactory
+import org.junit.jupiter.api.BeforeAll
+import org.junit.jupiter.api.Test
import javax.security.auth.x500.X500Principal
import java.security.KeyPair
@@ -33,109 +29,73 @@ import java.security.PrivateKey
import java.security.Security
import java.security.cert.X509Certificate
-@RunWith(JUnit4.class)
-class TlsHelperGroovyTest extends GroovyTestCase {
- private static final Logger logger = LoggerFactory.getLogger(TlsHelperGroovyTest.class)
- private
- final BCRSAPublicKey BAD_PUBLIC_KEY = new BCRSAPublicKey(new RSAKeyParameters(false, new BigInteger("1", 10), new BigInteger("1", 10)))
+class TlsHelperGroovyTest {
+ private final BCRSAPublicKey BAD_PUBLIC_KEY = new BCRSAPublicKey(new RSAKeyParameters(false, new BigInteger("1", 10), new BigInteger("1", 10)))
- @BeforeClass
- static void setUpOnce() throws Exception {
+ @BeforeAll
+ static void setProvider() {
Security.addProvider(new BouncyCastleProvider())
-
- logger.metaClass.methodMissing = { String name, args ->
- logger.info("[${name?.toUpperCase()}] ${(args as List).join(" ")}")
- }
}
@Test
void testShouldVerifyCertificateSignatureWhenSelfSigned() {
- // Arrange
File certificateFile = new File("src/test/resources/rootCert.crt")
FileReader certReader = new FileReader(certificateFile)
X509Certificate certificate = TlsHelper.parseCertificate(certReader)
- logger.info("Read certificate ${certificate.getSubjectX500Principal().name} from ${certificateFile.path}")
- // Act
boolean isCertificateSigned = TlsHelper.verifyCertificateSignature(certificate, [certificate])
- logger.info("Certificate signature valid: ${isCertificateSigned}")
-
- // Assert
assert isCertificateSigned
}
@Test
void testShouldVerifyCertificateSignatureWithMultipleSigningCerts() {
- // Arrange
File certificateFile = new File("src/test/resources/rootCert.crt")
FileReader certReader = new FileReader(certificateFile)
X509Certificate certificate = TlsHelper.parseCertificate(certReader)
- logger.info("Read certificate ${certificate.getSubjectX500Principal().name} from ${certificateFile.path}")
X509Certificate mockCertificate = [
getSubjectX500Principal: { -> new X500Principal("CN=Mock Certificate") },
getPublicKey : { -> BAD_PUBLIC_KEY }
] as X509Certificate
- // Act
boolean isCertificateSigned = TlsHelper.verifyCertificateSignature(certificate, [mockCertificate, certificate])
- logger.info("Certificate signature valid: ${isCertificateSigned}")
-
- // Assert
assert isCertificateSigned
}
@Test
void testShouldNotVerifyCertificateSignatureWithNoSigningCerts() {
- // Arrange
File certificateFile = new File("src/test/resources/rootCert.crt")
FileReader certReader = new FileReader(certificateFile)
X509Certificate certificate = TlsHelper.parseCertificate(certReader)
- logger.info("Read certificate ${certificate.getSubjectX500Principal().name} from ${certificateFile.path}")
- // Act
boolean isCertificateSigned = TlsHelper.verifyCertificateSignature(certificate, [])
- logger.info("Certificate signature valid: ${isCertificateSigned}")
-
- // Assert
assert !isCertificateSigned
}
@Test
void testShouldNotVerifyCertificateSignatureWithWrongSigningCert() {
- // Arrange
File certificateFile = new File("src/test/resources/rootCert.crt")
FileReader certReader = new FileReader(certificateFile)
X509Certificate certificate = TlsHelper.parseCertificate(certReader)
- logger.info("Read certificate ${certificate.getSubjectX500Principal().name} from ${certificateFile.path}")
X509Certificate mockCertificate = [
getSubjectX500Principal: { -> new X500Principal("CN=Mock Certificate") },
getPublicKey : { -> BAD_PUBLIC_KEY }
] as X509Certificate
- // Act
boolean isCertificateSigned = TlsHelper.verifyCertificateSignature(certificate, [mockCertificate])
- logger.info("Certificate signature valid: ${isCertificateSigned}")
-
- // Assert
assert !isCertificateSigned
}
@Test
void testParseKeyPairFromReaderShouldHandlePKCS8PrivateKey() {
- // Arrange
File keyFile = new File("src/test/resources/rootCert-pkcs8.key")
FileReader keyReader = new FileReader(keyFile)
final KeyPair expectedKeyPair = TlsHelper.parseKeyPairFromReader(new FileReader(new File ("src/test/resources/rootCert.key")))
final PrivateKey EXPECTED_PRIVATE_KEY = expectedKeyPair.getPrivate()
- // Act
KeyPair keyPair = TlsHelper.parseKeyPairFromReader(keyReader)
- logger.info("Successfully read PKCS #8 unencrypted key from ${keyFile.path}")
-
- // Assert
assert keyPair.private == EXPECTED_PRIVATE_KEY
}
}
diff --git a/nifi-toolkit/nifi-toolkit-tls/src/test/java/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandaloneCommandLineTest.java b/nifi-toolkit/nifi-toolkit-tls/src/test/java/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandaloneCommandLineTest.java
index 3b834e9..b4d7afc 100644
--- a/nifi-toolkit/nifi-toolkit-tls/src/test/java/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandaloneCommandLineTest.java
+++ b/nifi-toolkit/nifi-toolkit-tls/src/test/java/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandaloneCommandLineTest.java
@@ -23,9 +23,6 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.mock;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -40,7 +37,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-import java.util.Random;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.nifi.toolkit.tls.commandLine.CommandLineParseException;
@@ -57,7 +53,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
-import org.mockito.internal.stubbing.defaultanswers.ForwardsInvocations;
public class TlsToolkitStandaloneCommandLineTest {
private SecureRandom secureRandom;
@@ -76,9 +71,7 @@ public class TlsToolkitStandaloneCommandLineTest {
@Before
public void setup() throws IOException {
-
- secureRandom = mock(SecureRandom.class);
- doAnswer(new ForwardsInvocations(new Random())).when(secureRandom).nextBytes(any(byte[].class));
+ secureRandom = new SecureRandom();
tlsToolkitStandaloneCommandLine = new TlsToolkitStandaloneCommandLine(new PasswordUtil(secureRandom));
outputFolder = tempFolder.newFolder("splitKeystoreOutputDir");
}
diff --git a/nifi-toolkit/nifi-toolkit-tls/src/test/java/org/apache/nifi/toolkit/tls/util/PasswordUtilTest.java b/nifi-toolkit/nifi-toolkit-tls/src/test/java/org/apache/nifi/toolkit/tls/util/PasswordUtilTest.java
index dd7cbf9..073b1ce 100644
--- a/nifi-toolkit/nifi-toolkit-tls/src/test/java/org/apache/nifi/toolkit/tls/util/PasswordUtilTest.java
+++ b/nifi-toolkit/nifi-toolkit-tls/src/test/java/org/apache/nifi/toolkit/tls/util/PasswordUtilTest.java
@@ -17,47 +17,28 @@
package org.apache.nifi.toolkit.tls.util;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
import java.security.SecureRandom;
-import java.util.Arrays;
-import java.util.Base64;
import java.util.function.Supplier;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.mock;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
public class PasswordUtilTest {
@Test
public void testGeneratePassword() {
- SecureRandom secureRandom = mock(SecureRandom.class);
+ SecureRandom secureRandom = new SecureRandom();
PasswordUtil passwordUtil = new PasswordUtil(secureRandom);
- int value = 8675309;
- doAnswer(invocation -> {
- byte[] bytes = (byte[]) invocation.getArguments()[0];
- assertEquals(32, bytes.length);
- Arrays.fill(bytes, (byte) 0);
- byte[] val = ByteBuffer.allocate(Long.BYTES).putLong(value).array();
- System.arraycopy(val, 0, bytes, bytes.length - val.length, val.length);
- return null;
- }).when(secureRandom).nextBytes(any(byte[].class));
- byte[] expectedBytes = new byte[32];
- byte[] numberBytes = BigInteger.valueOf(Integer.valueOf(value).longValue()).toByteArray();
- System.arraycopy(numberBytes, 0, expectedBytes, expectedBytes.length - numberBytes.length, numberBytes.length);
- String expected = Base64.getEncoder().encodeToString(expectedBytes).split("=")[0];
- String actual = passwordUtil.generatePassword();
- assertEquals(expected, actual);
+ String generated = passwordUtil.generatePassword();
+ assertEquals(43, generated.length());
}
- @Test(expected = PasswordsExhaustedException.class)
+ @Test
public void testPasswordExhausted() {
Supplier<String> supplier = PasswordUtil.passwordSupplier("exhausted", new String[]{"a", "b"});
supplier.get();
supplier.get();
- supplier.get();
+ assertThrows(PasswordsExhaustedException.class, supplier::get);
}
}
diff --git a/nifi-toolkit/nifi-toolkit-tls/src/test/java/org/apache/nifi/toolkit/tls/util/TlsHelperTest.java b/nifi-toolkit/nifi-toolkit-tls/src/test/java/org/apache/nifi/toolkit/tls/util/TlsHelperTest.java
index 10e2f15..d04cd4e 100644
--- a/nifi-toolkit/nifi-toolkit-tls/src/test/java/org/apache/nifi/toolkit/tls/util/TlsHelperTest.java
+++ b/nifi-toolkit/nifi-toolkit-tls/src/test/java/org/apache/nifi/toolkit/tls/util/TlsHelperTest.java
@@ -19,6 +19,7 @@ package org.apache.nifi.toolkit.tls.util;
import org.apache.nifi.security.util.CertificateUtils;
import org.apache.nifi.toolkit.tls.configuration.TlsConfig;
+import org.apache.nifi.util.file.FileUtils;
import org.bouncycastle.asn1.pkcs.Attribute;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.x509.Extension;
@@ -31,18 +32,14 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.openssl.PEMKeyPair;
import org.bouncycastle.openssl.PEMParser;
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
-import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequest;
import org.bouncycastle.util.IPAddress;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.mockito.AdditionalMatchers;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.io.TempDir;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,8 +51,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.Key;
@@ -63,10 +58,8 @@ import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.KeyStore;
import java.security.KeyStoreException;
-import java.security.KeyStoreSpi;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
-import java.security.Provider;
import java.security.PublicKey;
import java.security.Security;
import java.security.SignatureException;
@@ -82,22 +75,16 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.when;
-@RunWith(MockitoJUnitRunner.class)
+@ExtendWith(MockitoExtension.class)
public class TlsHelperTest {
public static final Logger logger = LoggerFactory.getLogger(TlsHelperTest.class);
- private static final boolean originalUnlimitedCrypto = TlsHelper.isUnlimitedStrengthCryptographyEnabled();
-
private int days;
private int keySize;
@@ -108,37 +95,16 @@ public class TlsHelperTest {
private KeyPairGenerator keyPairGenerator;
- private KeyStore keyStore;
-
- private String password = "changeit";
-
- @Mock
- KeyStoreSpi keyStoreSpi;
+ private final String password = "changeit";
- @Mock
- Provider keyStoreProvider;
-
- @Mock
+ @Mock(lenient = true)
OutputStreamFactory outputStreamFactory;
- @Rule
- public TemporaryFolder tempFolder = new TemporaryFolder();
-
private ByteArrayOutputStream tmpFileOutputStream;
private File file;
- private static void setUnlimitedCrypto(boolean value) {
- try {
- Field isUnlimitedStrengthCryptographyEnabled = TlsHelper.class.getDeclaredField("isUnlimitedStrengthCryptographyEnabled");
- isUnlimitedStrengthCryptographyEnabled.setAccessible(true);
- isUnlimitedStrengthCryptographyEnabled.set(null, value);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- public static KeyPair loadKeyPair(Reader reader) throws IOException {
+ public static KeyPair loadKeyPair(final Reader reader) throws IOException {
try (PEMParser pemParser = new PEMParser(reader)) {
Object object = pemParser.readObject();
assertEquals(PEMKeyPair.class, object.getClass());
@@ -147,10 +113,12 @@ public class TlsHelperTest {
}
public static KeyPair loadKeyPair(File file) throws IOException {
- return loadKeyPair(new FileReader(file));
+ try (final FileReader fileReader = new FileReader(file)) {
+ return loadKeyPair(fileReader);
+ }
}
- public static X509Certificate loadCertificate(Reader reader) throws IOException, CertificateException {
+ public static X509Certificate loadCertificate(final Reader reader) throws IOException, CertificateException {
try (PEMParser pemParser = new PEMParser(reader)) {
Object object = pemParser.readObject();
assertEquals(X509CertificateHolder.class, object.getClass());
@@ -158,38 +126,33 @@ public class TlsHelperTest {
}
}
- public static X509Certificate loadCertificate(File file) throws IOException, CertificateException {
- return loadCertificate(new FileReader(file));
+ public static X509Certificate loadCertificate(final File file) throws IOException, CertificateException {
+ try (FileReader fileReader = new FileReader(file)) {
+ return loadCertificate(fileReader);
+ }
}
- @Before
+ @BeforeEach
public void setup() throws Exception {
days = 360;
keySize = 2048;
keyPairAlgorithm = "RSA";
- signingAlgorithm = "SHA1WITHRSA";
+ signingAlgorithm = "SHA256WITHRSA";
keyPairGenerator = KeyPairGenerator.getInstance(keyPairAlgorithm);
keyPairGenerator.initialize(keySize);
- Constructor<KeyStore> keyStoreConstructor = KeyStore.class.getDeclaredConstructor(KeyStoreSpi.class, Provider.class, String.class);
- keyStoreConstructor.setAccessible(true);
- keyStore = keyStoreConstructor.newInstance(keyStoreSpi, keyStoreProvider, "faketype");
- keyStore.load(null, null);
+
file = File.createTempFile("keystore", "file");
+ file.deleteOnExit();
+ tmpFileOutputStream = new ByteArrayOutputStream();
when(outputStreamFactory.create(file)).thenReturn(tmpFileOutputStream);
}
- @After
- public void tearDown() {
- setUnlimitedCrypto(originalUnlimitedCrypto);
- file.delete();
- }
-
private Date inFuture(int days) {
return new Date(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(days));
}
@Test
- public void testTokenLengthInCalculateHmac() throws CertificateException, NoSuchAlgorithmException {
+ public void testTokenLengthInCalculateHmac() throws GeneralSecurityException {
List<String> badTokens = new ArrayList<>();
List<String> goodTokens = new ArrayList<>();
badTokens.add(null);
@@ -214,17 +177,13 @@ public class TlsHelperTest {
}
for (String token : goodTokens) {
- try {
- byte[] hmac = TlsHelper.calculateHMac(token, pubKey);
- assertTrue("HMAC length ok", hmac.length > 0);
- } catch (GeneralSecurityException e) {
- fail(e.getMessage());
- }
+ byte[] hmac = TlsHelper.calculateHMac(token, pubKey);
+ assertTrue(hmac.length > 0, "HMAC length OK");
}
}
@Test
- public void testGenerateSelfSignedCert() throws GeneralSecurityException, IOException, OperatorCreationException {
+ public void testGenerateSelfSignedCert() throws GeneralSecurityException {
String dn = "CN=testDN,O=testOrg";
X509Certificate x509Certificate = CertificateUtils.generateSelfSignedX509Certificate(TlsHelper.generateKeyPair(keyPairAlgorithm, keySize), dn, signingAlgorithm, days);
@@ -245,7 +204,7 @@ public class TlsHelperTest {
}
@Test
- public void testIssueCert() throws IOException, CertificateException, NoSuchAlgorithmException, OperatorCreationException, NoSuchProviderException, InvalidKeyException, SignatureException {
+ public void testIssueCert() throws IOException, CertificateException, NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, SignatureException {
X509Certificate issuer = loadCertificate(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("rootCert.crt")));
KeyPair issuerKeyPair = loadKeyPair(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("rootCert.key")));
@@ -273,81 +232,9 @@ public class TlsHelperTest {
@Test
public void testWriteKeyStoreSuccess() throws IOException, GeneralSecurityException {
- setUnlimitedCrypto(false);
String testPassword = "testPassword";
+ final KeyStore keyStore = setupKeystore();
assertEquals(testPassword, TlsHelper.writeKeyStore(keyStore, outputStreamFactory, file, testPassword, false));
- verify(keyStoreSpi, times(1)).engineStore(eq(tmpFileOutputStream), AdditionalMatchers.aryEq(testPassword.toCharArray()));
- }
-
- @Test
- public void testWriteKeyStoreFailure() throws IOException, GeneralSecurityException {
- setUnlimitedCrypto(false);
- String testPassword = "testPassword";
- IOException ioException = new IOException("Fail");
- doThrow(ioException).when(keyStoreSpi).engineStore(eq(tmpFileOutputStream), AdditionalMatchers.aryEq(testPassword.toCharArray()));
- try {
- TlsHelper.writeKeyStore(keyStore, outputStreamFactory, file, testPassword, true);
- fail("Expected " + ioException);
- } catch (IOException e) {
- assertEquals(ioException, e);
- }
- }
-
- @Test
- public void testWriteKeyStoreTruncate() throws IOException, GeneralSecurityException {
- setUnlimitedCrypto(false);
- String testPassword = "testPassword";
- String truncatedPassword = testPassword.substring(0, 7);
- IOException ioException = new IOException(TlsHelper.ILLEGAL_KEY_SIZE);
- doThrow(ioException).when(keyStoreSpi).engineStore(eq(tmpFileOutputStream), AdditionalMatchers.aryEq(testPassword.toCharArray()));
- assertEquals(truncatedPassword, TlsHelper.writeKeyStore(keyStore, outputStreamFactory, file, testPassword, true));
- verify(keyStoreSpi, times(1)).engineStore(eq(tmpFileOutputStream), AdditionalMatchers.aryEq(testPassword.toCharArray()));
- verify(keyStoreSpi, times(1)).engineStore(eq(tmpFileOutputStream), AdditionalMatchers.aryEq(truncatedPassword.toCharArray()));
- }
-
- @Test
- public void testWriteKeyStoreUnlimitedWontTruncate() throws GeneralSecurityException, IOException {
- setUnlimitedCrypto(true);
- String testPassword = "testPassword";
- IOException ioException = new IOException(TlsHelper.ILLEGAL_KEY_SIZE);
- doThrow(ioException).when(keyStoreSpi).engineStore(eq(tmpFileOutputStream), AdditionalMatchers.aryEq(testPassword.toCharArray()));
- try {
- TlsHelper.writeKeyStore(keyStore, outputStreamFactory, file, testPassword, true);
- fail("Expected " + ioException);
- } catch (IOException e) {
- assertEquals(ioException, e);
- }
- }
-
- @Test
- public void testWriteKeyStoreNoTruncate() throws IOException, GeneralSecurityException {
- setUnlimitedCrypto(false);
- String testPassword = "testPassword";
- IOException ioException = new IOException(TlsHelper.ILLEGAL_KEY_SIZE);
- doThrow(ioException).when(keyStoreSpi).engineStore(eq(tmpFileOutputStream), AdditionalMatchers.aryEq(testPassword.toCharArray()));
- try {
- TlsHelper.writeKeyStore(keyStore, outputStreamFactory, file, testPassword, false);
- fail("Expected " + GeneralSecurityException.class);
- } catch (GeneralSecurityException e) {
- assertTrue("Expected exception to contain " + TlsHelper.JCE_URL, e.getMessage().contains(TlsHelper.JCE_URL));
- }
- }
-
- @Test
- public void testWriteKeyStoreTruncateFailure() throws IOException, GeneralSecurityException {
- setUnlimitedCrypto(false);
- String testPassword = "testPassword";
- String truncatedPassword = testPassword.substring(0, 7);
- IOException ioException = new IOException(TlsHelper.ILLEGAL_KEY_SIZE);
- IOException ioException2 = new IOException(TlsHelper.ILLEGAL_KEY_SIZE);
- doThrow(ioException).when(keyStoreSpi).engineStore(eq(tmpFileOutputStream), AdditionalMatchers.aryEq(testPassword.toCharArray()));
- doThrow(ioException2).when(keyStoreSpi).engineStore(eq(tmpFileOutputStream), AdditionalMatchers.aryEq(truncatedPassword.toCharArray()));
- try {
- TlsHelper.writeKeyStore(keyStore, outputStreamFactory, file, testPassword, true);
- fail("Expected " + ioException2);
- } catch (IOException e) {
- assertEquals(ioException2, e);
- }
}
@Test
@@ -451,7 +338,7 @@ public class TlsHelperTest {
}
@Test
- public void testClientDnFilenameSlashes() throws Exception {
+ public void testClientDnFilenameSlashes() {
String clientDn = "OU=NiFi/Organisation,CN=testuser";
String escapedClientDn = TlsHelper.escapeFilename(CertificateUtils.reorderDn(clientDn));
@@ -459,7 +346,7 @@ public class TlsHelperTest {
}
@Test
- public void testClientDnFilenameSpecialChars() throws Exception {
+ public void testClientDnFilenameSpecialChars() {
String clientDn = "OU=NiFi#!Organisation,CN=testuser";
String escapedClientDn = TlsHelper.escapeFilename(CertificateUtils.reorderDn(clientDn));
@@ -467,18 +354,16 @@ public class TlsHelperTest {
}
private KeyStore setupKeystore() throws CertificateException, NoSuchAlgorithmException, IOException, KeyStoreException {
-
KeyStore ks = KeyStore.getInstance("JKS");
- InputStream readStream = getClass().getClassLoader().getResourceAsStream("keystore.jks");
- ks.load(readStream, password.toCharArray());
-
+ try (InputStream readStream = getClass().getClassLoader().getResourceAsStream("keystore.jks")) {
+ ks.load(readStream, password.toCharArray());
+ }
return ks;
}
@Test
- public void testOutputToFileTwoCertsAsPem() throws IOException, CertificateException, NoSuchAlgorithmException, KeyStoreException {
+ public void testOutputToFileTwoCertsAsPem(@TempDir final File folder) throws IOException, CertificateException, NoSuchAlgorithmException, KeyStoreException {
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
- File folder = tempFolder.newFolder("splitKeystoreOutputDir");
KeyStore keyStore = setupKeystore();
HashMap<String, Certificate> certs = TlsHelper.extractCerts(keyStore);
@@ -486,28 +371,31 @@ public class TlsHelperTest {
assertEquals(folder.listFiles().length, 2);
- for(File file : folder.listFiles()) {
+ for (File file : folder.listFiles()) {
X509Certificate certFromFile = loadCertificate(file);
assertTrue(certs.containsValue(certFromFile));
X509Certificate originalCert = (X509Certificate) certs.get(file.getName().split("\\.")[0]);
- assertTrue(originalCert.equals(certFromFile));
+ assertEquals(originalCert, certFromFile);
assertArrayEquals(originalCert.getSignature(), certFromFile.getSignature());
+ FileUtils.deleteFile(file, false);
}
}
// Keystore contains two certificates, but one key. This is to test the edge case where a certificate does not have a key.
@Test
- public void testOutputToFileOneKeyAsPem() throws IOException, CertificateException, NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException {
- File folder = tempFolder.newFolder("splitKeystoreOutputDir");
+ public void testOutputToFileOneKeyAsPem(@TempDir final File folder) throws IOException, CertificateException, NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException {
KeyStore keyStore = setupKeystore();
HashMap<String, Key> keys = TlsHelper.extractKeys(keyStore, password.toCharArray());
TlsHelper.outputKeysAsPem(keys, folder, ".key");
- for(File file : folder.listFiles()) {
- BufferedReader br = new BufferedReader(new FileReader(file));
- PEMParser pemParser = new PEMParser(br);
- PEMKeyPair key = (PEMKeyPair) pemParser.readObject();
- assertArrayEquals(keys.get(file.getName().split("\\.")[0]).getEncoded(), key.getPrivateKeyInfo().getEncoded());
+ for (File file : folder.listFiles()) {
+ try (BufferedReader br = new BufferedReader(new FileReader(file))) {
+ PEMParser pemParser = new PEMParser(br);
+ PEMKeyPair key = (PEMKeyPair) pemParser.readObject();
+ assertArrayEquals(keys.get(file.getName().split("\\.")[0]).getEncoded(), key.getPrivateKeyInfo().getEncoded());
+ } finally {
+ FileUtils.deleteFile(file, false);
+ }
}
}
@@ -526,6 +414,4 @@ public class TlsHelperTest {
assertEquals(1, keys.size());
keys.forEach((String alias, Key key) -> assertEquals("PKCS#8", key.getFormat()));
}
-
-
}