oscerd commented on code in PR #28553:
URL: https://github.com/apache/camel/pull/28553#discussion_r4386699315
##########
components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioProducer.java:
##########
@@ -196,6 +196,11 @@ private void doPutObject(
.object(objectName)
.userMetadata(objectMetadata);
+ MinioChecks.checkIfConfigIsNotEmptyAndSetAndConfig(
+ getConfiguration()::getServerSideEncryption,
putObjectRequest::sse);
+ MinioChecks.checkIfConfigIsNotEmptyAndSetAndConfig(
+ getConfiguration()::getServerSideEncryptionCustomerKey,
putObjectRequest::sse);
Review Comment:
Replaced all `MinioChecks` usages in `MinioProducer` with direct null
checks, completely eliminating `MinioChecks` from the producer.
##########
components/camel-minio/src/test/java/org/apache/camel/component/minio/MinioProducerEncryptionTest.java:
##########
@@ -0,0 +1,221 @@
+/*
+ * 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.camel.component.minio;
+
+import javax.crypto.KeyGenerator;
+import javax.crypto.SecretKey;
+
+import io.minio.BucketExistsArgs;
+import io.minio.CopyObjectArgs;
+import io.minio.GetObjectArgs;
+import io.minio.GetObjectResponse;
+import io.minio.MinioClient;
+import io.minio.ObjectWriteResponse;
+import io.minio.PutObjectArgs;
+import io.minio.ServerSideEncryption;
+import org.apache.camel.Exchange;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+class MinioProducerEncryptionTest extends CamelTestSupport {
+
+ private MinioClient minioClient;
+ private SecretKey secretKey;
+
+ @BeforeEach
+ void init() throws Exception {
+ minioClient = mock(MinioClient.class);
+
when(minioClient.bucketExists(any(BucketExistsArgs.class))).thenReturn(true);
+ KeyGenerator generator = KeyGenerator.getInstance("AES");
+ generator.init(256);
+ secretKey = generator.generateKey();
+ }
+
+ private MinioProducer createProducer(MinioEndpoint endpoint) throws
Exception {
+ endpoint.start();
+ MinioProducer producer = new MinioProducer(endpoint);
+ producer.start();
+ return producer;
+ }
+
+ @Test
+ void putObjectWithServerSideEncryption() throws Exception {
+ ServerSideEncryption.S3 sse = new ServerSideEncryption.S3();
+ MinioComponent component = context.getComponent("minio",
MinioComponent.class);
+ MinioEndpoint endpoint = (MinioEndpoint)
component.createEndpoint("minio://mybucket?autoCreateBucket=false");
+ endpoint.getConfiguration().setMinioClient(minioClient);
+ endpoint.getConfiguration().setServerSideEncryption(sse);
+
+
when(minioClient.putObject(any(PutObjectArgs.class))).thenReturn(mock(ObjectWriteResponse.class));
+
+ MinioProducer producer = createProducer(endpoint);
+ Exchange exchange = endpoint.createExchange();
+ exchange.getIn().setHeader(MinioConstants.OBJECT_NAME, "test.txt");
+ exchange.getIn().setBody("content");
+
+ producer.process(exchange);
+
+ ArgumentCaptor<PutObjectArgs> captor =
ArgumentCaptor.forClass(PutObjectArgs.class);
+ verify(minioClient).putObject(captor.capture());
+ assertSame(sse, captor.getValue().sse());
+ producer.stop();
+ endpoint.stop();
+ }
+
+ @Test
+ void putObjectWithCustomerKey() throws Exception {
+ ServerSideEncryption.CustomerKey ssec = new
ServerSideEncryption.CustomerKey(secretKey);
+ MinioComponent component = context.getComponent("minio",
MinioComponent.class);
+ MinioEndpoint endpoint = (MinioEndpoint)
component.createEndpoint("minio://mybucket?autoCreateBucket=false");
+ endpoint.getConfiguration().setMinioClient(minioClient);
+ endpoint.getConfiguration().setServerSideEncryptionCustomerKey(ssec);
+
+
when(minioClient.putObject(any(PutObjectArgs.class))).thenReturn(mock(ObjectWriteResponse.class));
+
+ MinioProducer producer = createProducer(endpoint);
+ Exchange exchange = endpoint.createExchange();
+ exchange.getIn().setHeader(MinioConstants.OBJECT_NAME, "test.txt");
+ exchange.getIn().setBody("content");
+
+ producer.process(exchange);
+
+ ArgumentCaptor<PutObjectArgs> captor =
ArgumentCaptor.forClass(PutObjectArgs.class);
+ verify(minioClient).putObject(captor.capture());
+ assertSame(ssec, captor.getValue().sse());
Review Comment:
Confirmed: the `PutObjectArgs.Builder` constructs the `PutObjectArgs`
instance on `.build()`, which is passed to `minioClient.putObject(...)` and
captured by the argument captor. Prior to the fix, the builder never received
an `sse(...)` configuration, so `captor.getValue().sse()` was `null` and
`assertSame` failed with an assertion error. The test is fully genuine and
exercises the active code path.
--
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]