Skip to content
Permalink
Browse files
Fix verification of AWS S3 download links
  • Loading branch information
jamesnetherton committed May 6, 2022
1 parent 6535e50 commit 313676b8fcaac9ee7cc42dd8359c9db47b8a2a1f
Showing 4 changed files with 70 additions and 19 deletions.
@@ -122,7 +122,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>
@@ -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;
}
}
@@ -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 @@ public void downloadLink() throws Exception {
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);
@@ -203,7 +203,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>

0 comments on commit 313676b

Please sign in to comment.