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:
Charles Lamb 2014-07-23 14:51:06 +00:00
parent 69b75fca7a
commit 687ce1a5fc
3 changed files with 32 additions and 2 deletions

View File

@ -59,3 +59,6 @@ fs-encryption (Unreleased)
OPTIMIZATIONS
BUG FIXES
HDFS-6733. Creating encryption zone results in NPE when
KeyProvider is null. (clamb)

View File

@ -8448,6 +8448,11 @@ void createEncryptionZone(final String src, String keyNameArg)
String keyName = keyNameArg;
boolean success = false;
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()) {
keyName = UUID.randomUUID().toString();
createNewKey(keyName, src);

View File

@ -68,6 +68,7 @@ public class TestEncryptionZones {
private MiniDFSCluster cluster;
private HdfsAdmin dfsAdmin;
private DistributedFileSystem fs;
private File testRootDir;
protected FileSystemTestWrapper fsWrapper;
protected FileContextTestWrapper fcWrapper;
@ -78,14 +79,14 @@ public void setup() throws IOException {
fsHelper = new FileSystemTestHelper();
// Set up java key store
String testRoot = fsHelper.getTestRootDir();
File testRootDir = new File(testRoot).getAbsoluteFile();
testRootDir = new File(testRoot).getAbsoluteFile();
conf.set(KeyProviderFactory.KEY_PROVIDER_PATH,
JavaKeyStoreProvider.SCHEME_NAME + "://file" + testRootDir + "/test.jks"
);
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
Logger.getLogger(EncryptionZoneManager.class).setLevel(Level.TRACE);
fs = cluster.getFileSystem();
fsWrapper = new FileSystemTestWrapper(cluster.getFileSystem());
fsWrapper = new FileSystemTestWrapper(fs);
fcWrapper = new FileContextTestWrapper(
FileContext.getFileContext(cluster.getURI(), conf));
dfsAdmin = new HdfsAdmin(cluster.getURI(), conf);
@ -429,4 +430,25 @@ public void testCipherSuiteNegotiation() throws Exception {
}
}
@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);
}
}