From 302d9a0a0dac721775a88f804a18d5224c0cd497 Mon Sep 17 00:00:00 2001 From: cnauroth Date: Mon, 8 Sep 2014 09:29:19 -0700 Subject: [PATCH] Credential Provider related Unit Test Failure on Windows. Contributed by Xiaoyu Yao. --- .../hadoop-common/CHANGES.txt | 3 +++ .../crypto/key/TestKeyProviderFactory.java | 24 ++++++++++--------- .../security/TestLdapGroupsMapping.java | 4 +++- .../alias/TestCredentialProviderFactory.java | 17 ++++++------- .../hadoop/security/ssl/KeyStoreTestUtil.java | 4 +++- .../hadoop/security/ssl/TestSSLFactory.java | 4 +++- 6 files changed, 34 insertions(+), 22 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index c77fddc789..fe011fd039 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -768,6 +768,9 @@ Release 2.6.0 - UNRELEASED HADOOP-11069. KMSClientProvider should use getAuthenticationMethod() to determine if in proxyuser mode or not. (tucu) + HADOOP-11073. Credential Provider related Unit Tests Failure on Windows. + (Xiaoyu Yao via cnauroth) + Release 2.5.1 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyProviderFactory.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyProviderFactory.java index 8c4c7b328b..8fb661d452 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyProviderFactory.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/key/TestKeyProviderFactory.java @@ -55,18 +55,18 @@ public void setup() { @Test public void testFactory() throws Exception { Configuration conf = new Configuration(); + final String userUri = UserProvider.SCHEME_NAME + ":///"; + final Path jksPath = new Path(tmpDir.toString(), "test.jks"); + final String jksUri = JavaKeyStoreProvider.SCHEME_NAME + + "://file" + jksPath.toUri().toString(); conf.set(KeyProviderFactory.KEY_PROVIDER_PATH, - UserProvider.SCHEME_NAME + ":///," + - JavaKeyStoreProvider.SCHEME_NAME + "://file" + tmpDir + "/test.jks"); + userUri + "," + jksUri); List providers = KeyProviderFactory.getProviders(conf); assertEquals(2, providers.size()); assertEquals(UserProvider.class, providers.get(0).getClass()); assertEquals(JavaKeyStoreProvider.class, providers.get(1).getClass()); - assertEquals(UserProvider.SCHEME_NAME + - ":///", providers.get(0).toString()); - assertEquals(JavaKeyStoreProvider.SCHEME_NAME + - "://file" + tmpDir + "/test.jks", - providers.get(1).toString()); + assertEquals(userUri, providers.get(0).toString()); + assertEquals(jksUri, providers.get(1).toString()); } @Test @@ -207,8 +207,9 @@ public void testUserProvider() throws Exception { @Test public void testJksProvider() throws Exception { Configuration conf = new Configuration(); + final Path jksPath = new Path(tmpDir.toString(), "test.jks"); final String ourUrl = - JavaKeyStoreProvider.SCHEME_NAME + "://file" + tmpDir + "/test.jks"; + JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri(); File file = new File(tmpDir, "test.jks"); file.delete(); @@ -317,8 +318,9 @@ public void checkPermissionRetention(Configuration conf, String ourUrl, Path pat @Test public void testJksProviderPasswordViaConfig() throws Exception { Configuration conf = new Configuration(); + final Path jksPath = new Path(tmpDir.toString(), "test.jks"); final String ourUrl = - JavaKeyStoreProvider.SCHEME_NAME + "://file" + tmpDir + "/test.jks"; + JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri(); File file = new File(tmpDir, "test.jks"); file.delete(); try { @@ -360,8 +362,8 @@ public void testJksProviderPasswordViaConfig() throws Exception { @Test public void testGetProviderViaURI() throws Exception { Configuration conf = new Configuration(false); - URI uri = new URI(JavaKeyStoreProvider.SCHEME_NAME + "://file" + tmpDir + - "/test.jks"); + final Path jksPath = new Path(tmpDir.toString(), "test.jks"); + URI uri = new URI(JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri()); KeyProvider kp = KeyProviderFactory.get(uri, conf); Assert.assertNotNull(kp); Assert.assertEquals(JavaKeyStoreProvider.class, kp.getClass()); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMapping.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMapping.java index 95cbc0ae20..a021a8afd4 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMapping.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMapping.java @@ -40,6 +40,7 @@ import javax.naming.directory.SearchResult; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.Path; import org.apache.hadoop.security.alias.CredentialProvider; import org.apache.hadoop.security.alias.CredentialProviderFactory; import org.apache.hadoop.security.alias.JavaKeyStoreProvider; @@ -165,8 +166,9 @@ public void testConfGetPassword() throws Exception { File testDir = new File(System.getProperty("test.build.data", "target/test-dir")); Configuration conf = new Configuration(); + final Path jksPath = new Path(testDir.toString(), "test.jks"); final String ourUrl = - JavaKeyStoreProvider.SCHEME_NAME + "://file/" + testDir + "/test.jks"; + JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri(); File file = new File(testDir, "test.jks"); file.delete(); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/alias/TestCredentialProviderFactory.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/alias/TestCredentialProviderFactory.java index 3d8794fb82..1eb1e8be98 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/alias/TestCredentialProviderFactory.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/alias/TestCredentialProviderFactory.java @@ -52,19 +52,19 @@ public class TestCredentialProviderFactory { @Test public void testFactory() throws Exception { Configuration conf = new Configuration(); + final String userUri = UserProvider.SCHEME_NAME + ":///"; + final Path jksPath = new Path(tmpDir.toString(), "test.jks"); + final String jksUri = JavaKeyStoreProvider.SCHEME_NAME + + "://file" + jksPath.toUri(); conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, - UserProvider.SCHEME_NAME + ":///," + - JavaKeyStoreProvider.SCHEME_NAME + "://file" + tmpDir + "/test.jks"); + userUri + "," + jksUri); List providers = CredentialProviderFactory.getProviders(conf); assertEquals(2, providers.size()); assertEquals(UserProvider.class, providers.get(0).getClass()); assertEquals(JavaKeyStoreProvider.class, providers.get(1).getClass()); - assertEquals(UserProvider.SCHEME_NAME + - ":///", providers.get(0).toString()); - assertEquals(JavaKeyStoreProvider.SCHEME_NAME + - "://file" + tmpDir + "/test.jks", - providers.get(1).toString()); + assertEquals(userUri, providers.get(0).toString()); + assertEquals(jksUri, providers.get(1).toString()); } @Test @@ -188,8 +188,9 @@ public void testUserProvider() throws Exception { @Test public void testJksProvider() throws Exception { Configuration conf = new Configuration(); + final Path jksPath = new Path(tmpDir.toString(), "test.jks"); final String ourUrl = - JavaKeyStoreProvider.SCHEME_NAME + "://file" + tmpDir + "/test.jks"; + JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri(); File file = new File(tmpDir, "test.jks"); file.delete(); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/KeyStoreTestUtil.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/KeyStoreTestUtil.java index 5f72f9e95e..b2a839ca2a 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/KeyStoreTestUtil.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/KeyStoreTestUtil.java @@ -19,6 +19,7 @@ package org.apache.hadoop.security.ssl; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.Path; import org.apache.hadoop.security.alias.CredentialProvider; import org.apache.hadoop.security.alias.CredentialProviderFactory; import org.apache.hadoop.security.alias.JavaKeyStoreProvider; @@ -392,8 +393,9 @@ public static void provisionPasswordsToCredentialProvider() throws Exception { "target/test-dir")); Configuration conf = new Configuration(); + final Path jksPath = new Path(testDir.toString(), "test.jks"); final String ourUrl = - JavaKeyStoreProvider.SCHEME_NAME + "://file/" + testDir + "/test.jks"; + JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri(); File file = new File(testDir, "test.jks"); file.delete(); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/TestSSLFactory.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/TestSSLFactory.java index 3c428fea28..004888c7b7 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/TestSSLFactory.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/TestSSLFactory.java @@ -22,6 +22,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileUtil; +import org.apache.hadoop.fs.Path; import org.apache.hadoop.security.alias.CredentialProvider; import org.apache.hadoop.security.alias.CredentialProviderFactory; import org.apache.hadoop.security.alias.JavaKeyStoreProvider; @@ -305,8 +306,9 @@ private void checkSSLFactoryInitWithPasswords(SSLFactory.Mode mode, if (useCredProvider) { File testDir = new File(System.getProperty("test.build.data", "target/test-dir")); + final Path jksPath = new Path(testDir.toString(), "test.jks"); final String ourUrl = - JavaKeyStoreProvider.SCHEME_NAME + "://file/" + testDir + "/test.jks"; + JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri(); sslConf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, ourUrl); } } else {