Skip to content
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

fix aws chunked encoding for a empty stream #3261

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class AwsChunkedStream {
m_request->GetRequestHash().second->Update(reinterpret_cast<unsigned char *>(m_data.GetUnderlyingData()), bytesRead);
}

if (m_chunkingStream != nullptr && !m_chunkingStream->bad()) {
if (bytesRead > 0 && m_chunkingStream != nullptr && !m_chunkingStream->bad()) {
if (m_chunkingStream->eof()) {
m_chunkingStream->clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,19 @@ TEST_F(AwsChunkedStreamTest, ShouldWorkOnSmallBuffer) {
// Any subsequent reads will return 0 because all streams are exhausted
amountRead = chunkedStream.BufferedRead(outputBuffer.GetUnderlyingData(), 100);
EXPECT_EQ(0ul, amountRead);
}
}

TEST_F(AwsChunkedStreamTest, ShouldWorkOnEmptyStream) {
StandardHttpRequest request{"www.nidia.com/juna", Http::HttpMethod::HTTP_GET};
auto requestHash = Aws::MakeShared<CRC32>(TEST_LOG_TAG);
request.SetRequestHash("crc32", requestHash);
std::shared_ptr<IOStream> inputStream = Aws::MakeShared<StringStream>(TEST_LOG_TAG, "");
AwsChunkedStream<5> chunkedStream{&request, inputStream};
Aws::Utils::Array<char> outputBuffer{100};
Aws::StringStream firstRead;
auto amountRead = chunkedStream.BufferedRead(outputBuffer.GetUnderlyingData(), 100);
std::copy(outputBuffer.GetUnderlyingData(), outputBuffer.GetUnderlyingData() + amountRead, std::ostream_iterator<char>(firstRead));
EXPECT_EQ(36ul, amountRead);
auto encodedStr = firstRead.str();
EXPECT_EQ("0\r\nx-amz-checksum-crc32:AAAAAA==\r\n\r\n", encodedStr);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,28 @@ namespace
ASSERT_TRUE(isErrorEventReceived);
}

TEST_F(BucketAndObjectOperationTest, TestNullBody)
{
const Aws::String fullBucketName = CalculateBucketName(BASE_PUT_OBJECTS_BUCKET_NAME.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
CreateBucketRequest createBucketRequest;
createBucketRequest.SetBucket(fullBucketName);
createBucketRequest.SetACL(BucketCannedACL::private_);

CreateBucketOutcome createBucketOutcome = Client->CreateBucket(createBucketRequest);
AWS_ASSERT_SUCCESS(createBucketOutcome);
const CreateBucketResult& createBucketResult = createBucketOutcome.GetResult();
ASSERT_TRUE(!createBucketResult.GetLocation().empty());
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName));
TagTestBucket(fullBucketName, Client);

PutObjectRequest putObjectRequest;
putObjectRequest.SetBucket(fullBucketName);
putObjectRequest.SetKey("sbiscigl_was_here_null");
PutObjectOutcome putObjectOutcome = Client->PutObject(putObjectRequest);
AWS_ASSERT_SUCCESS(putObjectOutcome);
}

TEST_F(BucketAndObjectOperationTest, TestEmptyBody)
{
const Aws::String fullBucketName = CalculateBucketName(BASE_PUT_OBJECTS_BUCKET_NAME.c_str());
Expand All @@ -1328,7 +1350,8 @@ namespace

PutObjectRequest putObjectRequest;
putObjectRequest.SetBucket(fullBucketName);
putObjectRequest.SetKey("sbiscigl_was_here");
putObjectRequest.SetKey("sbiscigl_was_here_empty");
putObjectRequest.SetBody(Aws::MakeShared<StringStream>(ALLOCATION_TAG, ""));
PutObjectOutcome putObjectOutcome = Client->PutObject(putObjectRequest);
AWS_ASSERT_SUCCESS(putObjectOutcome);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2387,6 +2387,28 @@ namespace
}
}

TEST_F(BucketAndObjectOperationTest, TestNullBody) {
const Aws::String fullBucketName = CalculateBucketName(BASE_PUT_OBJECTS_BUCKET_NAME.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);

CreateBucketRequest createBucketRequest;
createBucketRequest.SetBucket(fullBucketName);
createBucketRequest.SetACL(BucketCannedACL::private_);

CreateBucketOutcome createBucketOutcome = CreateBucket(createBucketRequest);
AWS_ASSERT_SUCCESS(createBucketOutcome);
const CreateBucketResult& createBucketResult = createBucketOutcome.GetResult();
ASSERT_TRUE(!createBucketResult.GetLocation().empty());
ASSERT_TRUE(WaitForBucketToPropagate(fullBucketName, Client));
TagTestBucket(fullBucketName, Client);

PutObjectRequest putObjectRequest;
putObjectRequest.SetBucket(fullBucketName);
putObjectRequest.SetKey("sbiscigl_was_here_null");
PutObjectOutcome putObjectOutcome = Client->PutObject(putObjectRequest);
AWS_ASSERT_SUCCESS(putObjectOutcome);
}

TEST_F(BucketAndObjectOperationTest, TestEmptyBody) {
const Aws::String fullBucketName = CalculateBucketName(BASE_PUT_OBJECTS_BUCKET_NAME.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
Expand All @@ -2404,7 +2426,8 @@ namespace

PutObjectRequest putObjectRequest;
putObjectRequest.SetBucket(fullBucketName);
putObjectRequest.SetKey("sbiscigl_was_here");
putObjectRequest.SetKey("sbiscigl_was_here_empty");
putObjectRequest.SetBody(Aws::MakeShared<StringStream>(ALLOCATION_TAG, ""));
PutObjectOutcome putObjectOutcome = Client->PutObject(putObjectRequest);
AWS_ASSERT_SUCCESS(putObjectOutcome);
}
Expand Down
Loading