From 7dd8e900f8a8bdebb170ff1d0097d4a05d1a6535 Mon Sep 17 00:00:00 2001 From: monthonk <47974768+monthonk@users.noreply.github.com> Date: Sun, 9 Jan 2022 18:01:47 +0000 Subject: [PATCH] HADOOP-14334. S3 SSEC tests to downgrade when running against a mandatory encryption object store (#3870) Contributed by Monthon Klongklaew Change-Id: Ib275c9690bbc90170c6a442ded198fe006c20bc1 --- .../fs/s3a/AbstractTestS3AEncryption.java | 15 +++++++++++++-- .../scale/ITestS3AHugeFilesSSECDiskBlocks.java | 17 +++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/AbstractTestS3AEncryption.java b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/AbstractTestS3AEncryption.java index 7945c820d06..d5778060020 100644 --- a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/AbstractTestS3AEncryption.java +++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/AbstractTestS3AEncryption.java @@ -19,6 +19,7 @@ package org.apache.hadoop.fs.s3a; import java.io.IOException; +import java.nio.file.AccessDeniedException; import org.junit.Test; @@ -81,10 +82,20 @@ public abstract class AbstractTestS3AEncryption extends AbstractS3ATestBase { skipIfEncryptionTestsDisabled(getFileSystem().getConf()); } + /** + * Skipping tests when running against mandatory encryption bucket + * which allows only certain encryption method. + * S3 throw AmazonS3Exception with status 403 AccessDenied + * then it is translated into AccessDeniedException by S3AUtils.translateException(...) + */ @Override public void setup() throws Exception { - super.setup(); - requireEncryptedFileSystem(); + try { + super.setup(); + requireEncryptedFileSystem(); + } catch (AccessDeniedException e) { + skip("Bucket does not allow " + getSSEAlgorithm() + " encryption method"); + } } /** diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/scale/ITestS3AHugeFilesSSECDiskBlocks.java b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/scale/ITestS3AHugeFilesSSECDiskBlocks.java index d2e04d928df..3dc64ea3b45 100644 --- a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/scale/ITestS3AHugeFilesSSECDiskBlocks.java +++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/scale/ITestS3AHugeFilesSSECDiskBlocks.java @@ -23,6 +23,9 @@ import org.apache.hadoop.fs.s3a.Constants; import org.apache.hadoop.fs.s3a.S3AEncryptionMethods; import org.apache.hadoop.fs.s3a.S3ATestUtils; +import java.nio.file.AccessDeniedException; + +import static org.apache.hadoop.fs.contract.ContractTestUtils.skip; 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.SERVER_SIDE_ENCRYPTION_ALGORITHM; @@ -41,10 +44,20 @@ public class ITestS3AHugeFilesSSECDiskBlocks private static final String KEY_1 = "4niV/jPK5VFRHY+KNb6wtqYd4xXyMgdJ9XQJpcQUVbs="; + /** + * Skipping tests when running against mandatory encryption bucket + * which allows only certain encryption method. + * S3 throw AmazonS3Exception with status 403 AccessDenied + * then it is translated into AccessDeniedException by S3AUtils.translateException(...) + */ @Override public void setup() throws Exception { - super.setup(); - skipIfEncryptionTestsDisabled(getConfiguration()); + try { + super.setup(); + skipIfEncryptionTestsDisabled(getConfiguration()); + } catch (AccessDeniedException e) { + skip("Bucket does not allow " + S3AEncryptionMethods.SSE_C + " encryption method"); + } } @SuppressWarnings("deprecation")