-
Notifications
You must be signed in to change notification settings - Fork 916
Fixed s3 decoding response for ListObjectsVersion and ListMultipartUploads #1630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"category": "Amazon S3", | ||
"type": "bugfix", | ||
"description": "Fixed an issue where fields in `ListObjectVersionsResponse` and `ListMultipartUploadsResponse` are not decoded correctly when encodingType is specified as url. See [#1601](https://github.com/aws/aws-sdk-java-v2/issues/1601)" | ||
} |
134 changes: 134 additions & 0 deletions
134
services/s3/src/it/java/software/amazon/awssdk/services/s3/UrlEncodingIntegrationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* Copyright 2010-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 software.amazon.awssdk.services.s3; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static software.amazon.awssdk.testutils.service.S3BucketUtils.temporaryBucketName; | ||
|
||
import org.apache.commons.lang3.RandomStringUtils; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import software.amazon.awssdk.core.sync.RequestBody; | ||
import software.amazon.awssdk.services.s3.model.CreateMultipartUploadResponse; | ||
import software.amazon.awssdk.services.s3.model.EncodingType; | ||
import software.amazon.awssdk.services.s3.model.ListMultipartUploadsResponse; | ||
import software.amazon.awssdk.services.s3.model.ListObjectVersionsResponse; | ||
import software.amazon.awssdk.services.s3.model.ListObjectsResponse; | ||
import software.amazon.awssdk.services.s3.model.ListObjectsV2Response; | ||
import software.amazon.awssdk.services.s3.model.PutObjectRequest; | ||
import software.amazon.awssdk.services.s3.model.UploadPartResponse; | ||
|
||
/** | ||
* Integration tests for the operations that support encoding type | ||
*/ | ||
public class UrlEncodingIntegrationTest extends S3IntegrationTestBase { | ||
/** | ||
* The name of the bucket created, used, and deleted by these tests. | ||
*/ | ||
private static final String BUCKET_NAME = temporaryBucketName(UrlEncodingIntegrationTest.class); | ||
private static final String KEY_NAME_WITH_SPECIAL_CHARS = "filename_@_=_&_?_+_)_.temp"; | ||
|
||
@BeforeClass | ||
public static void createResources() { | ||
createBucket(BUCKET_NAME); | ||
s3.putObject(PutObjectRequest.builder() | ||
.bucket(BUCKET_NAME) | ||
.key(KEY_NAME_WITH_SPECIAL_CHARS) | ||
.build(), RequestBody.fromString(RandomStringUtils.random(1000))); | ||
} | ||
|
||
/** | ||
* Releases all resources created in this test. | ||
*/ | ||
@AfterClass | ||
public static void tearDown() { | ||
deleteBucketAndAllContents(BUCKET_NAME); | ||
} | ||
|
||
@Test | ||
public void listObjectVersionsWithUrlEncodingType_shouldDecode() { | ||
ListObjectVersionsResponse listObjectVersionsResponse = | ||
s3.listObjectVersions(b -> b.bucket(BUCKET_NAME).encodingType(EncodingType.URL)); | ||
listObjectVersionsResponse.versions().forEach(v -> assertKeyIsDecoded(v.key())); | ||
|
||
ListObjectVersionsResponse asyncResponse = | ||
s3Async.listObjectVersions(b -> b.bucket(BUCKET_NAME).encodingType(EncodingType.URL)).join(); | ||
|
||
asyncResponse.versions().forEach(v -> assertKeyIsDecoded(v.key())); | ||
} | ||
|
||
@Test | ||
public void listObjectV2WithUrlEncodingType_shouldDecode() { | ||
ListObjectsV2Response listObjectsV2Response = | ||
s3.listObjectsV2(b -> b.bucket(BUCKET_NAME).encodingType(EncodingType.URL)); | ||
|
||
listObjectsV2Response.contents().forEach(c -> assertKeyIsDecoded(c.key())); | ||
ListObjectVersionsResponse asyncResponse = | ||
s3Async.listObjectVersions(b -> b.bucket(BUCKET_NAME).encodingType(EncodingType.URL)).join(); | ||
|
||
asyncResponse.versions().forEach(v -> assertKeyIsDecoded(v.key())); | ||
} | ||
|
||
@Test | ||
public void listObjectWithUrlEncodingType_shouldDecode() { | ||
ListObjectsResponse listObjectsV2Response = | ||
s3.listObjects(b -> b.bucket(BUCKET_NAME).encodingType(EncodingType.URL)); | ||
|
||
listObjectsV2Response.contents().forEach(c -> assertKeyIsDecoded(c.key())); | ||
ListObjectVersionsResponse asyncResponse = | ||
s3Async.listObjectVersions(b -> b.bucket(BUCKET_NAME).encodingType(EncodingType.URL)).join(); | ||
|
||
asyncResponse.versions().forEach(v -> assertKeyIsDecoded(v.key())); | ||
} | ||
|
||
@Test | ||
public void listMultipartUploadsWithUrlEncodingType_shouldDecode() { | ||
String uploaddId = null; | ||
try { | ||
CreateMultipartUploadResponse multipartUploadResponse = | ||
s3.createMultipartUpload(b -> b.bucket(BUCKET_NAME).key(KEY_NAME_WITH_SPECIAL_CHARS)); | ||
uploaddId = multipartUploadResponse.uploadId(); | ||
|
||
String finalUploadId = uploaddId; | ||
UploadPartResponse uploadPartResponse = s3.uploadPart(b -> b.bucket(BUCKET_NAME) | ||
.key(KEY_NAME_WITH_SPECIAL_CHARS) | ||
.partNumber(1) | ||
.uploadId(finalUploadId), | ||
RequestBody.fromString(RandomStringUtils.random(1000))); | ||
|
||
|
||
ListMultipartUploadsResponse listMultipartUploadsResponse = | ||
s3.listMultipartUploads(b -> b.encodingType(EncodingType.URL).bucket(BUCKET_NAME)); | ||
|
||
listMultipartUploadsResponse.uploads().forEach(upload -> assertThat(upload.key()).isEqualTo(KEY_NAME_WITH_SPECIAL_CHARS)); | ||
|
||
ListMultipartUploadsResponse asyncListMultipartUploadsResponse = | ||
s3Async.listMultipartUploads(b -> b.encodingType(EncodingType.URL).bucket(BUCKET_NAME)).join(); | ||
|
||
asyncListMultipartUploadsResponse.uploads().forEach(upload -> assertKeyIsDecoded(upload.key())); | ||
} finally { | ||
if (uploaddId != null) { | ||
String finalUploadId = uploaddId; | ||
s3.abortMultipartUpload(b -> b.bucket(BUCKET_NAME).key(KEY_NAME_WITH_SPECIAL_CHARS).uploadId(finalUploadId)); | ||
} | ||
} | ||
} | ||
|
||
private void assertKeyIsDecoded(String key) { | ||
assertThat(key).isEqualTo(KEY_NAME_WITH_SPECIAL_CHARS); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should consider adding a backlog task to automate at least catching future S3 operations that expose similar behavior?
We could probably make it as simple as operations that have an
encodingType
parameterThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1