You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by mo...@apache.org on 2017/02/06 20:09:24 UTC
knox git commit: KNOX-769 - Fix SecureClusterTest for Java 1.7
Repository: knox
Updated Branches:
refs/heads/master 47c1f4ac2 -> 8eaf3bbf1
KNOX-769 - Fix SecureClusterTest for Java 1.7
Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/8eaf3bbf
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/8eaf3bbf
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/8eaf3bbf
Branch: refs/heads/master
Commit: 8eaf3bbf12c81452c1e0c30fdcd6fefb634b2bf6
Parents: 47c1f4a
Author: Sandeep More <mo...@apache.org>
Authored: Mon Feb 6 15:08:33 2017 -0500
Committer: Sandeep More <mo...@apache.org>
Committed: Mon Feb 6 15:08:33 2017 -0500
----------------------------------------------------------------------
.../hadoop/gateway/SecureClusterTest.java | 70 +++++++++++++++++---
1 file changed, 60 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/knox/blob/8eaf3bbf/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/SecureClusterTest.java
----------------------------------------------------------------------
diff --git a/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/SecureClusterTest.java b/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/SecureClusterTest.java
index 33e5589..62dc734 100644
--- a/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/SecureClusterTest.java
+++ b/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/SecureClusterTest.java
@@ -77,7 +77,19 @@ import static org.junit.Assert.assertTrue;
public class SecureClusterTest {
private static MiniDFSCluster miniDFSCluster;
- private static MiniKdc kdc;
+
+ /**
+ * Referring {@link MiniKdc} as {@link Object} to prevent the class loader
+ * from trying to load it before @BeforeClass annotation is called. Need to
+ * play this game because {@link MiniKdc} is not compatible with Java 7 so if
+ * we detect Java 7 we quit the test.
+ * <p>
+ * As result we need to up cast this object to {@link MiniKdc} every place we
+ * use it.
+ *
+ * @since 0.10
+ */
+ private static Object kdc;
private static HdfsConfiguration configuration;
private static int nameNodeHttpPort;
private static String userName;
@@ -85,8 +97,22 @@ public class SecureClusterTest {
private static GatewayTestDriver driver = new GatewayTestDriver();
private static File baseDir;
+ /**
+ * Test should run if java major version is greater or equal to this property.
+ *
+ * @since 0.10
+ */
+ private static int JAVA_MAJOR_VERSION_FOR_TEST = 8;
+
@BeforeClass
public static void setupSuite() throws Exception {
+
+ /*
+ * Run the test only if the jre version matches the one we want, see
+ * KNOX-769
+ */
+ org.junit.Assume.assumeTrue(isJreVersionOK());
+
nameNodeHttpPort = TestUtils.findFreePort();
configuration = new HdfsConfiguration();
baseDir = new File(KeyStoreTestUtil.getClasspathDir(SecureClusterTest.class));
@@ -101,10 +127,11 @@ public class SecureClusterTest {
.build();
}
+
private static void initKdc() throws Exception {
Properties kdcConf = MiniKdc.createConf();
kdc = new MiniKdc(kdcConf, baseDir);
- kdc.start();
+ ((MiniKdc)kdc).start();
configuration = new HdfsConfiguration();
SecurityUtil.setAuthenticationMethod(UserGroupInformation.AuthenticationMethod.KERBEROS, configuration);
@@ -115,9 +142,9 @@ public class SecureClusterTest {
String keytab = keytabFile.getAbsolutePath();
// Windows will not reverse name lookup "127.0.0.1" to "localhost".
String krbInstance = Path.WINDOWS ? "127.0.0.1" : "localhost";
- kdc.createPrincipal(keytabFile, userName + "/" + krbInstance, "HTTP/" + krbInstance);
- String hdfsPrincipal = userName + "/" + krbInstance + "@" + kdc.getRealm();
- String spnegoPrincipal = "HTTP/" + krbInstance + "@" + kdc.getRealm();
+ ((MiniKdc)kdc).createPrincipal(keytabFile, userName + "/" + krbInstance, "HTTP/" + krbInstance);
+ String hdfsPrincipal = userName + "/" + krbInstance + "@" + ((MiniKdc)kdc).getRealm();
+ String spnegoPrincipal = "HTTP/" + krbInstance + "@" + ((MiniKdc)kdc).getRealm();
configuration.set(DFS_NAMENODE_KERBEROS_PRINCIPAL_KEY, hdfsPrincipal);
configuration.set(DFS_NAMENODE_KEYTAB_FILE_KEY, keytab);
@@ -153,7 +180,7 @@ public class SecureClusterTest {
private static void setupKnox(String keytab, String hdfsPrincipal) throws Exception {
//kerberos setup for http client
File jaasConf = setupJaasConf(baseDir, keytab, hdfsPrincipal);
- System.setProperty("java.security.krb5.conf", kdc.getKrb5conf().getAbsolutePath());
+ System.setProperty("java.security.krb5.conf", ((MiniKdc)kdc).getKrb5conf().getAbsolutePath());
System.setProperty("java.security.auth.login.config", jaasConf.getAbsolutePath());
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
System.setProperty("sun.security.krb5.debug", "true");
@@ -163,7 +190,7 @@ public class SecureClusterTest {
GatewayTestConfig config = new GatewayTestConfig();
config.setGatewayPath( "gateway" );
config.setHadoopKerberosSecured(true);
- config.setKerberosConfig(kdc.getKrb5conf().getAbsolutePath());
+ config.setKerberosConfig(((MiniKdc)kdc).getKrb5conf().getAbsolutePath());
config.setKerberosLoginConfig(jaasConf.getAbsolutePath());
driver.setResourceBase(SecureClusterTest.class);
driver.setupLdap(0);
@@ -172,9 +199,13 @@ public class SecureClusterTest {
@AfterClass
public static void cleanupSuite() throws Exception {
- kdc.stop();
- miniDFSCluster.shutdown();
- driver.cleanup();
+ /* No need to clean up if we did not start anything */
+ if (isJreVersionOK()) {
+ ((MiniKdc) kdc).stop();
+ miniDFSCluster.shutdown();
+ driver.cleanup();
+ }
+
}
@Test
@@ -296,4 +327,23 @@ public class SecureClusterTest {
return xml;
}
+ /**
+ * Check whether java version is >= {@link #JAVA_MAJOR_VERSION_FOR_TEST}
+ *
+ * @since 0.10
+ * @return
+ */
+ public static boolean isJreVersionOK() {
+
+ final String jreVersion = System.getProperty("java.version");
+ int majorVersion = Integer.parseInt(String.valueOf(jreVersion.charAt(2)));
+
+ if (majorVersion >= JAVA_MAJOR_VERSION_FOR_TEST) {
+ return true;
+ }
+
+ return false;
+
+ }
+
}