mirror of https://github.com/apache/nifi.git
NIFI-11611 Refactored TlsConfigurationTest from Groovy to Java
This closes #7309 Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
parent
eca4f5d68f
commit
2f8e5b27b0
|
@ -1,90 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.apache.nifi.security.util
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeAll
|
|
||||||
import org.junit.jupiter.api.Test
|
|
||||||
import org.slf4j.Logger
|
|
||||||
import org.slf4j.LoggerFactory
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue
|
|
||||||
|
|
||||||
class TlsConfigurationTest {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(TlsConfigurationTest.class)
|
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
static void setUpOnce() {
|
|
||||||
logger.metaClass.methodMissing = { String name, args ->
|
|
||||||
logger.info("[${name?.toUpperCase()}] ${(args as List).join(" ")}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testShouldParseJavaVersion() {
|
|
||||||
// Arrange
|
|
||||||
def possibleVersions = ["1.5.0", "1.6.0", "1.7.0.123", "1.8.0.231", "9.0.1", "10.1.2", "11.2.3", "12.3.456"]
|
|
||||||
|
|
||||||
// Act
|
|
||||||
def majorVersions = possibleVersions.collect { String version ->
|
|
||||||
logger.debug("Attempting to determine major version of ${version}")
|
|
||||||
TlsConfiguration.parseJavaVersion(version)
|
|
||||||
}
|
|
||||||
logger.info("Major versions: ${majorVersions}")
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
assertTrue(majorVersions.stream()
|
|
||||||
.allMatch(num -> num >= 5 && num <= 12))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testShouldGetCurrentSupportedTlsProtocolVersions() {
|
|
||||||
// Arrange
|
|
||||||
int javaMajorVersion = TlsConfiguration.getJavaVersion()
|
|
||||||
logger.debug("Running on Java version: ${javaMajorVersion}")
|
|
||||||
|
|
||||||
// Act
|
|
||||||
def tlsVersions = TlsConfiguration.getCurrentSupportedTlsProtocolVersions()
|
|
||||||
logger.info("Supported protocol versions for ${javaMajorVersion}: ${tlsVersions}")
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
if (javaMajorVersion < 11) {
|
|
||||||
assertArrayEquals(new String[]{"TLSv1.2"}, tlsVersions)
|
|
||||||
} else {
|
|
||||||
assertArrayEquals(new String[]{"TLSv1.3", "TLSv1.2"}, tlsVersions)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testShouldGetMaxCurrentSupportedTlsProtocolVersion() {
|
|
||||||
// Arrange
|
|
||||||
int javaMajorVersion = TlsConfiguration.getJavaVersion()
|
|
||||||
logger.debug("Running on Java version: ${javaMajorVersion}")
|
|
||||||
|
|
||||||
// Act
|
|
||||||
def tlsVersion = TlsConfiguration.getHighestCurrentSupportedTlsProtocolVersion()
|
|
||||||
logger.info("Highest supported protocol version for ${javaMajorVersion}: ${tlsVersion}")
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
if (javaMajorVersion < 11) {
|
|
||||||
assertEquals("TLSv1.2", tlsVersion)
|
|
||||||
} else {
|
|
||||||
assertEquals("TLSv1.3", tlsVersion)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.nifi.security.util;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.condition.EnabledForJreRange;
|
||||||
|
import org.junit.jupiter.api.condition.JRE;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
public class TlsConfigurationTest {
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@ValueSource(strings = {"1.5.0", "1.6.0", "1.7.0.123", "1.8.0.231", "9.0.1", "10.1.2", "11.2.3", "12.3.456"})
|
||||||
|
public void testParseJavaVersion(String version) {
|
||||||
|
int javaVersion = TlsConfiguration.parseJavaVersion(version);
|
||||||
|
|
||||||
|
assertTrue(javaVersion >= 5 && javaVersion <= 12);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnabledForJreRange(min = JRE.JAVA_11)
|
||||||
|
public void testGeSupportedTlsProtocolVersionsForJava11AndHigher() {
|
||||||
|
assertArrayEquals(new String[]{"TLSv1.3", "TLSv1.2"},
|
||||||
|
TlsConfiguration.getCurrentSupportedTlsProtocolVersions());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnabledForJreRange(max = JRE.JAVA_10)
|
||||||
|
public void testGeSupportedTlsProtocolVersionsForJava10AndLower() {
|
||||||
|
assertArrayEquals(new String[]{"TLSv1.2"},
|
||||||
|
TlsConfiguration.getCurrentSupportedTlsProtocolVersions());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnabledForJreRange(min = JRE.JAVA_11)
|
||||||
|
public void testGetHighestCurrentSupportedTlsProtocolVersionForJava11AndHigher() {
|
||||||
|
assertEquals("TLSv1.3", TlsConfiguration.getHighestCurrentSupportedTlsProtocolVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnabledForJreRange(max = JRE.JAVA_10)
|
||||||
|
public void testGetHighestCurrentSupportedTlsProtocolVersionForJava10AndLower() {
|
||||||
|
assertEquals("TLSv1.2", TlsConfiguration.getHighestCurrentSupportedTlsProtocolVersion());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue