From 435367a94652d486002e3edbb3a115a5ca6cf28d Mon Sep 17 00:00:00 2001 From: Jakob Vogel Date: Tue, 22 Sep 2020 12:50:32 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Adds=20test=20case=20reproducing=20behaviou?= =?UTF-8?q?r=20described=20in=20issue=20=F0=9F=91=AF=E2=80=8D=E2=99=82?= =?UTF-8?q?=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #153 --- src/test/java/BaseAWSSpec.groovy | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/test/java/BaseAWSSpec.groovy b/src/test/java/BaseAWSSpec.groovy index 8100ff9..e7a99ab 100644 --- a/src/test/java/BaseAWSSpec.groovy +++ b/src/test/java/BaseAWSSpec.groovy @@ -10,12 +10,16 @@ import com.amazonaws.services.s3.AmazonS3Client import com.amazonaws.services.s3.model.AmazonS3Exception import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest import com.amazonaws.services.s3.model.ObjectMetadata +import com.amazonaws.services.s3.model.ResponseHeaderOverrides import com.amazonaws.services.s3.transfer.TransferManagerBuilder import com.google.common.base.Charsets import com.google.common.io.ByteStreams import com.google.common.io.Files import sirius.kernel.BaseSpecification +import java.time.Instant +import java.time.temporal.ChronoUnit + abstract class BaseAWSSpec extends BaseSpecification { abstract AmazonS3Client getClient() @@ -194,4 +198,35 @@ abstract class BaseAWSSpec extends BaseSpecification { downloadedData == content } + // reported in https://github.com/scireum/s3ninja/issues/153 + def "PUT and then GET on presigned URL with ResponseHeaderOverrides works as expected"() { + given: + def client = getClient() + when: + if (!client.doesBucketExist("test")) { + client.createBucket("test") + } + and: + client.putObject( + "test", + "test", + new ByteArrayInputStream("Test".getBytes(Charsets.UTF_8)), + new ObjectMetadata()) + def content = new String( + ByteStreams.toByteArray(client.getObject("test", "test").getObjectContent()), + Charsets.UTF_8) + and: + GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest("test", "test") + .withExpiration(Date.from(Instant.now().plus(1, ChronoUnit.HOURS))) + .withResponseHeaders( + new ResponseHeaderOverrides() + .withContentDisposition("inline; filename=\"hello.txt\"")) + URLConnection c = new URL(getClient().generatePresignedUrl(request).toString()).openConnection() + and: + String downloadedData = new String(ByteStreams.toByteArray(c.getInputStream()), Charsets.UTF_8) + then: + content == "Test" + and: + downloadedData == "Test" + } } From 0902564b549fa02c1cbbe9e2ba5f68e523e777f9 Mon Sep 17 00:00:00 2001 From: Jakob Vogel Date: Tue, 22 Sep 2020 13:14:12 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Encodes=20spaces=20as=20`%20`=20instead=20o?= =?UTF-8?q?f=20`+`=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #153 --- src/main/java/ninja/Aws4HashCalculator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ninja/Aws4HashCalculator.java b/src/main/java/ninja/Aws4HashCalculator.java index 81b1821..70509c8 100644 --- a/src/main/java/ninja/Aws4HashCalculator.java +++ b/src/main/java/ninja/Aws4HashCalculator.java @@ -168,7 +168,7 @@ private void appendQueryStringValue(String name, } canonicalRequest.append(Strings.urlEncode(name)); canonicalRequest.append("="); - canonicalRequest.append(Strings.urlEncode(value)); + canonicalRequest.append(Strings.urlEncode(value).replace("+", "%20")); } private String hashedCanonicalRequest(final StringBuilder canonicalRequest) {