mirror of
https://github.com/apache/nifi.git
synced 2025-02-06 01:58:32 +00:00
NIFI-6337 Resolved groovy unit test execution problems in nifi-properties-loader and fixed failing unit tests.
Signed-off-by: Matthew Burgess <mattyb149@apache.org> This closes #3508
This commit is contained in:
parent
a951a8ec61
commit
a9d1dd7b08
@ -1,4 +1,5 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
@ -47,4 +48,28 @@
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<!-- Required to run Groovy tests without any Java tests -->
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>1.5</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add-test-source</id>
|
||||
<phase>generate-test-sources</phase>
|
||||
<goals>
|
||||
<goal>add-test-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>src/test/groovy</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -17,7 +17,6 @@
|
||||
package org.apache.nifi.properties
|
||||
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider
|
||||
import org.bouncycastle.util.encoders.DecoderException
|
||||
import org.bouncycastle.util.encoders.Hex
|
||||
import org.junit.After
|
||||
import org.junit.Assume
|
||||
@ -302,9 +301,10 @@ class AESSensitivePropertyProviderTest extends GroovyTestCase {
|
||||
SensitivePropertyProvider spp = new AESSensitivePropertyProvider(Hex.decode(getKeyOfSize(keySize)))
|
||||
logger.info("Initialized ${spp.name} with key size ${keySize}")
|
||||
String cipherText = spp.protect(PLAINTEXT)
|
||||
|
||||
// Remove the IV from the "complete" cipher text
|
||||
final String MISSING_IV_CIPHER_TEXT = cipherText[18..-1]
|
||||
logger.info("Manipulated ${cipherText} to\n${MISSING_IV_CIPHER_TEXT.padLeft(163)}")
|
||||
logger.info("Manipulated ${cipherText} to\n${MISSING_IV_CIPHER_TEXT.padLeft(172)}")
|
||||
|
||||
def msg = shouldFail(IllegalArgumentException) {
|
||||
spp.unprotect(MISSING_IV_CIPHER_TEXT)
|
||||
@ -313,9 +313,9 @@ class AESSensitivePropertyProviderTest extends GroovyTestCase {
|
||||
|
||||
// Remove the IV from the "complete" cipher text but keep the delimiter
|
||||
final String MISSING_IV_CIPHER_TEXT_WITH_DELIMITER = cipherText[16..-1]
|
||||
logger.info("Manipulated ${cipherText} to\n${MISSING_IV_CIPHER_TEXT_WITH_DELIMITER.padLeft(163)}")
|
||||
logger.info("Manipulated ${cipherText} to\n${MISSING_IV_CIPHER_TEXT_WITH_DELIMITER.padLeft(172)}")
|
||||
|
||||
def msgWithDelimiter = shouldFail(DecoderException) {
|
||||
def msgWithDelimiter = shouldFail(IllegalArgumentException) {
|
||||
spp.unprotect(MISSING_IV_CIPHER_TEXT_WITH_DELIMITER)
|
||||
}
|
||||
logger.expected("${msgWithDelimiter} for keySize ${keySize} and cipher text [${MISSING_IV_CIPHER_TEXT_WITH_DELIMITER}]")
|
||||
@ -324,7 +324,7 @@ class AESSensitivePropertyProviderTest extends GroovyTestCase {
|
||||
assert msg == "The cipher text does not contain the delimiter || -- it should be of the form Base64(IV) || Base64(cipherText)"
|
||||
|
||||
// Assert
|
||||
assert msgWithDelimiter =~ "unable to decode base64 string"
|
||||
assert msgWithDelimiter == "The IV (0 bytes) must be at least 12 bytes"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpOnce() throws Exception {
|
||||
static void setUpOnce() throws Exception {
|
||||
Security.addProvider(new BouncyCastleProvider())
|
||||
|
||||
logger.metaClass.methodMissing = { String name, args ->
|
||||
@ -76,11 +76,11 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
void tearDown() throws Exception {
|
||||
// Clear the sensitive property providers between runs
|
||||
// if (ProtectedNiFiProperties.@localProviderCache) {
|
||||
// ProtectedNiFiProperties.@localProviderCache = [:]
|
||||
@ -89,14 +89,14 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownOnce() {
|
||||
static void tearDownOnce() {
|
||||
if (originalPropertiesPath) {
|
||||
System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, originalPropertiesPath)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorShouldCreateNewInstance() throws Exception {
|
||||
void testConstructorShouldCreateNewInstance() throws Exception {
|
||||
// Arrange
|
||||
|
||||
// Act
|
||||
@ -108,7 +108,7 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldCreateInstanceWithKey() throws Exception {
|
||||
void testShouldCreateInstanceWithKey() throws Exception {
|
||||
// Arrange
|
||||
|
||||
// Act
|
||||
@ -120,7 +120,7 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldGetDefaultProviderKey() throws Exception {
|
||||
void testShouldGetDefaultProviderKey() throws Exception {
|
||||
// Arrange
|
||||
final String EXPECTED_PROVIDER_KEY = "aes/gcm/${Cipher.getMaxAllowedKeyLength("AES") > 128 ? 256 : 128}"
|
||||
logger.info("Expected provider key: ${EXPECTED_PROVIDER_KEY}")
|
||||
@ -133,7 +133,7 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldInitializeSensitivePropertyProviderFactory() throws Exception {
|
||||
void testShouldInitializeSensitivePropertyProviderFactory() throws Exception {
|
||||
// Arrange
|
||||
NiFiPropertiesLoader niFiPropertiesLoader = new NiFiPropertiesLoader()
|
||||
|
||||
@ -145,7 +145,7 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldLoadUnprotectedPropertiesFromFile() throws Exception {
|
||||
void testShouldLoadUnprotectedPropertiesFromFile() throws Exception {
|
||||
// Arrange
|
||||
File unprotectedFile = new File("src/test/resources/conf/nifi.properties")
|
||||
NiFiPropertiesLoader niFiPropertiesLoader = new NiFiPropertiesLoader()
|
||||
@ -161,7 +161,7 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldNotLoadUnprotectedPropertiesFromNullFile() throws Exception {
|
||||
void testShouldNotLoadUnprotectedPropertiesFromNullFile() throws Exception {
|
||||
// Arrange
|
||||
NiFiPropertiesLoader niFiPropertiesLoader = new NiFiPropertiesLoader()
|
||||
|
||||
@ -176,7 +176,7 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldNotLoadUnprotectedPropertiesFromMissingFile() throws Exception {
|
||||
void testShouldNotLoadUnprotectedPropertiesFromMissingFile() throws Exception {
|
||||
// Arrange
|
||||
File missingFile = new File("src/test/resources/conf/nifi_missing.properties")
|
||||
assert !missingFile.exists()
|
||||
@ -194,7 +194,7 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldNotLoadUnprotectedPropertiesFromUnreadableFile() throws Exception {
|
||||
void testShouldNotLoadUnprotectedPropertiesFromUnreadableFile() throws Exception {
|
||||
// Arrange
|
||||
File unreadableFile = new File("src/test/resources/conf/nifi_no_permissions.properties")
|
||||
Files.setPosixFilePermissions(unreadableFile.toPath(), [] as Set)
|
||||
@ -216,7 +216,7 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldLoadUnprotectedPropertiesFromPath() throws Exception {
|
||||
void testShouldLoadUnprotectedPropertiesFromPath() throws Exception {
|
||||
// Arrange
|
||||
File unprotectedFile = new File("src/test/resources/conf/nifi.properties")
|
||||
NiFiPropertiesLoader niFiPropertiesLoader = new NiFiPropertiesLoader()
|
||||
@ -232,7 +232,7 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldLoadUnprotectedPropertiesFromProtectedFile() throws Exception {
|
||||
void testShouldLoadUnprotectedPropertiesFromProtectedFile() throws Exception {
|
||||
// Arrange
|
||||
File protectedFile = new File("src/test/resources/conf/nifi_with_sensitive_properties_protected_aes.properties")
|
||||
NiFiPropertiesLoader niFiPropertiesLoader = NiFiPropertiesLoader.withKey(KEY_HEX)
|
||||
@ -272,7 +272,7 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldExtractKeyFromBootstrapFile() throws Exception {
|
||||
void testShouldExtractKeyFromBootstrapFile() throws Exception {
|
||||
// Arrange
|
||||
def defaultNiFiPropertiesFilePath = "src/test/resources/bootstrap_tests/conf/nifi.properties"
|
||||
System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, defaultNiFiPropertiesFilePath)
|
||||
@ -285,7 +285,7 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldNotExtractKeyFromBootstrapFileWithoutKeyLine() throws Exception {
|
||||
void testShouldNotExtractKeyFromBootstrapFileWithoutKeyLine() throws Exception {
|
||||
// Arrange
|
||||
def defaultNiFiPropertiesFilePath = "src/test/resources/bootstrap_tests/missing_key_line/nifi.properties"
|
||||
System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, defaultNiFiPropertiesFilePath)
|
||||
@ -298,7 +298,7 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldNotExtractKeyFromBootstrapFileWithoutKey() throws Exception {
|
||||
void testShouldNotExtractKeyFromBootstrapFileWithoutKey() throws Exception {
|
||||
// Arrange
|
||||
def defaultNiFiPropertiesFilePath = "src/test/resources/bootstrap_tests/missing_key_line/nifi.properties"
|
||||
System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, defaultNiFiPropertiesFilePath)
|
||||
@ -311,7 +311,7 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldNotExtractKeyFromMissingBootstrapFile() throws Exception {
|
||||
void testShouldNotExtractKeyFromMissingBootstrapFile() throws Exception {
|
||||
// Arrange
|
||||
def defaultNiFiPropertiesFilePath = "src/test/resources/bootstrap_tests/missing_bootstrap/nifi.properties"
|
||||
System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, defaultNiFiPropertiesFilePath)
|
||||
@ -327,7 +327,7 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldNotExtractKeyFromUnreadableBootstrapFile() throws Exception {
|
||||
void testShouldNotExtractKeyFromUnreadableBootstrapFile() throws Exception {
|
||||
// Arrange
|
||||
File unreadableFile = new File("src/test/resources/bootstrap_tests/unreadable_bootstrap/bootstrap.conf")
|
||||
Set<PosixFilePermission> originalPermissions = Files.getPosixFilePermissions(unreadableFile.toPath())
|
||||
@ -352,7 +352,7 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
|
||||
@Ignore("Unreadable conf directory breaks build")
|
||||
@Test
|
||||
public void testShouldNotExtractKeyFromUnreadableConfDir() throws Exception {
|
||||
void testShouldNotExtractKeyFromUnreadableConfDir() throws Exception {
|
||||
// Arrange
|
||||
File unreadableDir = new File("src/test/resources/bootstrap_tests/unreadable_conf")
|
||||
Set<PosixFilePermission> originalPermissions = Files.getPosixFilePermissions(unreadableDir.toPath())
|
||||
@ -376,7 +376,7 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldLoadUnprotectedPropertiesFromProtectedDefaultFileAndUseBootstrapKey() throws Exception {
|
||||
void testShouldLoadUnprotectedPropertiesFromProtectedDefaultFileAndUseBootstrapKey() throws Exception {
|
||||
// Arrange
|
||||
File protectedFile = new File("src/test/resources/bootstrap_tests/conf/nifi_with_sensitive_properties_protected_aes.properties")
|
||||
System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, protectedFile.path)
|
||||
@ -402,7 +402,7 @@ class NiFiPropertiesLoaderGroovyTest extends GroovyTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldUpdateKeyInFactory() throws Exception {
|
||||
void testShouldUpdateKeyInFactory() throws Exception {
|
||||
// Arrange
|
||||
File originalKeyFile = new File("src/test/resources/conf/nifi_with_sensitive_properties_protected_aes_128.properties")
|
||||
File passwordKeyFile = new File("src/test/resources/conf/nifi_with_sensitive_properties_protected_aes_128_password.properties")
|
||||
|
@ -74,7 +74,7 @@ nifi.sensitive.props.key=6WUpex+VZiN05LXu||joWJMuoSzYniEC7IAoingTimlG7+RGk8I2irl
|
||||
nifi.sensitive.props.key.protected=aes/gcm/128
|
||||
nifi.sensitive.props.algorithm=PBEWITHMD5AND256BITAES-CBC-OPENSSL
|
||||
nifi.sensitive.props.provider=BC
|
||||
nifi.sensitive.props.additional.keys=nifi.ui.banner.text
|
||||
nifi.sensitive.props.additional.keys=nifi.ui.banner.text, nifi.version
|
||||
|
||||
nifi.security.keystore=/path/to/keystore.jks
|
||||
nifi.security.keystoreType=JKS
|
||||
|
Loading…
x
Reference in New Issue
Block a user