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

jamesnetherton pushed a commit to branch 2.7.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit e1935c1df393ae3b1bed1864a43010d6dbb518a8
Author: James Netherton <jamesnether...@gmail.com>
AuthorDate: Fri May 6 10:54:40 2022 +0100

    Fix verification of AWS S3 download links
---
 .../aws2-quarkus-client/aws2-s3/pom.xml            |  2 +-
 .../aws2/s3/it/AwsS3PresignerProducer.java         | 60 ++++++++++++++++++++++
 .../quarkus/component/aws2/s3/it/Aws2S3Test.java   | 25 +++------
 .../aws2-quarkus-client-grouped/pom.xml            |  2 +-
 4 files changed, 70 insertions(+), 19 deletions(-)

diff --git a/integration-test-groups/aws2-quarkus-client/aws2-s3/pom.xml 
b/integration-test-groups/aws2-quarkus-client/aws2-s3/pom.xml
index 02dec136dc..fc21f41819 100644
--- a/integration-test-groups/aws2-quarkus-client/aws2-s3/pom.xml
+++ b/integration-test-groups/aws2-quarkus-client/aws2-s3/pom.xml
@@ -128,7 +128,7 @@
                             <properties>
                                 
<copy-tests.source.dir>${maven.multiModuleProjectDirectory}/integration-test-groups/aws2/aws2-s3</copy-tests.source.dir>
                                 
<copy-tests.dest.module.dir>${project.basedir}</copy-tests.dest.module.dir>
-                                
<copy-tests.excludes>**/*TestEnvCustomizer,**/*application.properties</copy-tests.excludes>
+                                
<copy-tests.excludes>**/*TestEnvCustomizer,**/*application.properties,**/*AwsS3PresignerProducer.java</copy-tests.excludes>
                             </properties>
                         </configuration>
                     </execution>
diff --git 
a/integration-test-groups/aws2/aws2-s3/src/main/java/org/apache/camel/quarkus/component/aws2/s3/it/AwsS3PresignerProducer.java
 
b/integration-test-groups/aws2/aws2-s3/src/main/java/org/apache/camel/quarkus/component/aws2/s3/it/AwsS3PresignerProducer.java
new file mode 100644
index 0000000000..a5b8fa852e
--- /dev/null
+++ 
b/integration-test-groups/aws2/aws2-s3/src/main/java/org/apache/camel/quarkus/component/aws2/s3/it/AwsS3PresignerProducer.java
@@ -0,0 +1,60 @@
+/*
+ * 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.quarkus.component.aws2.s3.it;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Optional;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Singleton;
+
+import org.eclipse.microprofile.config.inject.ConfigProperty;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.s3.internal.signing.DefaultS3Presigner;
+import software.amazon.awssdk.services.s3.presigner.S3Presigner;
+
+@ApplicationScoped
+public class AwsS3PresignerProducer {
+
+    @ConfigProperty(name = "camel.component.aws2-s3.uri-endpoint-override")
+    Optional<String> uriEndpointOverride;
+
+    @ConfigProperty(name = "camel.component.aws2-s3.region")
+    String region;
+
+    @ConfigProperty(name = "camel.component.aws2-s3.access-key")
+    String accessKey;
+
+    @ConfigProperty(name = "camel.component.aws2-s3.secret-key")
+    String secretKey;
+
+    @Singleton
+    public S3Presigner awsS3Presigner() throws URISyntaxException {
+        if (uriEndpointOverride.isPresent()) {
+            return DefaultS3Presigner.builder()
+                    .region(Region.of(region))
+                    .credentialsProvider(StaticCredentialsProvider.create(
+                            AwsBasicCredentials.create(accessKey, secretKey)))
+                    .endpointOverride(new URI(uriEndpointOverride.get()))
+                    .build();
+        }
+        return null;
+    }
+}
diff --git 
a/integration-test-groups/aws2/aws2-s3/src/test/java/org/apache/camel/quarkus/component/aws2/s3/it/Aws2S3Test.java
 
b/integration-test-groups/aws2/aws2-s3/src/test/java/org/apache/camel/quarkus/component/aws2/s3/it/Aws2S3Test.java
index 4cd2c26d85..2596c4d03c 100644
--- 
a/integration-test-groups/aws2/aws2-s3/src/test/java/org/apache/camel/quarkus/component/aws2/s3/it/Aws2S3Test.java
+++ 
b/integration-test-groups/aws2/aws2-s3/src/test/java/org/apache/camel/quarkus/component/aws2/s3/it/Aws2S3Test.java
@@ -17,6 +17,8 @@
 package org.apache.camel.quarkus.component.aws2.s3.it;
 
 import java.net.URI;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
 import java.util.Locale;
 import java.util.UUID;
 import java.util.stream.Stream;
@@ -304,23 +306,12 @@ class Aws2S3Test {
             final URI downloadUri = new URI(downloadLink);
 
             // Make sure that the download link works
-            // Note that localstack produces a real AWS link so when testing 
against localstack,
-            // the link won't work
-            final String realKey = System.getenv("AWS_ACCESS_KEY");
-            final String realSecret = System.getenv("AWS_SECRET_KEY");
-            final String realRegion = System.getenv("AWS_REGION");
-            final boolean realCredentialsProvided = realKey != null && 
realSecret != null && realRegion != null;
-            if (realCredentialsProvided) {
-                RestAssured.given()
-                        .log().all()
-                        .contentType(ContentType.TEXT)
-                        .port(downloadUri.getPort())
-                        .get(downloadLink)
-                        .then()
-                        .statusCode(200)
-                        .body(is(blobContent));
-            }
-
+            RestAssured.given()
+                    .port(downloadUri.getPort())
+                    .get(URLDecoder.decode(downloadLink, 
StandardCharsets.UTF_8))
+                    .then()
+                    .statusCode(200)
+                    .body(is(blobContent));
         } finally {
             // Delete
             deleteObject(oid);
diff --git a/integration-tests/aws2-quarkus-client-grouped/pom.xml 
b/integration-tests/aws2-quarkus-client-grouped/pom.xml
index 69c4dfe679..fed6ab5bfb 100644
--- a/integration-tests/aws2-quarkus-client-grouped/pom.xml
+++ b/integration-tests/aws2-quarkus-client-grouped/pom.xml
@@ -209,7 +209,7 @@
                             <properties>
                                 
<copy-tests.source.dir>${maven.multiModuleProjectDirectory}/integration-test-groups/aws2/aws2-s3</copy-tests.source.dir>
                                 
<copy-tests.dest.module.dir>${project.basedir}</copy-tests.dest.module.dir>
-                                
<copy-tests.excludes>**/*TestEnvCustomizer,**/*application.properties</copy-tests.excludes>
+                                
<copy-tests.excludes>**/*TestEnvCustomizer,**/*application.properties,**/*AwsS3PresignerProducer.java</copy-tests.excludes>
                             </properties>
                         </configuration>
                     </execution>

Reply via email to