-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Verifying ContentRange on response from GetObject #3604
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
Open
pulimsr
wants to merge
6
commits into
main
Choose a base branch
from
transfer-manager
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+249
−24
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7416dbf
Verifying ContentRange on response from GetObject
pulimsr feb6137
Merge branch 'main' of https://github.com/aws/aws-sdk-cpp into transf…
pulimsr e451630
adding tranfermanager unit tests and updating error case for contentR…
pulimsr 0e3db48
Merge branch 'main' of https://github.com/aws/aws-sdk-cpp into transf…
pulimsr a1f9c72
Merge branch 'main' of https://github.com/aws/aws-sdk-cpp into transf…
pulimsr de95b1e
unit test for mock contentrange response
pulimsr 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
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
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,31 @@ | ||
| add_project(aws-cpp-sdk-transfer-unit-tests | ||
| "Unit Tests for the Transfer Manager" | ||
| aws-cpp-sdk-transfer | ||
| aws-cpp-sdk-s3 | ||
| testing-resources | ||
| aws_test_main | ||
| aws-cpp-sdk-core) | ||
|
|
||
| add_definitions(-DRESOURCES_DIR="${CMAKE_CURRENT_SOURCE_DIR}/resources") | ||
|
|
||
| if(MSVC AND BUILD_SHARED_LIBS) | ||
| add_definitions(-DGTEST_LINKED_AS_SHARED_LIBRARY=1) | ||
| endif() | ||
|
|
||
| enable_testing() | ||
|
|
||
| if(PLATFORM_ANDROID AND BUILD_SHARED_LIBS) | ||
| add_library(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/TransferUnitTests.cpp) | ||
| else() | ||
| add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/TransferUnitTests.cpp) | ||
| endif() | ||
|
|
||
| set_compiler_flags(${PROJECT_NAME}) | ||
| set_compiler_warnings(${PROJECT_NAME}) | ||
|
|
||
| target_link_libraries(${PROJECT_NAME} ${PROJECT_LIBS}) | ||
|
|
||
| if(MSVC AND BUILD_SHARED_LIBS) | ||
| set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/DELAYLOAD:aws-cpp-sdk-transfer.dll /DELAYLOAD:aws-cpp-sdk-core.dll") | ||
| target_link_libraries(${PROJECT_NAME} delayimp.lib) | ||
| endif() |
110 changes: 110 additions & 0 deletions
110
tests/aws-cpp-sdk-transfer-unit-tests/TransferUnitTests.cpp
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,110 @@ | ||
| #include <gtest/gtest.h> | ||
| #include <aws/core/Aws.h> | ||
| #include <aws/core/utils/threading/PooledThreadExecutor.h> | ||
| #include <aws/s3/S3Client.h> | ||
| #include <aws/s3/model/GetObjectRequest.h> | ||
| #include <aws/s3/model/GetObjectResult.h> | ||
| #include <aws/transfer/TransferManager.h> | ||
| #include <aws/testing/AwsTestHelpers.h> | ||
| #include <aws/testing/MemoryTesting.h> | ||
| #include <sstream> | ||
|
|
||
| using namespace Aws; | ||
| using namespace Aws::S3; | ||
| using namespace Aws::S3::Model; | ||
| using namespace Aws::Transfer; | ||
| using namespace Aws::Utils::Threading; | ||
|
|
||
| const char* ALLOCATION_TAG = "TransferUnitTest"; | ||
|
|
||
| class MockS3Client : public S3Client { | ||
| public: | ||
| MockS3Client() : S3Client(), shouldReturnWrongRange(false) {} | ||
|
|
||
| void SetReturnWrongRange(bool wrongRange) { | ||
| shouldReturnWrongRange = wrongRange; | ||
| } | ||
|
|
||
| GetObjectOutcome GetObject(const GetObjectRequest& request) const override { | ||
| GetObjectResult result; | ||
|
|
||
| if (request.RangeHasBeenSet()) { | ||
| if (shouldReturnWrongRange) { | ||
| // Return a different range than requested | ||
| result.SetContentRange("bytes 1024-2047/2048"); | ||
| } else { | ||
| // Parse the requested range and return matching ContentRange | ||
| Aws::String requestRange = request.GetRange(); | ||
| if (requestRange.find("bytes=") == 0) { | ||
| Aws::String range = requestRange.substr(6); // Remove "bytes=" | ||
| result.SetContentRange("bytes " + range + "/2048"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Create a raw pointer stream | ||
| auto stream = Aws::New<std::stringstream>(ALLOCATION_TAG); | ||
| *stream << "mock data"; | ||
| result.ReplaceBody(stream); | ||
|
|
||
| return GetObjectOutcome(std::move(result)); | ||
| } | ||
|
|
||
| private: | ||
| bool shouldReturnWrongRange; | ||
| }; | ||
|
|
||
| class TransferUnitTest : public testing::Test { | ||
| protected: | ||
| void SetUp() override { | ||
| executor = Aws::MakeShared<PooledThreadExecutor>(ALLOCATION_TAG, 1); | ||
| mockS3Client = Aws::MakeShared<MockS3Client>(ALLOCATION_TAG); | ||
| } | ||
|
|
||
| static void SetUpTestSuite() { | ||
| #ifdef USE_AWS_MEMORY_MANAGEMENT | ||
| _testMemorySystem.reset(new ExactTestMemorySystem(1024, 128)); | ||
| _options.memoryManagementOptions.memoryManager = _testMemorySystem.get(); | ||
| #endif | ||
| InitAPI(_options); | ||
| } | ||
|
|
||
| static void TearDownTestSuite() { | ||
| ShutdownAPI(_options); | ||
| #ifdef USE_AWS_MEMORY_MANAGEMENT | ||
| EXPECT_EQ(_testMemorySystem->GetCurrentOutstandingAllocations(), 0ULL); | ||
| EXPECT_EQ(_testMemorySystem->GetCurrentBytesAllocated(), 0ULL); | ||
| EXPECT_TRUE(_testMemorySystem->IsClean()); | ||
| _testMemorySystem.reset(); | ||
| #endif | ||
| } | ||
|
|
||
| std::shared_ptr<PooledThreadExecutor> executor; | ||
| std::shared_ptr<MockS3Client> mockS3Client; | ||
| static SDKOptions _options; | ||
| #ifdef USE_AWS_MEMORY_MANAGEMENT | ||
| static std::unique_ptr<ExactTestMemorySystem> _testMemorySystem; | ||
| #endif | ||
| }; | ||
|
|
||
| SDKOptions TransferUnitTest::_options; | ||
| #ifdef USE_AWS_MEMORY_MANAGEMENT | ||
| std::unique_ptr<ExactTestMemorySystem> TransferUnitTest::_testMemorySystem = nullptr; | ||
| #endif | ||
|
|
||
| TEST_F(TransferUnitTest, ContentRangeVerification_Failure) { | ||
| mockS3Client->SetReturnWrongRange(true); | ||
|
|
||
| TransferManagerConfiguration config(executor.get()); | ||
| config.s3Client = mockS3Client; | ||
| auto transferManager = TransferManager::Create(config); | ||
|
|
||
| auto createStreamFn = []() { | ||
| return Aws::New<std::stringstream>(ALLOCATION_TAG); | ||
| }; | ||
|
|
||
| auto handle = transferManager->DownloadFile("test-bucket", "test-key", 0, 1024, createStreamFn); | ||
| handle->WaitUntilFinished(); | ||
|
|
||
| EXPECT_EQ(TransferStatus::FAILED, handle->GetStatus()); | ||
| } |
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 there also be a test with a false content range to test for failures?
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'll look into creating a mock S3 response with an incorrect ContentRange to test the failure path
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.
+1 i think even as going as far to have a "transfer manager unit test" might be good. you can largely copy the S3 unit tests to create the skeleton of it.