|
25 | 25 | import org.apache.hadoop.fs.Path; |
26 | 26 | import org.apache.hadoop.fs.s3a.Constants; |
27 | 27 | import org.apache.hadoop.fs.s3a.EncryptionTestUtils; |
| 28 | +import org.apache.hadoop.fs.s3a.S3AEncryptionMethods; |
28 | 29 | import org.apache.hadoop.fs.s3a.S3AFileSystem; |
29 | 30 |
|
30 | 31 | import static org.apache.hadoop.fs.s3a.Constants.S3_ENCRYPTION_ALGORITHM; |
31 | 32 | import static org.apache.hadoop.fs.s3a.S3AEncryptionMethods.DSSE_KMS; |
32 | 33 | import static org.apache.hadoop.fs.s3a.S3AEncryptionMethods.SSE_KMS; |
33 | 34 | import static org.apache.hadoop.fs.s3a.S3ATestUtils.getTestBucketName; |
34 | 35 | import static org.apache.hadoop.fs.s3a.S3ATestUtils.skipIfEncryptionNotSet; |
| 36 | +import static org.apache.hadoop.fs.s3a.S3AUtils.getEncryptionAlgorithm; |
35 | 37 | import static org.apache.hadoop.fs.s3a.S3AUtils.getS3EncryptionKey; |
36 | 38 |
|
37 | 39 | /** |
@@ -61,20 +63,30 @@ protected String getBlockOutputBufferName() { |
61 | 63 | */ |
62 | 64 | @Override |
63 | 65 | protected boolean isEncrypted(S3AFileSystem fileSystem) { |
64 | | - Configuration c = new Configuration(); |
65 | | - return StringUtils.isNotBlank(getS3EncryptionKey(getTestBucketName(c), c)); |
| 66 | + Configuration conf = new Configuration(); |
| 67 | + return StringUtils.isNotBlank(getS3EncryptionKey(getTestBucketName(conf), conf)); |
66 | 68 | } |
67 | 69 |
|
| 70 | + /** |
| 71 | + * This test suite will run if the algorithm is set to SSE_KMS or DSSE_KMS; |
| 72 | + * the assertions validate this. |
| 73 | + * @param hugeFile file to validate. |
| 74 | + * @throws IOException problems with encryption lookup. |
| 75 | + * @throws AssertionError if the encryption is not as expected. |
| 76 | + */ |
68 | 77 | @Override |
69 | 78 | protected void assertEncrypted(Path hugeFile) throws IOException { |
70 | | - Configuration c = new Configuration(); |
71 | | - String kmsKey = getS3EncryptionKey(getTestBucketName(c), c); |
72 | | - if (SSE_KMS.getMethod().equals(c.get(S3_ENCRYPTION_ALGORITHM))) { |
| 79 | + Configuration conf = new Configuration(); |
| 80 | + |
| 81 | + final String bucket = getTestBucketName(conf); |
| 82 | + String kmsKey = getS3EncryptionKey(bucket, conf); |
| 83 | + final S3AEncryptionMethods algorithm = getEncryptionAlgorithm(bucket, conf); |
| 84 | + if (SSE_KMS.equals(algorithm)) { |
73 | 85 | EncryptionTestUtils.assertEncrypted(getFileSystem(), hugeFile, SSE_KMS, kmsKey); |
74 | | - } else if (DSSE_KMS.getMethod().equals(c.get(S3_ENCRYPTION_ALGORITHM))) { |
| 86 | + } else if (DSSE_KMS.equals(algorithm)) { |
75 | 87 | EncryptionTestUtils.assertEncrypted(getFileSystem(), hugeFile, DSSE_KMS, kmsKey); |
76 | 88 | } else { |
77 | | - throw new AssertionError("Invalid encryption configured"); |
| 89 | + throw new AssertionError("Invalid encryption configured: " + algorithm); |
78 | 90 | } |
79 | 91 | } |
80 | 92 | } |
0 commit comments