-
Notifications
You must be signed in to change notification settings - Fork 997
added part count validation for download request #6353
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
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ed1e4f1
added part count and content range validation for download
Fred1155 391a506
changelog added
Fred1155 fc956ac
remove contentRange validation since part size could different
Fred1155 c1acdd8
feedback addressed
Fred1155 fd674d0
delete unused utils
Fred1155 450368b
change validation in futurn complete
Fred1155 a272a7a
added unit test
Fred1155 355ec82
Merge branch 'master' into bole/partcount-range-validation
Fred1155 13de014
change test name
Fred1155 a556358
minor change
Fred1155 72e94fa
minor change
Fred1155 c70e5cf
Merge branch 'master' into bole/partcount-range-validation
Fred1155 a790c8b
Merge branch 'master' into bole/partcount-range-validation
Fred1155 6eaf6df
Integration test added
Fred1155 45a9635
Merge branch 'master' into bole/partcount-range-validation
Fred1155 749fc3c
Unit test fixed
Fred1155 a3c55cb
swap method body of onError and handleError
Fred1155 80ae743
minor change
Fred1155 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,6 @@ | ||
| { | ||
| "type": "bugfix", | ||
| "category": "Amazon S3", | ||
| "contributor": "", | ||
| "description": "Added additional validations for multipart download operations in the Java multipart S3 client" | ||
| } |
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
120 changes: 120 additions & 0 deletions
120
.../services/s3/internal/multipart/MultipartDownloaderSubscriberPartCountValidationTest.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,120 @@ | ||
| /* | ||
| * Copyright 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.internal.multipart; | ||
|
|
||
|
|
||
| import static org.junit.Assert.assertThrows; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.mockito.ArgumentMatchers.eq; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.ExecutionException; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.Mock; | ||
| import org.mockito.MockitoAnnotations; | ||
| import org.reactivestreams.Subscription; | ||
| import software.amazon.awssdk.core.async.AsyncResponseTransformer; | ||
| import software.amazon.awssdk.core.exception.SdkClientException; | ||
| import software.amazon.awssdk.services.s3.S3AsyncClient; | ||
| import software.amazon.awssdk.services.s3.model.GetObjectRequest; | ||
| import software.amazon.awssdk.services.s3.model.GetObjectResponse; | ||
|
|
||
| public class MultipartDownloaderSubscriberPartCountValidationTest { | ||
| @Mock | ||
| private S3AsyncClient s3Client; | ||
|
|
||
| @Mock | ||
| private Subscription subscription; | ||
|
|
||
| @Mock | ||
| private AsyncResponseTransformer<GetObjectResponse, GetObjectResponse> responseTransformer; | ||
|
|
||
| private GetObjectRequest getObjectRequest; | ||
| private MultipartDownloaderSubscriber subscriber; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| MockitoAnnotations.openMocks(this); | ||
| getObjectRequest = GetObjectRequest.builder() | ||
| .bucket("test-bucket") | ||
| .key("test-key") | ||
| .build(); | ||
| } | ||
|
|
||
| @Test | ||
| void callCountMatchesTotalParts_shouldPass() throws InterruptedException { | ||
| subscriber = new MultipartDownloaderSubscriber(s3Client, getObjectRequest); | ||
| GetObjectResponse response1 = createMockResponse(3, "etag1"); | ||
| GetObjectResponse response2 = createMockResponse(3, "etag2"); | ||
| GetObjectResponse response3 = createMockResponse(3, "etag3"); | ||
|
|
||
| CompletableFuture<GetObjectResponse> future1 = CompletableFuture.completedFuture(response1); | ||
| CompletableFuture<GetObjectResponse> future2 = CompletableFuture.completedFuture(response2); | ||
| CompletableFuture<GetObjectResponse> future3 = CompletableFuture.completedFuture(response3); | ||
|
|
||
| when(s3Client.getObject(any(GetObjectRequest.class), eq(responseTransformer))) | ||
| .thenReturn(future1, future2, future3); | ||
|
|
||
| subscriber.onSubscribe(subscription); | ||
| subscriber.onNext(responseTransformer); | ||
| subscriber.onNext(responseTransformer); | ||
| subscriber.onNext(responseTransformer); | ||
| Thread.sleep(100); | ||
|
|
||
| subscriber.onComplete(); | ||
|
|
||
| assertDoesNotThrow(() -> subscriber.future().get(1, TimeUnit.SECONDS)); | ||
| } | ||
|
|
||
| @Test | ||
| void callCountMoreThanTotalParts_shouldThrowException() throws InterruptedException { | ||
| subscriber = new MultipartDownloaderSubscriber(s3Client, getObjectRequest, 3); | ||
| GetObjectResponse response1 = createMockResponse(2, "etag1"); | ||
|
|
||
| CompletableFuture<GetObjectResponse> future1 = CompletableFuture.completedFuture(response1); | ||
|
|
||
| when(s3Client.getObject(any(GetObjectRequest.class), eq(responseTransformer))) | ||
| .thenReturn(future1); | ||
|
|
||
| subscriber.onSubscribe(subscription); | ||
| subscriber.onNext(responseTransformer); | ||
| Thread.sleep(100); | ||
|
|
||
| subscriber.onComplete(); | ||
|
|
||
| ExecutionException exception = assertThrows(ExecutionException.class, | ||
| () -> subscriber.future().get(1, TimeUnit.SECONDS)); | ||
| assertTrue(exception.getCause() instanceof SdkClientException); | ||
| assertTrue(exception.getCause().getMessage().contains("PartsCount validation failed")); | ||
| assertTrue(exception.getCause().getMessage().contains("Expected 2, downloaded 4 parts")); | ||
|
|
||
| } | ||
|
|
||
| private GetObjectResponse createMockResponse(int partsCount, String etag) { | ||
| GetObjectResponse.Builder builder = GetObjectResponse.builder() | ||
| .eTag(etag) | ||
| .contentLength(1024L); | ||
|
|
||
| builder.partsCount(partsCount); | ||
| return builder.build(); | ||
| } | ||
|
|
||
| } |
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
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.
Just curious, why are we making this change?
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.
I used this change to do some testing, but that testing is deleted. Figured this change makes the response more "real" so I kept it