|
@@ -19,7 +19,11 @@
|
|
|
package org.apache.hadoop.fs.s3a;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
+import org.apache.hadoop.fs.s3a.impl.HeaderProcessing;
|
|
|
+import org.assertj.core.api.Assertions;
|
|
|
import software.amazon.awssdk.services.s3.model.HeadObjectResponse;
|
|
|
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
@@ -28,6 +32,8 @@ import org.apache.hadoop.fs.FileSystem;
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
|
|
|
import static org.apache.hadoop.fs.s3a.Constants.S3_ENCRYPTION_KEY;
|
|
|
+import static org.apache.hadoop.fs.s3a.impl.HeaderProcessing.XA_ENCRYPTION_KEY_ID;
|
|
|
+import static org.apache.hadoop.fs.s3a.impl.HeaderProcessing.XA_SERVER_SIDE_ENCRYPTION;
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
|
public final class EncryptionTestUtils {
|
|
@@ -111,4 +117,31 @@ public final class EncryptionTestUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Assert that a path is encrypted with right encryption settings.
|
|
|
+ * @param fs filesystem.
|
|
|
+ * @param path path
|
|
|
+ * @param algorithm encryption algorithm.
|
|
|
+ * @param kmsKey full kms key if present.
|
|
|
+ * @throws IOException any IOE.
|
|
|
+ */
|
|
|
+ public static void validateEncryptionFileAttributes(S3AFileSystem fs,
|
|
|
+ Path path,
|
|
|
+ String algorithm,
|
|
|
+ Optional<String> kmsKey) throws IOException {
|
|
|
+ Map<String, byte[]> xAttrs = fs.getXAttrs(path);
|
|
|
+ Assertions.assertThat(xAttrs.get(XA_SERVER_SIDE_ENCRYPTION))
|
|
|
+ .describedAs("Server side encryption must not be null")
|
|
|
+ .isNotNull();
|
|
|
+ Assertions.assertThat(HeaderProcessing.decodeBytes(xAttrs.get(XA_SERVER_SIDE_ENCRYPTION)))
|
|
|
+ .describedAs("Server side encryption algorithm must match")
|
|
|
+ .isEqualTo(algorithm);
|
|
|
+ Assertions.assertThat(xAttrs)
|
|
|
+ .describedAs("Encryption key id should be present")
|
|
|
+ .containsKey(XA_ENCRYPTION_KEY_ID);
|
|
|
+ kmsKey.ifPresent(s -> Assertions
|
|
|
+ .assertThat(HeaderProcessing.decodeBytes(xAttrs.get(XA_ENCRYPTION_KEY_ID)))
|
|
|
+ .describedAs("Encryption key id should match with the kms key")
|
|
|
+ .isEqualTo(s));
|
|
|
+ }
|
|
|
}
|