|
@@ -20,13 +20,9 @@ package org.apache.hadoop.fs.s3a;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.nio.file.AccessDeniedException;
|
|
import java.nio.file.AccessDeniedException;
|
|
-import java.util.Arrays;
|
|
|
|
-import java.util.Collection;
|
|
|
|
|
|
|
|
import org.assertj.core.api.Assertions;
|
|
import org.assertj.core.api.Assertions;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
-import org.junit.runner.RunWith;
|
|
|
|
-import org.junit.runners.Parameterized;
|
|
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
@@ -37,19 +33,14 @@ import org.apache.hadoop.io.IOUtils;
|
|
|
|
|
|
import static org.apache.hadoop.fs.contract.ContractTestUtils.dataset;
|
|
import static org.apache.hadoop.fs.contract.ContractTestUtils.dataset;
|
|
import static org.apache.hadoop.fs.contract.ContractTestUtils.touch;
|
|
import static org.apache.hadoop.fs.contract.ContractTestUtils.touch;
|
|
-import static org.apache.hadoop.fs.s3a.Constants.DIRECTORY_MARKER_POLICY;
|
|
|
|
-import static org.apache.hadoop.fs.s3a.Constants.DIRECTORY_MARKER_POLICY_DELETE;
|
|
|
|
-import static org.apache.hadoop.fs.s3a.Constants.DIRECTORY_MARKER_POLICY_KEEP;
|
|
|
|
import static org.apache.hadoop.fs.s3a.Constants.ETAG_CHECKSUM_ENABLED;
|
|
import static org.apache.hadoop.fs.s3a.Constants.ETAG_CHECKSUM_ENABLED;
|
|
import static org.apache.hadoop.fs.s3a.Constants.S3_ENCRYPTION_ALGORITHM;
|
|
import static org.apache.hadoop.fs.s3a.Constants.S3_ENCRYPTION_ALGORITHM;
|
|
import static org.apache.hadoop.fs.s3a.Constants.S3_ENCRYPTION_KEY;
|
|
import static org.apache.hadoop.fs.s3a.Constants.S3_ENCRYPTION_KEY;
|
|
import static org.apache.hadoop.fs.s3a.Constants.SERVER_SIDE_ENCRYPTION_ALGORITHM;
|
|
import static org.apache.hadoop.fs.s3a.Constants.SERVER_SIDE_ENCRYPTION_ALGORITHM;
|
|
import static org.apache.hadoop.fs.s3a.Constants.SERVER_SIDE_ENCRYPTION_KEY;
|
|
import static org.apache.hadoop.fs.s3a.Constants.SERVER_SIDE_ENCRYPTION_KEY;
|
|
-import static org.apache.hadoop.fs.s3a.S3ATestUtils.createTestPath;
|
|
|
|
-import static org.apache.hadoop.fs.s3a.S3ATestUtils.disableFilesystemCaching;
|
|
|
|
import static org.apache.hadoop.fs.s3a.S3ATestUtils.getTestBucketName;
|
|
import static org.apache.hadoop.fs.s3a.S3ATestUtils.getTestBucketName;
|
|
|
|
+import static org.apache.hadoop.fs.s3a.S3ATestUtils.maybeSkipRootTests;
|
|
import static org.apache.hadoop.fs.s3a.S3ATestUtils.removeBaseAndBucketOverrides;
|
|
import static org.apache.hadoop.fs.s3a.S3ATestUtils.removeBaseAndBucketOverrides;
|
|
-import static org.apache.hadoop.fs.s3a.S3ATestUtils.skipIfEncryptionTestsDisabled;
|
|
|
|
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
|
|
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -60,7 +51,6 @@ import static org.apache.hadoop.test.LambdaTestUtils.intercept;
|
|
* Equally "vexing" has been the optimizations of getFileStatus(), wherein
|
|
* Equally "vexing" has been the optimizations of getFileStatus(), wherein
|
|
* LIST comes before HEAD path + /
|
|
* LIST comes before HEAD path + /
|
|
*/
|
|
*/
|
|
-@RunWith(Parameterized.class)
|
|
|
|
public class ITestS3AEncryptionSSEC extends AbstractTestS3AEncryption {
|
|
public class ITestS3AEncryptionSSEC extends AbstractTestS3AEncryption {
|
|
|
|
|
|
private static final String SERVICE_AMAZON_S3_STATUS_CODE_403
|
|
private static final String SERVICE_AMAZON_S3_STATUS_CODE_403
|
|
@@ -75,31 +65,11 @@ public class ITestS3AEncryptionSSEC extends AbstractTestS3AEncryption {
|
|
= "msdo3VvvZznp66Gth58a91Hxe/UpExMkwU9BHkIjfW8=";
|
|
= "msdo3VvvZznp66Gth58a91Hxe/UpExMkwU9BHkIjfW8=";
|
|
private static final int TEST_FILE_LEN = 2048;
|
|
private static final int TEST_FILE_LEN = 2048;
|
|
|
|
|
|
- /**
|
|
|
|
- * Parameterization.
|
|
|
|
- */
|
|
|
|
- @Parameterized.Parameters(name = "{0}")
|
|
|
|
- public static Collection<Object[]> params() {
|
|
|
|
- return Arrays.asList(new Object[][]{
|
|
|
|
- {"keep-markers", true},
|
|
|
|
- {"delete-markers", false}
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Parameter: should directory markers be retained?
|
|
|
|
- */
|
|
|
|
- private final boolean keepMarkers;
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Filesystem created with a different key.
|
|
* Filesystem created with a different key.
|
|
*/
|
|
*/
|
|
private S3AFileSystem fsKeyB;
|
|
private S3AFileSystem fsKeyB;
|
|
|
|
|
|
- public ITestS3AEncryptionSSEC(final String name,
|
|
|
|
- final boolean keepMarkers) {
|
|
|
|
- this.keepMarkers = keepMarkers;
|
|
|
|
- }
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
@SuppressWarnings("deprecation")
|
|
@Override
|
|
@Override
|
|
@@ -108,16 +78,11 @@ public class ITestS3AEncryptionSSEC extends AbstractTestS3AEncryption {
|
|
String bucketName = getTestBucketName(conf);
|
|
String bucketName = getTestBucketName(conf);
|
|
// directory marker options
|
|
// directory marker options
|
|
removeBaseAndBucketOverrides(bucketName, conf,
|
|
removeBaseAndBucketOverrides(bucketName, conf,
|
|
- DIRECTORY_MARKER_POLICY,
|
|
|
|
ETAG_CHECKSUM_ENABLED,
|
|
ETAG_CHECKSUM_ENABLED,
|
|
S3_ENCRYPTION_ALGORITHM,
|
|
S3_ENCRYPTION_ALGORITHM,
|
|
S3_ENCRYPTION_KEY,
|
|
S3_ENCRYPTION_KEY,
|
|
SERVER_SIDE_ENCRYPTION_ALGORITHM,
|
|
SERVER_SIDE_ENCRYPTION_ALGORITHM,
|
|
SERVER_SIDE_ENCRYPTION_KEY);
|
|
SERVER_SIDE_ENCRYPTION_KEY);
|
|
- conf.set(DIRECTORY_MARKER_POLICY,
|
|
|
|
- keepMarkers
|
|
|
|
- ? DIRECTORY_MARKER_POLICY_KEEP
|
|
|
|
- : DIRECTORY_MARKER_POLICY_DELETE);
|
|
|
|
conf.set(S3_ENCRYPTION_ALGORITHM,
|
|
conf.set(S3_ENCRYPTION_ALGORITHM,
|
|
getSSEAlgorithm().getMethod());
|
|
getSSEAlgorithm().getMethod());
|
|
conf.set(S3_ENCRYPTION_KEY, KEY_1);
|
|
conf.set(S3_ENCRYPTION_KEY, KEY_1);
|
|
@@ -129,6 +94,9 @@ public class ITestS3AEncryptionSSEC extends AbstractTestS3AEncryption {
|
|
public void setup() throws Exception {
|
|
public void setup() throws Exception {
|
|
super.setup();
|
|
super.setup();
|
|
assumeEnabled();
|
|
assumeEnabled();
|
|
|
|
+ // although not a root dir test, this confuses paths enough it shouldn't be run in
|
|
|
|
+ // parallel with other jobs
|
|
|
|
+ maybeSkipRootTests(getConfiguration());
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -154,7 +122,7 @@ public class ITestS3AEncryptionSSEC extends AbstractTestS3AEncryption {
|
|
() -> {
|
|
() -> {
|
|
int len = TEST_FILE_LEN;
|
|
int len = TEST_FILE_LEN;
|
|
describe("Create an encrypted file of size " + len);
|
|
describe("Create an encrypted file of size " + len);
|
|
- Path src = path("testCreateFileAndReadWithDifferentEncryptionKey");
|
|
|
|
|
|
+ Path src = methodPath();
|
|
writeThenReadFile(src, len);
|
|
writeThenReadFile(src, len);
|
|
|
|
|
|
//extract the test FS
|
|
//extract the test FS
|
|
@@ -174,7 +142,7 @@ public class ITestS3AEncryptionSSEC extends AbstractTestS3AEncryption {
|
|
*/
|
|
*/
|
|
@Test
|
|
@Test
|
|
public void testCreateSubdirWithDifferentKey() throws Exception {
|
|
public void testCreateSubdirWithDifferentKey() throws Exception {
|
|
- Path base = path("testCreateSubdirWithDifferentKey");
|
|
|
|
|
|
+ Path base = methodPath();
|
|
Path nestedDirectory = new Path(base, "nestedDir");
|
|
Path nestedDirectory = new Path(base, "nestedDir");
|
|
fsKeyB = createNewFileSystemWithSSECKey(
|
|
fsKeyB = createNewFileSystemWithSSECKey(
|
|
KEY_2);
|
|
KEY_2);
|
|
@@ -213,9 +181,10 @@ public class ITestS3AEncryptionSSEC extends AbstractTestS3AEncryption {
|
|
*/
|
|
*/
|
|
@Test
|
|
@Test
|
|
public void testRenameFile() throws Exception {
|
|
public void testRenameFile() throws Exception {
|
|
- Path src = path("original-path.txt");
|
|
|
|
|
|
+ final Path base = methodPath();
|
|
|
|
+ Path src = new Path(base, "original-path.txt");
|
|
writeThenReadFile(src, TEST_FILE_LEN);
|
|
writeThenReadFile(src, TEST_FILE_LEN);
|
|
- Path newPath = path("different-path.txt");
|
|
|
|
|
|
+ Path newPath = new Path(base, "different-path.txt");
|
|
getFileSystem().rename(src, newPath);
|
|
getFileSystem().rename(src, newPath);
|
|
byte[] data = dataset(TEST_FILE_LEN, 'a', 'z');
|
|
byte[] data = dataset(TEST_FILE_LEN, 'a', 'z');
|
|
ContractTestUtils.verifyFileContents(getFileSystem(), newPath, data);
|
|
ContractTestUtils.verifyFileContents(getFileSystem(), newPath, data);
|
|
@@ -228,11 +197,11 @@ public class ITestS3AEncryptionSSEC extends AbstractTestS3AEncryption {
|
|
@Test
|
|
@Test
|
|
public void testListEncryptedDir() throws Exception {
|
|
public void testListEncryptedDir() throws Exception {
|
|
|
|
|
|
- Path pathABC = path("testListEncryptedDir/a/b/c/");
|
|
|
|
|
|
+ Path pathABC = new Path(methodPath(), "a/b/c/");
|
|
Path pathAB = pathABC.getParent();
|
|
Path pathAB = pathABC.getParent();
|
|
Path pathA = pathAB.getParent();
|
|
Path pathA = pathAB.getParent();
|
|
|
|
|
|
- Path nestedDirectory = createTestPath(pathABC);
|
|
|
|
|
|
+ Path nestedDirectory = pathABC;
|
|
assertTrue(getFileSystem().mkdirs(nestedDirectory));
|
|
assertTrue(getFileSystem().mkdirs(nestedDirectory));
|
|
|
|
|
|
fsKeyB = createNewFileSystemWithSSECKey(KEY_4);
|
|
fsKeyB = createNewFileSystemWithSSECKey(KEY_4);
|
|
@@ -261,7 +230,7 @@ public class ITestS3AEncryptionSSEC extends AbstractTestS3AEncryption {
|
|
@Test
|
|
@Test
|
|
public void testListStatusEncryptedDir() throws Exception {
|
|
public void testListStatusEncryptedDir() throws Exception {
|
|
|
|
|
|
- Path pathABC = path("testListStatusEncryptedDir/a/b/c/");
|
|
|
|
|
|
+ Path pathABC = new Path(methodPath(), "a/b/c/");
|
|
Path pathAB = pathABC.getParent();
|
|
Path pathAB = pathABC.getParent();
|
|
Path pathA = pathAB.getParent();
|
|
Path pathA = pathAB.getParent();
|
|
assertTrue(getFileSystem().mkdirs(pathABC));
|
|
assertTrue(getFileSystem().mkdirs(pathABC));
|
|
@@ -296,7 +265,7 @@ public class ITestS3AEncryptionSSEC extends AbstractTestS3AEncryption {
|
|
*/
|
|
*/
|
|
@Test
|
|
@Test
|
|
public void testListStatusEncryptedFile() throws Exception {
|
|
public void testListStatusEncryptedFile() throws Exception {
|
|
- Path pathABC = path("testListStatusEncryptedFile/a/b/c/");
|
|
|
|
|
|
+ Path pathABC = new Path(methodPath(), "a/b/c/");
|
|
assertTrue("mkdirs failed", getFileSystem().mkdirs(pathABC));
|
|
assertTrue("mkdirs failed", getFileSystem().mkdirs(pathABC));
|
|
|
|
|
|
Path fileToStat = new Path(pathABC, "fileToStat.txt");
|
|
Path fileToStat = new Path(pathABC, "fileToStat.txt");
|
|
@@ -305,23 +274,9 @@ public class ITestS3AEncryptionSSEC extends AbstractTestS3AEncryption {
|
|
fsKeyB = createNewFileSystemWithSSECKey(KEY_4);
|
|
fsKeyB = createNewFileSystemWithSSECKey(KEY_4);
|
|
|
|
|
|
//Until this point, no exception is thrown about access
|
|
//Until this point, no exception is thrown about access
|
|
- if (statusProbesCheckS3(fsKeyB, fileToStat)) {
|
|
|
|
- intercept(AccessDeniedException.class,
|
|
|
|
- SERVICE_AMAZON_S3_STATUS_CODE_403,
|
|
|
|
- () -> fsKeyB.listStatus(fileToStat));
|
|
|
|
- } else {
|
|
|
|
- fsKeyB.listStatus(fileToStat);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Do file status probes check S3?
|
|
|
|
- * @param fs filesystem
|
|
|
|
- * @param path file path
|
|
|
|
- * @return true if check for a path being a file will issue a HEAD request.
|
|
|
|
- */
|
|
|
|
- private boolean statusProbesCheckS3(S3AFileSystem fs, Path path) {
|
|
|
|
- return true;
|
|
|
|
|
|
+ intercept(AccessDeniedException.class,
|
|
|
|
+ SERVICE_AMAZON_S3_STATUS_CODE_403,
|
|
|
|
+ () -> fsKeyB.listStatus(fileToStat));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -332,22 +287,17 @@ public class ITestS3AEncryptionSSEC extends AbstractTestS3AEncryption {
|
|
*/
|
|
*/
|
|
@Test
|
|
@Test
|
|
public void testDeleteEncryptedObjectWithDifferentKey() throws Exception {
|
|
public void testDeleteEncryptedObjectWithDifferentKey() throws Exception {
|
|
- //requireUnguardedFilesystem();
|
|
|
|
- Path pathABC = path("testDeleteEncryptedObjectWithDifferentKey/a/b/c/");
|
|
|
|
|
|
|
|
|
|
+ Path pathABC = new Path(methodPath(), "a/b/c/");
|
|
Path pathAB = pathABC.getParent();
|
|
Path pathAB = pathABC.getParent();
|
|
Path pathA = pathAB.getParent();
|
|
Path pathA = pathAB.getParent();
|
|
assertTrue(getFileSystem().mkdirs(pathABC));
|
|
assertTrue(getFileSystem().mkdirs(pathABC));
|
|
Path fileToDelete = new Path(pathABC, "filetobedeleted.txt");
|
|
Path fileToDelete = new Path(pathABC, "filetobedeleted.txt");
|
|
writeThenReadFile(fileToDelete, TEST_FILE_LEN);
|
|
writeThenReadFile(fileToDelete, TEST_FILE_LEN);
|
|
fsKeyB = createNewFileSystemWithSSECKey(KEY_4);
|
|
fsKeyB = createNewFileSystemWithSSECKey(KEY_4);
|
|
- if (statusProbesCheckS3(fsKeyB, fileToDelete)) {
|
|
|
|
- intercept(AccessDeniedException.class,
|
|
|
|
- SERVICE_AMAZON_S3_STATUS_CODE_403,
|
|
|
|
- () -> fsKeyB.delete(fileToDelete, false));
|
|
|
|
- } else {
|
|
|
|
- fsKeyB.delete(fileToDelete, false);
|
|
|
|
- }
|
|
|
|
|
|
+ intercept(AccessDeniedException.class,
|
|
|
|
+ SERVICE_AMAZON_S3_STATUS_CODE_403,
|
|
|
|
+ () -> fsKeyB.delete(fileToDelete, false));
|
|
//This is possible
|
|
//This is possible
|
|
fsKeyB.delete(pathABC, true);
|
|
fsKeyB.delete(pathABC, true);
|
|
fsKeyB.delete(pathAB, true);
|
|
fsKeyB.delete(pathAB, true);
|
|
@@ -360,7 +310,7 @@ public class ITestS3AEncryptionSSEC extends AbstractTestS3AEncryption {
|
|
*/
|
|
*/
|
|
@Test
|
|
@Test
|
|
public void testChecksumRequiresReadAccess() throws Throwable {
|
|
public void testChecksumRequiresReadAccess() throws Throwable {
|
|
- Path path = path("tagged-file");
|
|
|
|
|
|
+ Path path = methodPath();
|
|
S3AFileSystem fs = getFileSystem();
|
|
S3AFileSystem fs = getFileSystem();
|
|
touch(fs, path);
|
|
touch(fs, path);
|
|
Assertions.assertThat(fs.getFileChecksum(path))
|
|
Assertions.assertThat(fs.getFileChecksum(path))
|