Repository: knox Updated Branches: refs/heads/master 2e5c0866e -> 4df88bb80
KNOX-1623 - Fix jenkins failure and minor doc changes Project: http://git-wip-us.apache.org/repos/asf/knox/repo Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/4df88bb8 Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/4df88bb8 Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/4df88bb8 Branch: refs/heads/master Commit: 4df88bb80d2785febc5f11de154355a30c2a66e3 Parents: 2e5c086 Author: Sandeep More <[email protected]> Authored: Thu Dec 6 10:21:19 2018 -0500 Committer: Sandeep More <[email protected]> Committed: Thu Dec 6 10:22:33 2018 -0500 ---------------------------------------------------------------------- .../apache/knox/gateway/shell/KnoxSession.java | 10 +-- .../knox/gateway/SecureKnoxShellTest.java | 73 ++++---------------- 2 files changed, 19 insertions(+), 64 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/knox/blob/4df88bb8/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSession.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSession.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSession.java index ca2672c..b62055e 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSession.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSession.java @@ -137,8 +137,8 @@ public class KnoxSession implements Closeable { * @param jaasConf jaas configuration (optional- can be null) * @param krb5Conf kerberos configuration (optional - can be null) * @param debug enable debug messages - * @return - * @throws URISyntaxException + * @return KnoxSession + * @throws URISyntaxException exception in case of malformed url * @since 1.3.0 */ public static KnoxSession kerberosLogin(final String url, @@ -160,9 +160,9 @@ public class KnoxSession implements Closeable { * Support kerberos authentication. * This method assumed kinit has already been called * and the token is persisted on disk. - * @param url - * @return - * @throws URISyntaxException + * @param url Gateway url + * @return KnoxSession + * @throws URISyntaxException exception in case of malformed url * @since 1.3.0 */ public static KnoxSession kerberosLogin(final String url) http://git-wip-us.apache.org/repos/asf/knox/blob/4df88bb8/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/knox/gateway/SecureKnoxShellTest.java ---------------------------------------------------------------------- diff --git a/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/knox/gateway/SecureKnoxShellTest.java b/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/knox/gateway/SecureKnoxShellTest.java index 817250e..d562e46 100644 --- a/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/knox/gateway/SecureKnoxShellTest.java +++ b/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/knox/gateway/SecureKnoxShellTest.java @@ -43,7 +43,6 @@ import java.io.OutputStreamWriter; import java.io.Writer; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; import java.util.Locale; import java.util.Properties; @@ -57,17 +56,7 @@ import static org.junit.Assert.assertTrue; public class SecureKnoxShellTest { private static final String SCRIPT = "SecureWebHdfsPutGet.groovy"; - /** - * 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. - * - */ - private static Object kdc; + private static MiniKdc kdc; private static String userName; private static HdfsConfiguration configuration; private static int nameNodeHttpPort; @@ -81,26 +70,12 @@ public class SecureKnoxShellTest { private static MiniDFSCluster miniDFSCluster; private static GatewayTestDriver driver = new GatewayTestDriver(); - /** - * 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; - public SecureKnoxShellTest() { super(); } @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()); baseDir = new File( KeyStoreTestUtil.getClasspathDir(SecureKnoxShellTest.class)); ticketCache = new File( @@ -126,7 +101,7 @@ public class SecureKnoxShellTest { private static void initKdc() throws Exception { final Properties kdcConf = MiniKdc.createConf(); kdc = new MiniKdc(kdcConf, baseDir); - ((MiniKdc) kdc).start(); + kdc.start(); userName = UserGroupInformation .createUserForTesting("guest", new String[] { "users" }).getUserName(); @@ -134,26 +109,30 @@ public class SecureKnoxShellTest { keytab = keytabFile.getAbsolutePath(); // Windows will not reverse name lookup "127.0.0.1" to "localhost". final String krbInstance = Path.WINDOWS ? "127.0.0.1" : "localhost"; - ((MiniKdc) kdc).createPrincipal(keytabFile, userName + "/" + krbInstance, + kdc.createPrincipal(keytabFile, userName + "/" + krbInstance, "HTTP/" + krbInstance); hdfsPrincipal = - userName + "/" + krbInstance + "@" + ((MiniKdc) kdc).getRealm(); - spnegoPrincipal = "HTTP/" + krbInstance + "@" + ((MiniKdc) kdc).getRealm(); + userName + "/" + krbInstance + "@" + kdc.getRealm(); + spnegoPrincipal = "HTTP/" + krbInstance + "@" + kdc.getRealm(); - krb5conf = ((MiniKdc) kdc).getKrb5conf().getAbsolutePath(); + krb5conf = kdc.getKrb5conf().getAbsolutePath(); } @AfterClass public static void cleanupSuite() throws Exception { - /* No need to clean up if we did not start anything */ - if (isJreVersionOK()) { - ((MiniKdc) kdc).stop(); - Files.deleteIfExists(ticketCache.toPath()); + + if(kdc != null) { + kdc.stop(); + } + if(miniDFSCluster != null) { miniDFSCluster.shutdown(); + } + if(driver != null) { driver.cleanup(); } + } private static File setupJaasConf(File baseDir, String keyTabFile, @@ -268,28 +247,6 @@ public class SecureKnoxShellTest { .configure(ClassLoader.getSystemResource("log4j.properties")); } - /** - * Check whether java version is >= {@link #JAVA_MAJOR_VERSION_FOR_TEST} - * - * @return - * @since 0.10 - */ - 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; - } - - /** - * Test Kerberos login using KnoxShell using keytab. - * - * @throws Exception - */ @Test public void testCachedTicket() throws Exception { setupLogging(); @@ -299,8 +256,6 @@ public class SecureKnoxShellTest { /** * Do the heavy lifting here. - * - * @throws Exception */ private void webhdfsPutGet() throws Exception { DistributedFileSystem fileSystem = miniDFSCluster.getFileSystem();
