gaborgsomogyi commented on code in PR #28070:
URL: https://github.com/apache/flink/pull/28070#discussion_r3168779117
##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/S3EncryptionConfig.java:
##########
@@ -148,7 +145,9 @@ public static S3EncryptionConfig sseKms(
* @throws IllegalArgumentException if the encryption type is invalid
*/
public static S3EncryptionConfig fromConfig(
- @Nullable String encryptionTypeStr, @Nullable String kmsKeyId) {
+ @Nullable String encryptionTypeStr,
+ @Nullable String kmsKeyId,
Review Comment:
Fixed. Added `sseKms(Map<String,String>)` overload and updated `fromConfig`
to call `sseKms(encryptionContext)` for the default-key case, so the context is
no longer discarded.
##########
flink-filesystems/flink-s3-fs-native/src/test/java/org/apache/flink/fs/s3native/S3EncryptionConfigTest.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.fs.s3native;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import software.amazon.awssdk.services.s3.model.ServerSideEncryption;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Collections;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import static
org.apache.flink.fs.s3native.S3EncryptionConfig.EncryptionType.NONE;
+import static
org.apache.flink.fs.s3native.S3EncryptionConfig.EncryptionType.SSE_KMS;
+import static
org.apache.flink.fs.s3native.S3EncryptionConfig.EncryptionType.SSE_S3;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/** Tests for {@link S3EncryptionConfig}. */
+class S3EncryptionConfigTest {
+
+ // ---- factory methods ----
+
+ @ParameterizedTest
+ @MethodSource
+ void testFactoryMethodProperties(
+ S3EncryptionConfig config,
+ S3EncryptionConfig.EncryptionType expectedType,
+ boolean expectedEnabled,
+ ServerSideEncryption expectedSse) {
+ assertThat(config.getEncryptionType()).isEqualTo(expectedType);
+ assertThat(config.isEnabled()).isEqualTo(expectedEnabled);
+ assertThat(config.getKmsKeyId()).isNull();
+ assertThat(config.getServerSideEncryption()).isEqualTo(expectedSse);
+ }
+
+ static Stream<Arguments> testFactoryMethodProperties() {
+ return Stream.of(
+ Arguments.of(S3EncryptionConfig.none(), NONE, false, null),
+ Arguments.of(S3EncryptionConfig.sseS3(), SSE_S3, true,
ServerSideEncryption.AES256),
+ Arguments.of(
+ S3EncryptionConfig.sseKms(), SSE_KMS, true,
ServerSideEncryption.AWS_KMS));
+ }
+
+ @Test
+ void testSseKmsExplicitKey() {
+ S3EncryptionConfig c =
S3EncryptionConfig.sseKms("arn:aws:kms:us-east-1:123:key/abc");
+
assertThat(c.getKmsKeyId()).isEqualTo("arn:aws:kms:us-east-1:123:key/abc");
+ assertThat(c.isEnabled()).isTrue();
+ }
+
+ @Test
+ void testSseKmsWithEncryptionContext() {
+ Map<String, String> ctx = Map.of("dept", "finance");
+ S3EncryptionConfig c = S3EncryptionConfig.sseKms("key-id", ctx);
+ assertThat(c.getEncryptionContext()).isEqualTo(ctx);
+ assertThat(c.hasEncryptionContext()).isTrue();
+ }
+
+ @Test
+ void testEncryptionContextIsDefensiveCopy() {
+ Map<String, String> ctx = new java.util.HashMap<>(Map.of("k", "v"));
+ S3EncryptionConfig c = S3EncryptionConfig.sseKms("key-id", ctx);
+ ctx.put("extra", "value");
+ assertThat(c.getEncryptionContext()).containsOnlyKeys("k");
+ }
+
+ @Test
+ void testNoEncryptionContextByDefault() {
+
assertThat(S3EncryptionConfig.sseKms().hasEncryptionContext()).isFalse();
+
assertThat(S3EncryptionConfig.sseKms().getEncryptionContext()).isEmpty();
+ }
+
+ // ---- fromConfig ----
+
+ @ParameterizedTest
+ @MethodSource
+ void testFromConfigParsesType(String input,
S3EncryptionConfig.EncryptionType expected) {
+ assertThat(
+ S3EncryptionConfig.fromConfig(input, null,
Collections.emptyMap())
+ .getEncryptionType())
+ .isEqualTo(expected);
+ }
+
+ static Stream<Arguments> testFromConfigParsesType() {
+ return Stream.of(
+ Arguments.of(null, NONE),
+ Arguments.of("", NONE),
+ Arguments.of("none", NONE),
+ Arguments.of("NONE", NONE),
+ Arguments.of("sse-s3", SSE_S3),
+ Arguments.of("AES256", SSE_S3),
+ Arguments.of("sse-kms", SSE_KMS),
+ Arguments.of("aws:kms", SSE_KMS));
+ }
+
+ @Test
+ void testFromConfigSseKmsKeyId() {
+ assertThat(
+ S3EncryptionConfig.fromConfig("sse-kms", "my-key",
Collections.emptyMap())
+ .getKmsKeyId())
+ .isEqualTo("my-key");
+ assertThat(
+ S3EncryptionConfig.fromConfig("sse-kms", "",
Collections.emptyMap())
+ .getKmsKeyId())
+ .isNull();
+ assertThat(
+ S3EncryptionConfig.fromConfig("sse-kms", null,
Collections.emptyMap())
+ .getKmsKeyId())
+ .isNull();
+ assertThat(
+ S3EncryptionConfig.fromConfig("sse-kms", "my-key",
Map.of("env", "prod"))
+ .getEncryptionContext())
+ .isEqualTo(Map.of("env", "prod"));
+ assertThat(
+ S3EncryptionConfig.fromConfig("sse-kms", null,
Map.of("env", "prod"))
Review Comment:
Done. Test renamed to
`fromConfig_sseKmsDefaultKeyWithContext_contextPreserved` and assertion flipped
to `isTrue()`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]