Skip to content

Commit

Permalink
fix bug where we did not pass crt flex checksum configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
sbiscigl committed Aug 12, 2024
1 parent 6d758f3 commit 76d1a4e
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6275,6 +6275,7 @@ namespace Aws
std::shared_ptr<Aws::Http::HttpRequest> request;
std::shared_ptr<Aws::Http::HttpResponse> response;
std::shared_ptr<Aws::Crt::Http::HttpRequest> crtHttpRequest;
std::shared_ptr<struct aws_s3_checksum_config> checksumConfig;
};

Aws::Client::XmlOutcome GenerateXmlOutcome(const std::shared_ptr<Http::HttpResponse>& response) const;
Expand Down
46 changes: 46 additions & 0 deletions generated/src/aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,29 @@ void S3CrtClient::CopyObjectAsync(const CopyObjectRequest& request, const CopyOb
}
options.signing_config = &signing_config_override;

if (request.ChecksumAlgorithmHasBeenSet())
{
static std::pair<ChecksumAlgorithm, aws_s3_checksum_algorithm> crtChecksumMapping[]{
{ChecksumAlgorithm::CRC32, aws_s3_checksum_algorithm::AWS_SCA_CRC32},
{ChecksumAlgorithm::CRC32C, aws_s3_checksum_algorithm::AWS_SCA_CRC32C},
{ChecksumAlgorithm::SHA1, aws_s3_checksum_algorithm::AWS_SCA_SHA1},
{ChecksumAlgorithm::SHA256, aws_s3_checksum_algorithm::AWS_SCA_SHA256},
};

const auto checksumAlgorithm = request.GetChecksumAlgorithm();
const auto mapping = std::find_if(std::begin(crtChecksumMapping),
std::end(crtChecksumMapping),
[&checksumAlgorithm](const std::pair<ChecksumAlgorithm, aws_s3_checksum_algorithm>& mapping){ return mapping.first == checksumAlgorithm; });
if (mapping != std::end(crtChecksumMapping))
{
std::shared_ptr<struct aws_s3_checksum_config> checksum_config{Aws::New<struct aws_s3_checksum_config>(ALLOCATION_TAG)};
userData->checksumConfig = checksum_config;
checksum_config->checksum_algorithm = mapping->second;
checksum_config->location = AWS_SCL_TRAILER;
options.checksum_config = checksum_config.get();
}
}

std::shared_ptr<Aws::Crt::Http::HttpRequest> crtHttpRequest = userData->request->ToCrtHttpRequest();
options.message= crtHttpRequest->GetUnderlyingMessage();
userData->crtHttpRequest = crtHttpRequest;
Expand Down Expand Up @@ -1030,6 +1053,29 @@ void S3CrtClient::PutObjectAsync(const PutObjectRequest& request, const PutObjec
}
options.signing_config = &signing_config_override;

if (request.ChecksumAlgorithmHasBeenSet())
{
static std::pair<ChecksumAlgorithm, aws_s3_checksum_algorithm> crtChecksumMapping[]{
{ChecksumAlgorithm::CRC32, aws_s3_checksum_algorithm::AWS_SCA_CRC32},
{ChecksumAlgorithm::CRC32C, aws_s3_checksum_algorithm::AWS_SCA_CRC32C},
{ChecksumAlgorithm::SHA1, aws_s3_checksum_algorithm::AWS_SCA_SHA1},
{ChecksumAlgorithm::SHA256, aws_s3_checksum_algorithm::AWS_SCA_SHA256},
};

const auto checksumAlgorithm = request.GetChecksumAlgorithm();
const auto mapping = std::find_if(std::begin(crtChecksumMapping),
std::end(crtChecksumMapping),
[&checksumAlgorithm](const std::pair<ChecksumAlgorithm, aws_s3_checksum_algorithm>& mapping){ return mapping.first == checksumAlgorithm; });
if (mapping != std::end(crtChecksumMapping))
{
std::shared_ptr<struct aws_s3_checksum_config> checksum_config{Aws::New<struct aws_s3_checksum_config>(ALLOCATION_TAG)};
userData->checksumConfig = checksum_config;
checksum_config->checksum_algorithm = mapping->second;
checksum_config->location = AWS_SCL_TRAILER;
options.checksum_config = checksum_config.get();
}
}

