HDFS-6733. Creating encryption zone results in NPE when KeyProvider is null. (clamb)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/fs-encryption@1612843 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
69b75fca7a
commit
687ce1a5fc
|
@ -59,3 +59,6 @@ fs-encryption (Unreleased)
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
||||||
|
HDFS-6733. Creating encryption zone results in NPE when
|
||||||
|
KeyProvider is null. (clamb)
|
||||||
|
|
|
@ -8448,6 +8448,11 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
||||||
String keyName = keyNameArg;
|
String keyName = keyNameArg;
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
try {
|
try {
|
||||||
|
if (provider == null) {
|
||||||
|
throw new IOException(
|
||||||
|
"Can't create an encryption zone for " + src +
|
||||||
|
" since no key provider is available.");
|
||||||
|
}
|
||||||
if (keyName == null || keyName.isEmpty()) {
|
if (keyName == null || keyName.isEmpty()) {
|
||||||
keyName = UUID.randomUUID().toString();
|
keyName = UUID.randomUUID().toString();
|
||||||
createNewKey(keyName, src);
|
createNewKey(keyName, src);
|
||||||
|
|
|
@ -68,6 +68,7 @@ public class TestEncryptionZones {
|
||||||
private MiniDFSCluster cluster;
|
private MiniDFSCluster cluster;
|
||||||
private HdfsAdmin dfsAdmin;
|
private HdfsAdmin dfsAdmin;
|
||||||
private DistributedFileSystem fs;
|
private DistributedFileSystem fs;
|
||||||
|
private File testRootDir;
|
||||||
|
|
||||||
protected FileSystemTestWrapper fsWrapper;
|
protected FileSystemTestWrapper fsWrapper;
|
||||||
protected FileContextTestWrapper fcWrapper;
|
protected FileContextTestWrapper fcWrapper;
|
||||||
|
@ -78,14 +79,14 @@ public class TestEncryptionZones {
|
||||||
fsHelper = new FileSystemTestHelper();
|
fsHelper = new FileSystemTestHelper();
|
||||||
// Set up java key store
|
// Set up java key store
|
||||||
String testRoot = fsHelper.getTestRootDir();
|
String testRoot = fsHelper.getTestRootDir();
|
||||||
File testRootDir = new File(testRoot).getAbsoluteFile();
|
testRootDir = new File(testRoot).getAbsoluteFile();
|
||||||
conf.set(KeyProviderFactory.KEY_PROVIDER_PATH,
|
conf.set(KeyProviderFactory.KEY_PROVIDER_PATH,
|
||||||
JavaKeyStoreProvider.SCHEME_NAME + "://file" + testRootDir + "/test.jks"
|
JavaKeyStoreProvider.SCHEME_NAME + "://file" + testRootDir + "/test.jks"
|
||||||
);
|
);
|
||||||
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
|
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
|
||||||
Logger.getLogger(EncryptionZoneManager.class).setLevel(Level.TRACE);
|
Logger.getLogger(EncryptionZoneManager.class).setLevel(Level.TRACE);
|
||||||
fs = cluster.getFileSystem();
|
fs = cluster.getFileSystem();
|
||||||
fsWrapper = new FileSystemTestWrapper(cluster.getFileSystem());
|
fsWrapper = new FileSystemTestWrapper(fs);
|
||||||
fcWrapper = new FileContextTestWrapper(
|
fcWrapper = new FileContextTestWrapper(
|
||||||
FileContext.getFileContext(cluster.getURI(), conf));
|
FileContext.getFileContext(cluster.getURI(), conf));
|
||||||
dfsAdmin = new HdfsAdmin(cluster.getURI(), conf);
|
dfsAdmin = new HdfsAdmin(cluster.getURI(), conf);
|
||||||
|
@ -429,4 +430,25 @@ public class TestEncryptionZones {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 120000)
|
||||||
|
public void testCreateEZWithNoProvider() throws Exception {
|
||||||
|
|
||||||
|
final Configuration clusterConf = cluster.getConfiguration(0);
|
||||||
|
clusterConf.set(KeyProviderFactory.KEY_PROVIDER_PATH, "");
|
||||||
|
cluster.restartNameNode(true);
|
||||||
|
/* Test failure of create EZ on a directory that doesn't exist. */
|
||||||
|
final Path zone1 = new Path("/zone1");
|
||||||
|
/* Normal creation of an EZ */
|
||||||
|
fsWrapper.mkdir(zone1, FsPermission.getDirDefault(), true);
|
||||||
|
try {
|
||||||
|
dfsAdmin.createEncryptionZone(zone1, null);
|
||||||
|
fail("expected exception");
|
||||||
|
} catch (IOException e) {
|
||||||
|
assertExceptionContains("since no key provider is available", e);
|
||||||
|
}
|
||||||
|
clusterConf.set(KeyProviderFactory.KEY_PROVIDER_PATH,
|
||||||
|
JavaKeyStoreProvider.SCHEME_NAME + "://file" + testRootDir + "/test.jks"
|
||||||
|
);
|
||||||
|
cluster.restartNameNode(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue