Credential Provider related Unit Test Failure on Windows. Contributed by Xiaoyu Yao.

This commit is contained in:
cnauroth 2014-09-08 09:29:19 -07:00
parent 0974f434c4
commit 302d9a0a0d
6 changed files with 34 additions and 22 deletions

View File

@ -768,6 +768,9 @@ Release 2.6.0 - UNRELEASED
HADOOP-11069. KMSClientProvider should use getAuthenticationMethod() to HADOOP-11069. KMSClientProvider should use getAuthenticationMethod() to
determine if in proxyuser mode or not. (tucu) 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 Release 2.5.1 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -55,18 +55,18 @@ public void setup() {
@Test @Test
public void testFactory() throws Exception { public void testFactory() throws Exception {
Configuration conf = new Configuration(); 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, conf.set(KeyProviderFactory.KEY_PROVIDER_PATH,
UserProvider.SCHEME_NAME + ":///," + userUri + "," + jksUri);
JavaKeyStoreProvider.SCHEME_NAME + "://file" + tmpDir + "/test.jks");
List<KeyProvider> providers = KeyProviderFactory.getProviders(conf); List<KeyProvider> providers = KeyProviderFactory.getProviders(conf);
assertEquals(2, providers.size()); assertEquals(2, providers.size());
assertEquals(UserProvider.class, providers.get(0).getClass()); assertEquals(UserProvider.class, providers.get(0).getClass());
assertEquals(JavaKeyStoreProvider.class, providers.get(1).getClass()); assertEquals(JavaKeyStoreProvider.class, providers.get(1).getClass());
assertEquals(UserProvider.SCHEME_NAME + assertEquals(userUri, providers.get(0).toString());
":///", providers.get(0).toString()); assertEquals(jksUri, providers.get(1).toString());
assertEquals(JavaKeyStoreProvider.SCHEME_NAME +
"://file" + tmpDir + "/test.jks",
providers.get(1).toString());
} }
@Test @Test
@ -207,8 +207,9 @@ public void testUserProvider() throws Exception {
@Test @Test
public void testJksProvider() throws Exception { public void testJksProvider() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
final Path jksPath = new Path(tmpDir.toString(), "test.jks");
final String ourUrl = final String ourUrl =
JavaKeyStoreProvider.SCHEME_NAME + "://file" + tmpDir + "/test.jks"; JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri();
File file = new File(tmpDir, "test.jks"); File file = new File(tmpDir, "test.jks");
file.delete(); file.delete();
@ -317,8 +318,9 @@ public void checkPermissionRetention(Configuration conf, String ourUrl, Path pat
@Test @Test
public void testJksProviderPasswordViaConfig() throws Exception { public void testJksProviderPasswordViaConfig() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
final Path jksPath = new Path(tmpDir.toString(), "test.jks");
final String ourUrl = final String ourUrl =
JavaKeyStoreProvider.SCHEME_NAME + "://file" + tmpDir + "/test.jks"; JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri();
File file = new File(tmpDir, "test.jks"); File file = new File(tmpDir, "test.jks");
file.delete(); file.delete();
try { try {
@ -360,8 +362,8 @@ public void testJksProviderPasswordViaConfig() throws Exception {
@Test @Test
public void testGetProviderViaURI() throws Exception { public void testGetProviderViaURI() throws Exception {
Configuration conf = new Configuration(false); Configuration conf = new Configuration(false);
URI uri = new URI(JavaKeyStoreProvider.SCHEME_NAME + "://file" + tmpDir + final Path jksPath = new Path(tmpDir.toString(), "test.jks");
"/test.jks"); URI uri = new URI(JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri());
KeyProvider kp = KeyProviderFactory.get(uri, conf); KeyProvider kp = KeyProviderFactory.get(uri, conf);
Assert.assertNotNull(kp); Assert.assertNotNull(kp);
Assert.assertEquals(JavaKeyStoreProvider.class, kp.getClass()); Assert.assertEquals(JavaKeyStoreProvider.class, kp.getClass());

View File

@ -40,6 +40,7 @@
import javax.naming.directory.SearchResult; import javax.naming.directory.SearchResult;
import org.apache.hadoop.conf.Configuration; 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.CredentialProvider;
import org.apache.hadoop.security.alias.CredentialProviderFactory; import org.apache.hadoop.security.alias.CredentialProviderFactory;
import org.apache.hadoop.security.alias.JavaKeyStoreProvider; 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", File testDir = new File(System.getProperty("test.build.data",
"target/test-dir")); "target/test-dir"));
Configuration conf = new Configuration(); Configuration conf = new Configuration();
final Path jksPath = new Path(testDir.toString(), "test.jks");
final String ourUrl = final String ourUrl =
JavaKeyStoreProvider.SCHEME_NAME + "://file/" + testDir + "/test.jks"; JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri();
File file = new File(testDir, "test.jks"); File file = new File(testDir, "test.jks");
file.delete(); file.delete();

View File

@ -52,19 +52,19 @@ public class TestCredentialProviderFactory {
@Test @Test
public void testFactory() throws Exception { public void testFactory() throws Exception {
Configuration conf = new Configuration(); 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, conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH,
UserProvider.SCHEME_NAME + ":///," + userUri + "," + jksUri);
JavaKeyStoreProvider.SCHEME_NAME + "://file" + tmpDir + "/test.jks");
List<CredentialProvider> providers = List<CredentialProvider> providers =
CredentialProviderFactory.getProviders(conf); CredentialProviderFactory.getProviders(conf);
assertEquals(2, providers.size()); assertEquals(2, providers.size());
assertEquals(UserProvider.class, providers.get(0).getClass()); assertEquals(UserProvider.class, providers.get(0).getClass());
assertEquals(JavaKeyStoreProvider.class, providers.get(1).getClass()); assertEquals(JavaKeyStoreProvider.class, providers.get(1).getClass());
assertEquals(UserProvider.SCHEME_NAME + assertEquals(userUri, providers.get(0).toString());
":///", providers.get(0).toString()); assertEquals(jksUri, providers.get(1).toString());
assertEquals(JavaKeyStoreProvider.SCHEME_NAME +
"://file" + tmpDir + "/test.jks",
providers.get(1).toString());
} }
@Test @Test
@ -188,8 +188,9 @@ public void testUserProvider() throws Exception {
@Test @Test
public void testJksProvider() throws Exception { public void testJksProvider() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
final Path jksPath = new Path(tmpDir.toString(), "test.jks");
final String ourUrl = final String ourUrl =
JavaKeyStoreProvider.SCHEME_NAME + "://file" + tmpDir + "/test.jks"; JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri();
File file = new File(tmpDir, "test.jks"); File file = new File(tmpDir, "test.jks");
file.delete(); file.delete();

View File

@ -19,6 +19,7 @@
package org.apache.hadoop.security.ssl; package org.apache.hadoop.security.ssl;
import org.apache.hadoop.conf.Configuration; 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.CredentialProvider;
import org.apache.hadoop.security.alias.CredentialProviderFactory; import org.apache.hadoop.security.alias.CredentialProviderFactory;
import org.apache.hadoop.security.alias.JavaKeyStoreProvider; import org.apache.hadoop.security.alias.JavaKeyStoreProvider;
@ -392,8 +393,9 @@ public static void provisionPasswordsToCredentialProvider() throws Exception {
"target/test-dir")); "target/test-dir"));
Configuration conf = new Configuration(); Configuration conf = new Configuration();
final Path jksPath = new Path(testDir.toString(), "test.jks");
final String ourUrl = final String ourUrl =
JavaKeyStoreProvider.SCHEME_NAME + "://file/" + testDir + "/test.jks"; JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri();
File file = new File(testDir, "test.jks"); File file = new File(testDir, "test.jks");
file.delete(); file.delete();

View File

@ -22,6 +22,7 @@
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileUtil; 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.CredentialProvider;
import org.apache.hadoop.security.alias.CredentialProviderFactory; import org.apache.hadoop.security.alias.CredentialProviderFactory;
import org.apache.hadoop.security.alias.JavaKeyStoreProvider; import org.apache.hadoop.security.alias.JavaKeyStoreProvider;
@ -305,8 +306,9 @@ private void checkSSLFactoryInitWithPasswords(SSLFactory.Mode mode,
if (useCredProvider) { if (useCredProvider) {
File testDir = new File(System.getProperty("test.build.data", File testDir = new File(System.getProperty("test.build.data",
"target/test-dir")); "target/test-dir"));
final Path jksPath = new Path(testDir.toString(), "test.jks");
final String ourUrl = final String ourUrl =
JavaKeyStoreProvider.SCHEME_NAME + "://file/" + testDir + "/test.jks"; JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri();
sslConf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, ourUrl); sslConf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, ourUrl);
} }
} else { } else {