std::shared_ptr<Aws::Crt::Http::HttpRequest> crtHttpRequest = userData->request->ToCrtHttpRequest();
options.message= crtHttpRequest->GetUnderlyingMessage();
userData->crtHttpRequest = crtHttpRequest;
Expand Down
19 changes: 19 additions & 0 deletions tests/aws-cpp-sdk-s3-crt-integration-tests/S3ExpressTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,25 @@ namespace {
}
}

TEST_F(S3ExpressTest, PutObjectChecksumWithoutAlgorithmValue) {
const auto bucketName = Testing::GetAwsResourcePrefix() + randomString() + S3_EXPRESS_SUFFIX;
const auto createOutcome = CreateBucket(bucketName);
AWS_EXPECT_SUCCESS(createOutcome);

auto request = PutObjectRequest()
.WithBucket(bucketName)
.WithKey("swingingparty")
.WithChecksumAlgorithm(ChecksumAlgorithm::CRC32);

std::shared_ptr<IOStream> body = Aws::MakeShared<StringStream>(ALLOCATION_TAG,
"Bring your own lampshade, somewhere there's a party.",
std::ios_base::in | std::ios_base::binary);
request.SetBody(body);

const auto response = client->PutObject(request);
AWS_EXPECT_SUCCESS(response);
}

TEST_F(S3ExpressTest, PutObjectChecksumWithoutAlgorithm) {
const auto bucketName = Testing::GetAwsResourcePrefix() + randomString() + S3_EXPRESS_SUFFIX;
const auto createOutcome = CreateBucket(bucketName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ namespace ${rootNamespace}
std::shared_ptr<Aws::Http::HttpRequest> request;
std::shared_ptr<Aws::Http::HttpResponse> response;
std::shared_ptr<Aws::Crt::Http::HttpRequest> crtHttpRequest;
std::shared_ptr<struct aws_s3_checksum_config> checksumConfig;
};

Aws::Client::XmlOutcome GenerateXmlOutcome(const std::shared_ptr<Http::HttpResponse>& response) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,31 @@ void ${className}::${operation.name}Async(${constText}${operation.request.shape.
signing_config_override.service = Aws::Crt::ByteCursorFromCString(computeEndpointOutcome.GetResult().signerServiceName.c_str());
#end
options.signing_config = &signing_config_override;
#if($operation.name == "PutObject" || $operation.name == "CopyObject")

if (request.ChecksumAlgorithmHasBeenSet())
{
static std::pair<ChecksumAlgorithm, aws_s3_checksum_algorithm> crtChecksumMapping[]{
{ChecksumAlgorithm::CRC32, aws_s3_checksum_algorithm::AWS_SCA_CRC32},
{ChecksumAlgorithm::CRC32C, aws_s3_checksum_algorithm::AWS_SCA_CRC32C},
{ChecksumAlgorithm::SHA1, aws_s3_checksum_algorithm::AWS_SCA_SHA1},
{ChecksumAlgorithm::SHA256, aws_s3_checksum_algorithm::AWS_SCA_SHA256},
};

const auto checksumAlgorithm = request.GetChecksumAlgorithm();
const auto mapping = std::find_if(std::begin(crtChecksumMapping),
std::end(crtChecksumMapping),
[&checksumAlgorithm](const std::pair<ChecksumAlgorithm, aws_s3_checksum_algorithm>& mapping){ return mapping.first == checksumAlgorithm; });
if (mapping != std::end(crtChecksumMapping))
{
std::shared_ptr<struct aws_s3_checksum_config> checksum_config{Aws::New<struct aws_s3_checksum_config>(ALLOCATION_TAG)};
userData->checksumConfig = checksum_config;
checksum_config->checksum_algorithm = mapping->second;
checksum_config->location = AWS_SCL_TRAILER;
options.checksum_config = checksum_config.get();
}
}
#end

std::shared_ptr<Aws::Crt::Http::HttpRequest> crtHttpRequest = userData->request->ToCrtHttpRequest();
options.message= crtHttpRequest->GetUnderlyingMessage();
Expand Down
2 changes: 1 addition & 1 deletion tools/scripts/run_integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def main():
"aws-cpp-sdk-sqs-integration-tests",
"aws-cpp-sdk-s3-integration-tests",
"aws-cpp-sdk-s3-unit-tests",
#"aws-cpp-sdk-s3-crt-integration-tests",
"aws-cpp-sdk-s3-crt-integration-tests",
#"aws-cpp-sdk-s3control-integration-tests",
# "aws-cpp-sdk-lambda-integration-tests",
"aws-cpp-sdk-cognitoidentity-integration-tests",
Expand Down

0 comments on commit 76d1a4e

Please sign in to comment.