You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/04/17 13:43:56 UTC

[camel] 07/10: CAMEL-14845 - camel-aws2-s3 - CopyObject doesn't support ServerSideEncryption, fixed tests naming

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 377991f6ae5de58e4033f032562748abf07d93e6
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Apr 17 15:01:02 2020 +0200

    CAMEL-14845 - camel-aws2-s3 - CopyObject doesn't support ServerSideEncryption, fixed tests naming
---
 ...yObjectCustomerKeyOperationIntegrationTest.java | 77 +++++++++++++++++++++-
 .../S3CopyObjectOperationIntegrationTest.java      | 77 +---------------------
 2 files changed, 77 insertions(+), 77 deletions(-)

diff --git a/components/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/integration/S3CopyObjectCustomerKeyOperationIntegrationTest.java b/components/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/integration/S3CopyObjectCustomerKeyOperationIntegrationTest.java
index 3726c27..fa723a9 100644
--- a/components/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/integration/S3CopyObjectCustomerKeyOperationIntegrationTest.java
+++ b/components/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/integration/S3CopyObjectCustomerKeyOperationIntegrationTest.java
@@ -16,6 +16,18 @@
  */
 package org.apache.camel.component.aws2.s3.integration;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.security.SecureRandom;
+import java.util.Base64;
+import java.util.UUID;
+
+import javax.crypto.KeyGenerator;
+
 import org.apache.camel.BindToRegistry;
 import org.apache.camel.EndpointInject;
 import org.apache.camel.Exchange;
@@ -30,11 +42,24 @@ import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
 import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
+import software.amazon.awssdk.core.ResponseInputStream;
 import software.amazon.awssdk.regions.Region;
 import software.amazon.awssdk.services.s3.S3Client;
+import software.amazon.awssdk.services.s3.model.GetObjectRequest;
+import software.amazon.awssdk.services.s3.model.GetObjectResponse;
+import software.amazon.awssdk.utils.Md5Utils;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
+import static software.amazon.awssdk.services.s3.model.ServerSideEncryption.AES256;
 
 @Disabled("Must be manually tested. Provide your own accessKey and secretKey!")
 public class S3CopyObjectCustomerKeyOperationIntegrationTest extends CamelTestSupport {
+    
+    String key = UUID.randomUUID().toString();
+    byte[] secretKey = generateSecretKey();
+    String b64Key = Base64.getEncoder().encodeToString(secretKey);
+    String b64KeyMd5 = Md5Utils.md5AsBase64(secretKey);
 
     @BindToRegistry("amazonS3Client")
     S3Client client = S3Client.builder().credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("xxx", "yyy"))).region(Region.EU_WEST_1).build();
@@ -68,6 +93,27 @@ public class S3CopyObjectCustomerKeyOperationIntegrationTest extends CamelTestSu
                 exchange.getIn().setHeader(AWS2S3Constants.S3_OPERATION, AWS2S3Operations.copyObject);
             }
         });
+        
+        Exchange res = template.request("direct:getObject", new Processor() {
+
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                GetObjectRequest getObjectRequest = GetObjectRequest.builder()
+                    .key("test1.txt")
+                    .bucket("mycamel1")
+                    .sseCustomerKey(b64Key)
+                    .sseCustomerAlgorithm(AES256.name())
+                    .sseCustomerKeyMD5(b64KeyMd5)
+                    .build();
+                exchange.getIn().setHeader(AWS2S3Constants.S3_OPERATION, AWS2S3Operations.getObject);
+                exchange.getIn().setBody(getObjectRequest);
+            }
+        });
+        
+        ResponseInputStream<GetObjectResponse> s3 = res.getIn().getBody(ResponseInputStream.class);
+        
+
+        assertEquals("Test", readInputStream(s3));
 
         assertMockEndpointsSatisfied();
     }
@@ -77,13 +123,38 @@ public class S3CopyObjectCustomerKeyOperationIntegrationTest extends CamelTestSu
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                String awsEndpoint = "aws2-s3://mycamel?autoCreateBucket=false";
-
+                String awsEndpoint = "aws2-s3://mycamel?autoCreateBucket=false&useCustomerKey=true&customerKeyId=RAW(" + b64Key + ")&customerKeyMD5=RAW(" + b64KeyMd5 + ")&customerAlgorithm=" + AES256.name();
+                String awsEndpoint1 = "aws2-s3://mycamel1?autoCreateBucket=false&pojoRequest=true";
                 from("direct:putObject").to(awsEndpoint);
 
-                from("direct:copyObject").to(awsEndpoint).to("mock:result");
+                from("direct:copyObject").to(awsEndpoint);
+                
+                from("direct:getObject").to(awsEndpoint1).to("mock:result");
 
             }
         };
     }
+    
+    protected static byte[] generateSecretKey() {
+        KeyGenerator generator;
+        try {
+            generator = KeyGenerator.getInstance("AES");
+            generator.init(256, new SecureRandom());
+            return generator.generateKey().getEncoded();
+        } catch (Exception e) {
+            fail("Unable to generate symmetric key: " + e.getMessage());
+            return null;
+        }
+    }
+    
+    private String readInputStream(ResponseInputStream<GetObjectResponse> s3Object) throws IOException {
+        StringBuilder textBuilder = new StringBuilder();
+        try (Reader reader = new BufferedReader(new InputStreamReader(s3Object, Charset.forName(StandardCharsets.UTF_8.name())))) {
+            int c = 0;
+            while ((c = reader.read()) != -1) {
+                textBuilder.append((char)c);
+            }
+        }
+        return textBuilder.toString();
+    }
 }
