HDFS-6807. Fix TestReservedRawPaths. (clamb)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/fs-encryption@1615188 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
beebb36595
commit
3d9e39e51f
@ -81,3 +81,5 @@ fs-encryption (Unreleased)
|
|||||||
|
|
||||||
HDFS-6785. Should not be able to create encryption zone using path
|
HDFS-6785. Should not be able to create encryption zone using path
|
||||||
to a non-directory file. (clamb)
|
to a non-directory file. (clamb)
|
||||||
|
|
||||||
|
HDFS-6807. Fix TestReservedRawPaths. (clamb)
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
import org.apache.hadoop.crypto.key.KeyProvider;
|
||||||
import org.apache.hadoop.fs.*;
|
import org.apache.hadoop.fs.*;
|
||||||
import org.apache.hadoop.fs.FileSystem;
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
import org.apache.hadoop.fs.FileSystem.Statistics;
|
import org.apache.hadoop.fs.FileSystem.Statistics;
|
||||||
@ -75,6 +76,7 @@
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.PrivilegedExceptionAction;
|
import java.security.PrivilegedExceptionAction;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
@ -1348,4 +1350,22 @@ public static void verifyFilesNotEqual(FileSystem fs, Path p1, Path p2,
|
|||||||
in2.close();
|
in2.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to create a key in the Key Provider.
|
||||||
|
*
|
||||||
|
* @param keyName The name of the key to create
|
||||||
|
* @param cluster The cluster to create it in
|
||||||
|
* @param conf Configuration to use
|
||||||
|
*/
|
||||||
|
public static void createKey(String keyName, MiniDFSCluster cluster,
|
||||||
|
Configuration conf)
|
||||||
|
throws NoSuchAlgorithmException, IOException {
|
||||||
|
KeyProvider provider = cluster.getNameNode().getNamesystem().getProvider();
|
||||||
|
final KeyProvider.Options options = KeyProvider.options(conf);
|
||||||
|
options.setDescription(keyName);
|
||||||
|
options.setBitLength(128);
|
||||||
|
provider.createKey(keyName, options);
|
||||||
|
provider.flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ public void setup() throws Exception {
|
|||||||
fs.getClient().provider = cluster.getNameNode().getNamesystem()
|
fs.getClient().provider = cluster.getNameNode().getNamesystem()
|
||||||
.getProvider();
|
.getProvider();
|
||||||
// Create a test key
|
// Create a test key
|
||||||
createKey(TEST_KEY);
|
DFSTestUtil.createKey(TEST_KEY, cluster, conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@ -147,19 +147,6 @@ public void assertZonePresent(String keyName, String path) throws IOException {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to create a key in the Key Provider.
|
|
||||||
*/
|
|
||||||
private void createKey(String keyName)
|
|
||||||
throws NoSuchAlgorithmException, IOException {
|
|
||||||
KeyProvider provider = cluster.getNameNode().getNamesystem().getProvider();
|
|
||||||
final KeyProvider.Options options = KeyProvider.options(conf);
|
|
||||||
options.setDescription(keyName);
|
|
||||||
options.setBitLength(128);
|
|
||||||
provider.createKey(keyName, options);
|
|
||||||
provider.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(timeout = 60000)
|
@Test(timeout = 60000)
|
||||||
public void testBasicOperations() throws Exception {
|
public void testBasicOperations() throws Exception {
|
||||||
|
|
||||||
@ -263,7 +250,7 @@ public void testBasicOperations() throws Exception {
|
|||||||
assertNumZones(1);
|
assertNumZones(1);
|
||||||
|
|
||||||
/* Test success of creating an EZ when they key exists. */
|
/* Test success of creating an EZ when they key exists. */
|
||||||
createKey(myKeyName);
|
DFSTestUtil.createKey(myKeyName, cluster, conf);
|
||||||
dfsAdmin.createEncryptionZone(zone2, myKeyName);
|
dfsAdmin.createEncryptionZone(zone2, myKeyName);
|
||||||
assertNumZones(++numZones);
|
assertNumZones(++numZones);
|
||||||
assertZonePresent(myKeyName, zone2.toString());
|
assertZonePresent(myKeyName, zone2.toString());
|
||||||
@ -601,7 +588,7 @@ public void doCleanup() throws Exception {
|
|||||||
// Test when the parent directory becomes a different EZ
|
// Test when the parent directory becomes a different EZ
|
||||||
fsWrapper.mkdir(zone1, FsPermission.getDirDefault(), true);
|
fsWrapper.mkdir(zone1, FsPermission.getDirDefault(), true);
|
||||||
final String otherKey = "otherKey";
|
final String otherKey = "otherKey";
|
||||||
createKey(otherKey);
|
DFSTestUtil.createKey(otherKey, cluster, conf);
|
||||||
dfsAdmin.createEncryptionZone(zone1, TEST_KEY);
|
dfsAdmin.createEncryptionZone(zone1, TEST_KEY);
|
||||||
|
|
||||||
executor.submit(new InjectFaultTask() {
|
executor.submit(new InjectFaultTask() {
|
||||||
@ -621,7 +608,7 @@ public void doCleanup() throws Exception {
|
|||||||
// Test that the retry limit leads to an error
|
// Test that the retry limit leads to an error
|
||||||
fsWrapper.mkdir(zone1, FsPermission.getDirDefault(), true);
|
fsWrapper.mkdir(zone1, FsPermission.getDirDefault(), true);
|
||||||
final String anotherKey = "anotherKey";
|
final String anotherKey = "anotherKey";
|
||||||
createKey(anotherKey);
|
DFSTestUtil.createKey(anotherKey, cluster, conf);
|
||||||
dfsAdmin.createEncryptionZone(zone1, anotherKey);
|
dfsAdmin.createEncryptionZone(zone1, anotherKey);
|
||||||
String keyToUse = otherKey;
|
String keyToUse = otherKey;
|
||||||
|
|
||||||
|
@ -57,12 +57,13 @@ public class TestReservedRawPaths {
|
|||||||
private MiniDFSCluster cluster;
|
private MiniDFSCluster cluster;
|
||||||
private HdfsAdmin dfsAdmin;
|
private HdfsAdmin dfsAdmin;
|
||||||
private DistributedFileSystem fs;
|
private DistributedFileSystem fs;
|
||||||
|
private final String TEST_KEY = "testKey";
|
||||||
|
|
||||||
protected FileSystemTestWrapper fsWrapper;
|
protected FileSystemTestWrapper fsWrapper;
|
||||||
protected FileContextTestWrapper fcWrapper;
|
protected FileContextTestWrapper fcWrapper;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws IOException {
|
public void setup() throws Exception {
|
||||||
conf = new HdfsConfiguration();
|
conf = new HdfsConfiguration();
|
||||||
fsHelper = new FileSystemTestHelper();
|
fsHelper = new FileSystemTestHelper();
|
||||||
// Set up java key store
|
// Set up java key store
|
||||||
@ -82,6 +83,7 @@ public void setup() throws IOException {
|
|||||||
// else the updates do not get flushed properly
|
// else the updates do not get flushed properly
|
||||||
fs.getClient().provider = cluster.getNameNode().getNamesystem()
|
fs.getClient().provider = cluster.getNameNode().getNamesystem()
|
||||||
.getProvider();
|
.getProvider();
|
||||||
|
DFSTestUtil.createKey(TEST_KEY, cluster, conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@ -110,7 +112,7 @@ public void testReadWriteRaw() throws Exception {
|
|||||||
// Create the first enc file
|
// Create the first enc file
|
||||||
final Path zone = new Path("/zone");
|
final Path zone = new Path("/zone");
|
||||||
fs.mkdirs(zone);
|
fs.mkdirs(zone);
|
||||||
dfsAdmin.createEncryptionZone(zone, null);
|
dfsAdmin.createEncryptionZone(zone, TEST_KEY);
|
||||||
final Path encFile1 = new Path(zone, "myfile");
|
final Path encFile1 = new Path(zone, "myfile");
|
||||||
DFSTestUtil.createFile(fs, encFile1, len, (short) 1, 0xFEED);
|
DFSTestUtil.createFile(fs, encFile1, len, (short) 1, 0xFEED);
|
||||||
// Read them back in and compare byte-by-byte
|
// Read them back in and compare byte-by-byte
|
||||||
@ -150,7 +152,7 @@ public void testGetFileStatus() throws Exception {
|
|||||||
final Path zone = new Path("zone");
|
final Path zone = new Path("zone");
|
||||||
final Path slashZone = new Path("/", zone);
|
final Path slashZone = new Path("/", zone);
|
||||||
fs.mkdirs(slashZone);
|
fs.mkdirs(slashZone);
|
||||||
dfsAdmin.createEncryptionZone(slashZone, null);
|
dfsAdmin.createEncryptionZone(slashZone, TEST_KEY);
|
||||||
|
|
||||||
final Path base = new Path("base");
|
final Path base = new Path("base");
|
||||||
final Path reservedRaw = new Path("/.reserved/raw");
|
final Path reservedRaw = new Path("/.reserved/raw");
|
||||||
@ -182,7 +184,7 @@ public void testReservedRawMkdir() throws Exception {
|
|||||||
final Path zone = new Path("zone");
|
final Path zone = new Path("zone");
|
||||||
final Path slashZone = new Path("/", zone);
|
final Path slashZone = new Path("/", zone);
|
||||||
fs.mkdirs(slashZone);
|
fs.mkdirs(slashZone);
|
||||||
dfsAdmin.createEncryptionZone(slashZone, null);
|
dfsAdmin.createEncryptionZone(slashZone, TEST_KEY);
|
||||||
final Path rawRoot = new Path("/.reserved/raw");
|
final Path rawRoot = new Path("/.reserved/raw");
|
||||||
final Path dir1 = new Path("dir1");
|
final Path dir1 = new Path("dir1");
|
||||||
final Path rawDir1 = new Path(rawRoot, dir1);
|
final Path rawDir1 = new Path(rawRoot, dir1);
|
||||||
@ -220,7 +222,7 @@ public void testAdminAccessOnly() throws Exception {
|
|||||||
final Path zone = new Path("zone");
|
final Path zone = new Path("zone");
|
||||||
final Path slashZone = new Path("/", zone);
|
final Path slashZone = new Path("/", zone);
|
||||||
fs.mkdirs(slashZone);
|
fs.mkdirs(slashZone);
|
||||||
dfsAdmin.createEncryptionZone(slashZone, null);
|
dfsAdmin.createEncryptionZone(slashZone, TEST_KEY);
|
||||||
final Path base = new Path("base");
|
final Path base = new Path("base");
|
||||||
final Path reservedRaw = new Path("/.reserved/raw");
|
final Path reservedRaw = new Path("/.reserved/raw");
|
||||||
final int len = 8192;
|
final int len = 8192;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user