|
@@ -20,6 +20,7 @@ package org.apache.hadoop.hdfs;
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.net.URI;
|
|
|
import java.net.URISyntaxException;
|
|
@@ -27,8 +28,11 @@ import java.util.HashSet;
|
|
|
import java.util.Set;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
+import org.apache.hadoop.crypto.key.JavaKeyStoreProvider;
|
|
|
import org.apache.hadoop.fs.BlockStoragePolicySpi;
|
|
|
+import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
|
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
|
+import org.apache.hadoop.fs.FileSystemTestHelper;
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
import org.apache.hadoop.hdfs.client.HdfsAdmin;
|
|
|
import org.apache.hadoop.hdfs.protocol.BlockStoragePolicy;
|
|
@@ -172,4 +176,33 @@ public class TestHdfsAdmin {
|
|
|
Assert.assertTrue(
|
|
|
Sets.difference(policyNamesSet2, policyNamesSet1).isEmpty());
|
|
|
}
|
|
|
+
|
|
|
+ private static String getKeyProviderURI() {
|
|
|
+ FileSystemTestHelper helper = new FileSystemTestHelper();
|
|
|
+ // Set up java key store
|
|
|
+ String testRoot = helper.getTestRootDir();
|
|
|
+ File testRootDir = new File(testRoot).getAbsoluteFile();
|
|
|
+ return JavaKeyStoreProvider.SCHEME_NAME + "://file" +
|
|
|
+ new Path(testRootDir.toString(), "test.jks").toUri();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testGetKeyProvider() throws IOException {
|
|
|
+ HdfsAdmin hdfsAdmin = new HdfsAdmin(FileSystem.getDefaultUri(conf), conf);
|
|
|
+ Assert.assertNull("should return null for an non-encrypted cluster",
|
|
|
+ hdfsAdmin.getKeyProvider());
|
|
|
+
|
|
|
+ shutDownCluster();
|
|
|
+
|
|
|
+ Configuration conf = new Configuration();
|
|
|
+ conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_KEY_PROVIDER_PATH,
|
|
|
+ getKeyProviderURI());
|
|
|
+
|
|
|
+ cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
|
|
|
+ cluster.waitActive();
|
|
|
+ hdfsAdmin = new HdfsAdmin(FileSystem.getDefaultUri(conf), conf);
|
|
|
+
|
|
|
+ Assert.assertNotNull("should not return null for an encrypted cluster",
|
|
|
+ hdfsAdmin.getKeyProvider());
|
|
|
+ }
|
|
|
}
|