diff --git a/components/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/integration/S3CopyObjectOperationIntegrationTest.java b/components/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/integration/S3CopyObjectOperationIntegrationTest.java
index fb0c6dd..b02c867 100644
--- a/components/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/integration/S3CopyObjectOperationIntegrationTest.java
+++ b/components/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/integration/S3CopyObjectOperationIntegrationTest.java
@@ -16,18 +16,6 @@
  */
 package org.apache.camel.component.aws2.s3.integration;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.security.SecureRandom;
-import java.util.Base64;
-import java.util.UUID;
-
-import javax.crypto.KeyGenerator;
-
 import org.apache.camel.BindToRegistry;
 import org.apache.camel.EndpointInject;
 import org.apache.camel.Exchange;
@@ -42,24 +30,11 @@ import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
 import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.core.ResponseInputStream;
 import software.amazon.awssdk.regions.Region;
 import software.amazon.awssdk.services.s3.S3Client;
-import software.amazon.awssdk.services.s3.model.GetObjectRequest;
-import software.amazon.awssdk.services.s3.model.GetObjectResponse;
-import software.amazon.awssdk.utils.Md5Utils;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
-import static software.amazon.awssdk.services.s3.model.ServerSideEncryption.AES256;
 
 @Disabled("Must be manually tested. Provide your own accessKey and secretKey!")
 public class S3CopyObjectOperationIntegrationTest extends CamelTestSupport {
-    
-    String key = UUID.randomUUID().toString();
-    byte[] secretKey = generateSecretKey();
-    String b64Key = Base64.getEncoder().encodeToString(secretKey);
-    String b64KeyMd5 = Md5Utils.md5AsBase64(secretKey);
 
     @BindToRegistry("amazonS3Client")
     S3Client client = S3Client.builder().credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("xxx", "yyy"))).region(Region.EU_WEST_1).build();
@@ -93,27 +68,6 @@ public class S3CopyObjectOperationIntegrationTest extends CamelTestSupport {
                 exchange.getIn().setHeader(AWS2S3Constants.S3_OPERATION, AWS2S3Operations.copyObject);
             }
         });
-        
-        Exchange res = template.request("direct:getObject", new Processor() {
-
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                GetObjectRequest getObjectRequest = GetObjectRequest.builder()
-                    .key("test1.txt")
-                    .bucket("mycamel1")
-                    .sseCustomerKey(b64Key)
-                    .sseCustomerAlgorithm(AES256.name())
-                    .sseCustomerKeyMD5(b64KeyMd5)
-                    .build();
-                exchange.getIn().setHeader(AWS2S3Constants.S3_OPERATION, AWS2S3Operations.getObject);
-                exchange.getIn().setBody(getObjectRequest);
-            }
-        });
-        
-        ResponseInputStream<GetObjectResponse> s3 = res.getIn().getBody(ResponseInputStream.class);
-        
-
-        assertEquals("Test", readInputStream(s3));
 
         assertMockEndpointsSatisfied();
     }
@@ -123,38 +77,13 @@ public class S3CopyObjectOperationIntegrationTest extends CamelTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                String awsEndpoint = "aws2-s3://mycamel?autoCreateBucket=false&useCustomerKey=true&customerKeyId=RAW(" + b64Key + ")&customerKeyMD5=RAW(" + b64KeyMd5 + ")&customerAlgorithm=" + AES256.name();
-                String awsEndpoint1 = "aws2-s3://mycamel1?autoCreateBucket=false&pojoRequest=true";
+                String awsEndpoint = "aws2-s3://mycamel?autoCreateBucket=false";
+
                 from("direct:putObject").to(awsEndpoint);
 
-                from("direct:copyObject").to(awsEndpoint);
-                
-                from("direct:getObject").to(awsEndpoint1).to("mock:result");
+                from("direct:copyObject").to(awsEndpoint).to("mock:result");
 
             }
         };
     }
-    
-    protected static byte[] generateSecretKey() {
-        KeyGenerator generator;
-        try {
-            generator = KeyGenerator.getInstance("AES");
-            generator.init(256, new SecureRandom());
-            return generator.generateKey().getEncoded();
-        } catch (Exception e) {
-            fail("Unable to generate symmetric key: " + e.getMessage());
-            return null;
-        }
-    }
-    
-    private String readInputStream(ResponseInputStream<GetObjectResponse> s3Object) throws IOException {
-        StringBuilder textBuilder = new StringBuilder();
-        try (Reader reader = new BufferedReader(new InputStreamReader(s3Object, Charset.forName(StandardCharsets.UTF_8.name())))) {
-            int c = 0;
-            while ((c = reader.read()) != -1) {
-                textBuilder.append((char)c);
-            }
-        }
-        return textBuilder.toString();
-    }
 }