From 72c3ba638b0d63e0b5c97ac04b386f6b3092bd3a Mon Sep 17 00:00:00 2001 From: Tianyi Wang Date: Sun, 29 Sep 2024 16:53:46 -0400 Subject: [PATCH] separate checksum config check and workflow --- .../9ebe24c4791541e0840da49eab6f9d97.json | 2 +- aws/checksum.go | 29 +- .../go/codegen/AwsHttpChecksumGenerator.java | 21 +- .../smithy/aws/go/codegen/SdkGoTypes.java | 5 - config/env_config.go | 4 +- config/load_options.go | 8 +- config/shared_config.go | 4 +- service/internal/checksum/middleware_add.go | 26 +- .../internal/checksum/middleware_add_test.go | 7 +- .../middleware_compute_input_checksum.go | 54 +--- .../middleware_compute_input_checksum_test.go | 298 +----------------- .../checksum/middleware_setup_context.go | 39 ++- .../checksum/middleware_setup_context_test.go | 100 +++++- .../checksum/middleware_validate_output.go | 19 +- .../middleware_validate_output_test.go | 91 ++---- service/s3/api_op_DeleteObjects.go | 3 +- service/s3/api_op_GetObject.go | 2 - ...api_op_PutBucketAccelerateConfiguration.go | 3 +- service/s3/api_op_PutBucketAcl.go | 3 +- service/s3/api_op_PutBucketCors.go | 3 +- service/s3/api_op_PutBucketEncryption.go | 3 +- .../api_op_PutBucketLifecycleConfiguration.go | 3 +- service/s3/api_op_PutBucketLogging.go | 3 +- .../s3/api_op_PutBucketOwnershipControls.go | 3 +- service/s3/api_op_PutBucketPolicy.go | 3 +- service/s3/api_op_PutBucketReplication.go | 3 +- service/s3/api_op_PutBucketRequestPayment.go | 3 +- service/s3/api_op_PutBucketTagging.go | 3 +- service/s3/api_op_PutBucketVersioning.go | 3 +- service/s3/api_op_PutBucketWebsite.go | 3 +- service/s3/api_op_PutObject.go | 3 +- service/s3/api_op_PutObjectAcl.go | 3 +- service/s3/api_op_PutObjectLegalHold.go | 3 +- .../s3/api_op_PutObjectLockConfiguration.go | 3 +- service/s3/api_op_PutObjectRetention.go | 3 +- service/s3/api_op_PutObjectTagging.go | 3 +- service/s3/api_op_PutPublicAccessBlock.go | 3 +- service/s3/api_op_RestoreObject.go | 3 +- service/s3/api_op_UploadPart.go | 3 +- .../internal/customizations/presign_test.go | 33 +- 40 files changed, 236 insertions(+), 575 deletions(-) diff --git a/.changelog/9ebe24c4791541e0840da49eab6f9d97.json b/.changelog/9ebe24c4791541e0840da49eab6f9d97.json index 20361e63e4e..962e901cae9 100644 --- a/.changelog/9ebe24c4791541e0840da49eab6f9d97.json +++ b/.changelog/9ebe24c4791541e0840da49eab6f9d97.json @@ -1,7 +1,7 @@ { "id": "9ebe24c4-7915-41e0-840d-a49eab6f9d97", "type": "feature", - "description": "add client cfg to opt-in/out checksum behavior and change its default algorithm", + "description": "This feature adds new client cfg fields so user can opt-in/out request/response checksum calculation/validation for operation modeled with checksum trait. The default MD5 checksum algorithm is replaced with CRC32.", "modules": [ ".", "config", diff --git a/aws/checksum.go b/aws/checksum.go index 5677ed668a6..dc9e9ac3c50 100644 --- a/aws/checksum.go +++ b/aws/checksum.go @@ -1,39 +1,26 @@ package aws // RequestChecksumCalculation controls request checksum calculation workflow -type RequestChecksumCalculation string +type RequestChecksumCalculation int const ( - // RequestChecksumCalculationWhenSupported indicates request checksum should be calculated if modeled - RequestChecksumCalculationWhenSupported RequestChecksumCalculation = "whenSupported" + // RequestChecksumCalculationWhenSupported indicates request checksum should be calculated if + // client operation model has request checksum trait + RequestChecksumCalculationWhenSupported RequestChecksumCalculation = 1 // RequestChecksumCalculationWhenRequired indicates request checksum should be calculated // if modeled and user set an algorithm - RequestChecksumCalculationWhenRequired = "whenRequired" + RequestChecksumCalculationWhenRequired = 2 ) // ResponseChecksumValidation controls response checksum validation workflow -type ResponseChecksumValidation string +type ResponseChecksumValidation int const ( // ResponseChecksumValidationWhenSupported indicates response checksum should be validated if modeled - ResponseChecksumValidationWhenSupported ResponseChecksumValidation = "whenSupported" + ResponseChecksumValidationWhenSupported ResponseChecksumValidation = 1 // ResponseChecksumValidationWhenRequired indicates response checksum should be validated if modeled // and user enable that in vlidation mode cfg - ResponseChecksumValidationWhenRequired = "whenRequired" -) - -// RequireChecksum indicates if a checksum needs calculated/validated for a request/response -type RequireChecksum string - -const ( - // RequireChecksumTrue indicates checksum should be calculated/validated - RequireChecksumTrue RequireChecksum = "true" - - // RequireChecksumFalse indicates checksum should not be calculated/validated - RequireChecksumFalse RequireChecksum = "false" - - // RequireChecksumPending indicates further check is needed to decide - RequireChecksumPending RequireChecksum = "pending" + ResponseChecksumValidationWhenRequired = 2 ) diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsHttpChecksumGenerator.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsHttpChecksumGenerator.java index 824eacd91c4..e47585e84ec 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsHttpChecksumGenerator.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsHttpChecksumGenerator.java @@ -263,7 +263,7 @@ private void writeInputMiddlewareHelper( writer.write(""" return $T(stack, $T{ GetAlgorithm: $L, - RequireChecksum: $T, + RequireChecksum: $L, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: $L, EnableComputeSHA256PayloadHash: true, @@ -275,7 +275,7 @@ private void writeInputMiddlewareHelper( AwsGoDependency.SERVICE_INTERNAL_CHECKSUM).build(), hasRequestAlgorithmMember ? getRequestAlgorithmAccessorFuncName(operationName) : "nil", - getInputRequireChecksum(isRequestChecksumRequired, hasRequestAlgorithmMember), + isRequestChecksumRequired, supportsRequestTrailingChecksum, supportsDecodedContentLengthHeader); } @@ -283,15 +283,6 @@ private void writeInputMiddlewareHelper( writer.insertTrailingNewline(); } - private Symbol getInputRequireChecksum(boolean isRequestChecksumRequired, boolean hasRequestAlgorithmMember) { - if (isRequestChecksumRequired) { - return SdkGoTypes.Aws.RequireChecksumTrue; - } else if (hasRequestAlgorithmMember) { - return SdkGoTypes.Aws.RequireChecksumPending; - } - return SdkGoTypes.Aws.RequireChecksumFalse; - } - private void writeOutputMiddlewareHelper( GoWriter writer, Model model, @@ -314,7 +305,6 @@ private void writeOutputMiddlewareHelper( writer.write(""" return $T(stack, $T{ GetValidationMode: $L, - RequireChecksum: $T, ResponseChecksumValidation: options.ResponseChecksumValidation, ValidationAlgorithms: $L, IgnoreMultipartValidation: $L, @@ -326,7 +316,6 @@ private void writeOutputMiddlewareHelper( SymbolUtils.createValueSymbolBuilder("OutputMiddlewareOptions", AwsGoDependency.SERVICE_INTERNAL_CHECKSUM).build(), getRequestValidationModeAccessorFuncName(operationName), - getOutputRequireChecksum(responseAlgorithms), convertToGoStringList(responseAlgorithms), ignoreMultipartChecksumValidationMap.getOrDefault( service.toShapeId(), new HashSet<>()).contains(operation.toShapeId()) @@ -334,12 +323,6 @@ private void writeOutputMiddlewareHelper( }); writer.insertTrailingNewline(); } - private Symbol getOutputRequireChecksum(List responseAlgorithms) { - if (responseAlgorithms.isEmpty()) { - return SdkGoTypes.Aws.RequireChecksumFalse; - } - return SdkGoTypes.Aws.RequireChecksumPending; - } private String convertToGoStringList(List list) { StringBuilder sb = new StringBuilder(); diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/SdkGoTypes.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/SdkGoTypes.java index 23d01efb4e0..e0158ba62af 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/SdkGoTypes.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/SdkGoTypes.java @@ -42,11 +42,6 @@ public static final class Aws { public static final Symbol RequestChecksumCalculation = AwsGoDependency.AWS_CORE.valueSymbol("RequestChecksumCalculation"); public static final Symbol ResponseChecksumValidation = AwsGoDependency.AWS_CORE.valueSymbol("ResponseChecksumValidation"); - public static final Symbol RequireChecksumTrue = AwsGoDependency.AWS_CORE.valueSymbol("RequireChecksumTrue"); - public static final Symbol RequireChecksumFalse = AwsGoDependency.AWS_CORE.valueSymbol("RequireChecksumFalse"); - public static final Symbol RequireChecksumPending = AwsGoDependency.AWS_CORE.valueSymbol("RequireChecksumPending"); - - public static final class Middleware { public static final Symbol GetRequiresLegacyEndpoints = AwsGoDependency.AWS_MIDDLEWARE.valueSymbol("GetRequiresLegacyEndpoints"); public static final Symbol GetSigningName = AwsGoDependency.AWS_MIDDLEWARE.valueSymbol("GetSigningName"); diff --git a/config/env_config.go b/config/env_config.go index c8d873008ec..27dad5fa05a 100644 --- a/config/env_config.go +++ b/config/env_config.go @@ -449,11 +449,11 @@ func (c EnvConfig) getAccountIDEndpointMode(context.Context) (aws.AccountIDEndpo } func (c EnvConfig) getRequestChecksumCalculation(context.Context) (aws.RequestChecksumCalculation, bool, error) { - return c.RequestChecksumCalculation, len(c.RequestChecksumCalculation) > 0, nil + return c.RequestChecksumCalculation, c.RequestChecksumCalculation > 0, nil } func (c EnvConfig) getResponseChecksumValidation(context.Context) (aws.ResponseChecksumValidation, bool, error) { - return c.ResponseChecksumValidation, len(c.ResponseChecksumValidation) > 0, nil + return c.ResponseChecksumValidation, c.ResponseChecksumValidation > 0, nil } // GetRetryMaxAttempts returns the value of AWS_MAX_ATTEMPTS if was specified, diff --git a/config/load_options.go b/config/load_options.go index 21c978edf31..14b6ad33f6c 100644 --- a/config/load_options.go +++ b/config/load_options.go @@ -292,11 +292,11 @@ func (o LoadOptions) getAccountIDEndpointMode(ctx context.Context) (aws.AccountI } func (o LoadOptions) getRequestChecksumCalculation(ctx context.Context) (aws.RequestChecksumCalculation, bool, error) { - return o.RequestChecksumCalculation, len(o.RequestChecksumCalculation) > 0, nil + return o.RequestChecksumCalculation, o.RequestChecksumCalculation > 0, nil } func (o LoadOptions) getResponseChecksumValidation(ctx context.Context) (aws.ResponseChecksumValidation, bool, error) { - return o.ResponseChecksumValidation, len(o.ResponseChecksumValidation) > 0, nil + return o.ResponseChecksumValidation, o.ResponseChecksumValidation > 0, nil } // WithRegion is a helper function to construct functional options @@ -359,7 +359,7 @@ func WithAccountIDEndpointMode(m aws.AccountIDEndpointMode) LoadOptionsFunc { // that sets RequestChecksumCalculation on config's LoadOptions func WithRequestChecksumCalculation(c aws.RequestChecksumCalculation) LoadOptionsFunc { return func(o *LoadOptions) error { - if c != "" { + if c > 0 { o.RequestChecksumCalculation = c } return nil @@ -370,7 +370,7 @@ func WithRequestChecksumCalculation(c aws.RequestChecksumCalculation) LoadOption // that sets ResponseChecksumValidation on config's LoadOptions func WithResponseChecksumValidation(v aws.ResponseChecksumValidation) LoadOptionsFunc { return func(o *LoadOptions) error { - if v != "" { + if v > 0 { o.ResponseChecksumValidation = v } return nil diff --git a/config/shared_config.go b/config/shared_config.go index d3842b7decf..edd8ca3770c 100644 --- a/config/shared_config.go +++ b/config/shared_config.go @@ -1278,11 +1278,11 @@ func (c SharedConfig) getAccountIDEndpointMode(ctx context.Context) (aws.Account } func (c SharedConfig) getRequestChecksumCalculation(ctx context.Context) (aws.RequestChecksumCalculation, bool, error) { - return c.RequestChecksumCalculation, len(c.RequestChecksumCalculation) > 0, nil + return c.RequestChecksumCalculation, c.RequestChecksumCalculation > 0, nil } func (c SharedConfig) getResponseChecksumValidation(ctx context.Context) (aws.ResponseChecksumValidation, bool, error) { - return c.ResponseChecksumValidation, len(c.ResponseChecksumValidation) > 0, nil + return c.ResponseChecksumValidation, c.ResponseChecksumValidation > 0, nil } func updateDefaultsMode(mode *aws.DefaultsMode, section ini.Section, key string) error { diff --git a/service/internal/checksum/middleware_add.go b/service/internal/checksum/middleware_add.go index a74d1f43bab..0c1755ab3f6 100644 --- a/service/internal/checksum/middleware_add.go +++ b/service/internal/checksum/middleware_add.go @@ -15,10 +15,8 @@ type InputMiddlewareOptions struct { // and true, or false if no algorithm is specified. GetAlgorithm func(interface{}) (string, bool) - // Whether operation model forces middleware to compute the input payload's checksum. The - // request will fail if the algorithm is not specified or unable to compute - // the checksum. - RequireChecksum aws.RequireChecksum + // Whether operation model forces middleware to compute the input payload's checksum. + RequireChecksum bool // User config to opt-in/out request checksum calculation RequestChecksumCalculation aws.RequestChecksumCalculation @@ -76,7 +74,9 @@ func AddInputMiddleware(stack *middleware.Stack, options InputMiddlewareOptions) // Initial checksum configuration look up middleware err = stack.Initialize.Add(&setupInputContext{ - GetAlgorithm: options.GetAlgorithm, + GetAlgorithm: options.GetAlgorithm, + RequireChecksum: options.RequireChecksum, + RequestChecksumCalculation: options.RequestChecksumCalculation, }, middleware.Before) if err != nil { return err @@ -85,8 +85,6 @@ func AddInputMiddleware(stack *middleware.Stack, options InputMiddlewareOptions) stack.Build.Remove("ContentChecksum") inputChecksum := &computeInputPayloadChecksum{ - RequireChecksum: options.RequireChecksum, - RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: options.EnableTrailingChecksum, EnableComputePayloadHash: options.EnableComputeSHA256PayloadHash, EnableDecodedContentLengthHeader: options.EnableDecodedContentLengthHeader, @@ -99,8 +97,6 @@ func AddInputMiddleware(stack *middleware.Stack, options InputMiddlewareOptions) if options.EnableTrailingChecksum { trailerMiddleware := &addInputChecksumTrailer{ EnableTrailingChecksum: inputChecksum.EnableTrailingChecksum, - RequireChecksum: inputChecksum.RequireChecksum, - RequestChecksumCalculation: inputChecksum.RequestChecksumCalculation, EnableComputePayloadHash: inputChecksum.EnableComputePayloadHash, EnableDecodedContentLengthHeader: inputChecksum.EnableDecodedContentLengthHeader, } @@ -128,12 +124,11 @@ type OutputMiddlewareOptions struct { // GetValidationMode is a function to get the checksum validation // mode of the output payload from the input parameters. // - // Given the input parameter value, the function must return the validation - // mode and true, or false if no mode is specified. + // Given the input parameter value, the function must return the validation mode GetValidationMode func(interface{}) (string, bool) // Whether operation model forces middleware to validate checksum - RequireChecksum aws.RequireChecksum + RequireChecksum bool // User config to opt-in/out response checksum validation ResponseChecksumValidation aws.ResponseChecksumValidation @@ -146,7 +141,7 @@ type OutputMiddlewareOptions struct { ValidationAlgorithms []string // If set the middleware will ignore output multipart checksums. Otherwise - // an checksum format error will be returned by the middleware. + // a checksum format error will be returned by the middleware. IgnoreMultipartValidation bool // When set the middleware will log when output does not have checksum or @@ -162,7 +157,8 @@ type OutputMiddlewareOptions struct { // checksum. func AddOutputMiddleware(stack *middleware.Stack, options OutputMiddlewareOptions) error { err := stack.Initialize.Add(&setupOutputContext{ - GetValidationMode: options.GetValidationMode, + GetValidationMode: options.GetValidationMode, + ResponseChecksumValidation: options.ResponseChecksumValidation, }, middleware.Before) if err != nil { return err @@ -173,8 +169,6 @@ func AddOutputMiddleware(stack *middleware.Stack, options OutputMiddlewareOption m := &validateOutputPayloadChecksum{ Algorithms: algorithms, - RequireChecksum: options.RequireChecksum, - ResponseChecksumValidation: options.ResponseChecksumValidation, IgnoreMultipartValidation: options.IgnoreMultipartValidation, LogMultipartValidationSkipped: options.LogMultipartValidationSkipped, LogValidationSkipped: options.LogValidationSkipped, diff --git a/service/internal/checksum/middleware_add_test.go b/service/internal/checksum/middleware_add_test.go index 1fa67629f49..7219c4a4172 100644 --- a/service/internal/checksum/middleware_add_test.go +++ b/service/internal/checksum/middleware_add_test.go @@ -9,7 +9,6 @@ import ( "reflect" "testing" - "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" ) @@ -64,7 +63,7 @@ func TestAddInputMiddleware(t *testing.T) { return string(AlgorithmCRC32), true }, EnableTrailingChecksum: true, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, }, expectMiddleware: []string{ "test", @@ -88,7 +87,6 @@ func TestAddInputMiddleware(t *testing.T) { }, }, expectFinalize: &computeInputPayloadChecksum{ - RequireChecksum: aws.RequireChecksumTrue, EnableTrailingChecksum: true, }, }, @@ -168,9 +166,6 @@ func TestAddInputMiddleware(t *testing.T) { var computeInput *computeInputPayloadChecksum if c.expectFinalize != nil && ok { computeInput = finalizeMW.(*computeInputPayloadChecksum) - if e, a := c.expectFinalize.RequireChecksum, computeInput.RequireChecksum; e != a { - t.Errorf("expect %v require checksum, got %v", e, a) - } if e, a := c.expectFinalize.EnableTrailingChecksum, computeInput.EnableTrailingChecksum; e != a { t.Errorf("expect %v enable trailing checksum, got %v", e, a) } diff --git a/service/internal/checksum/middleware_compute_input_checksum.go b/service/internal/checksum/middleware_compute_input_checksum.go index 181b3378fd3..b40181cbc26 100644 --- a/service/internal/checksum/middleware_compute_input_checksum.go +++ b/service/internal/checksum/middleware_compute_input_checksum.go @@ -8,7 +8,6 @@ import ( "io" "strconv" - "github.com/aws/aws-sdk-go-v2/aws" v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalcontext "github.com/aws/aws-sdk-go-v2/internal/context" presignedurlcust "github.com/aws/aws-sdk-go-v2/service/internal/presigned-url" @@ -50,14 +49,6 @@ type computeInputPayloadChecksum struct { // the Algorithm's header is already set on the request. EnableTrailingChecksum bool - // States that a checksum is required to be calculated for the operation. - // If input does not specify a checksum, fallback to built in CRC32 checksum is used. - // Replaces smithy-go's ContentChecksum middleware. - RequireChecksum aws.RequireChecksum - - // States user config to opt-in/out checksum calculation - RequestChecksumCalculation aws.RequestChecksumCalculation - // Enables support for computing the SHA256 checksum of input payloads // along with the algorithm specified checksum. Prevents downstream // middleware handlers (computePayloadSHA256) re-reading the payload. @@ -112,16 +103,12 @@ func (m *computeInputPayloadChecksum) HandleFinalize( ) ( out middleware.FinalizeOutput, metadata middleware.Metadata, err error, ) { - var algorithm Algorithm var checksum string - var set bool - algorithm, set, err = getInputAlgorithm(ctx) + algorithm, ok, err := getInputAlgorithm(ctx) if err != nil { return out, metadata, err } - - checkRequireChecksum(&m.RequireChecksum, m.RequestChecksumCalculation, set) - if m.RequireChecksum == aws.RequireChecksumFalse { + if !ok { return next.HandleFinalize(ctx, in) } @@ -154,12 +141,6 @@ func (m *computeInputPayloadChecksum) HandleFinalize( } } - // if user doesn't set algorithm, fallback to the default CRC32 checksum. - if !set { - algorithm = AlgorithmCRC32 - } - checksumHeader := AlgorithmHTTPHeader(algorithm) - computePayloadHash := m.EnableComputePayloadHash if v := v4.GetPayloadHash(ctx); v != "" { computePayloadHash = false @@ -222,6 +203,7 @@ func (m *computeInputPayloadChecksum) HandleFinalize( } } + checksumHeader := AlgorithmHTTPHeader(algorithm) req.Header.Set(checksumHeader, checksum) if computePayloadHash { @@ -253,8 +235,6 @@ func (e computeInputTrailingChecksumError) Unwrap() error { return e.Err } // - Trailing checksums are supported. type addInputChecksumTrailer struct { EnableTrailingChecksum bool - RequireChecksum aws.RequireChecksum - RequestChecksumCalculation aws.RequestChecksumCalculation EnableComputePayloadHash bool EnableDecodedContentLengthHeader bool } @@ -270,18 +250,13 @@ func (m *addInputChecksumTrailer) HandleFinalize( ) ( out middleware.FinalizeOutput, metadata middleware.Metadata, err error, ) { - var algorithm Algorithm - var set bool - algorithm, set, err = getInputAlgorithm(ctx) + algorithm, ok, err := getInputAlgorithm(ctx) if err != nil { return out, metadata, computeInputTrailingChecksumError{ Msg: "failed to get algorithm", Err: err, } - } - - checkRequireChecksum(&m.RequireChecksum, m.RequestChecksumCalculation, set) - if m.RequireChecksum == aws.RequireChecksumFalse { + } else if !ok { return next.HandleFinalize(ctx, in) } @@ -310,11 +285,6 @@ func (m *addInputChecksumTrailer) HandleFinalize( } } - // if user doesn't set algorithm, fallback to the default CRC32 checksum. - if !set { - algorithm = AlgorithmCRC32 - } - stream := req.GetStream() streamLength, err := getRequestStreamLength(req) if err != nil { @@ -390,13 +360,13 @@ func (m *addInputChecksumTrailer) HandleFinalize( return out, metadata, err } -func checkRequireChecksum(requireChecksum *aws.RequireChecksum, requestChecksumCalculation aws.RequestChecksumCalculation, set bool) { - if *requireChecksum == aws.RequireChecksumPending && - requestChecksumCalculation == aws.RequestChecksumCalculationWhenRequired && - !set { - *requireChecksum = aws.RequireChecksumFalse - } -} +//func checkRequireChecksum(requireChecksum *aws.RequireChecksum, requestChecksumCalculation aws.RequestChecksumCalculation, set bool) { +// if *requireChecksum == aws.RequireChecksumPending && +// requestChecksumCalculation == aws.RequestChecksumCalculationWhenRequired && +// !set { +// *requireChecksum = aws.RequireChecksumFalse +// } +//} func getInputAlgorithm(ctx context.Context) (Algorithm, bool, error) { ctxAlgorithm := internalcontext.GetChecksumInputAlgorithm(ctx) diff --git a/service/internal/checksum/middleware_compute_input_checksum_test.go b/service/internal/checksum/middleware_compute_input_checksum_test.go index 96adcea629f..14ba4a852c3 100644 --- a/service/internal/checksum/middleware_compute_input_checksum_test.go +++ b/service/internal/checksum/middleware_compute_input_checksum_test.go @@ -15,7 +15,6 @@ import ( "testing" "testing/iotest" - "github.com/aws/aws-sdk-go-v2/aws" v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalcontext "github.com/aws/aws-sdk-go-v2/internal/context" "github.com/aws/smithy-go/logging" @@ -94,7 +93,7 @@ func TestComputeInputPayloadChecksum(t *testing.T) { "CRC32": "AAAAAA==", }, }, - "http no algorithm require checksum header preset": { + "http no algorithm checksum header preset": { buildInput: middleware.BuildInput{ Request: func() *smithyhttp.Request { r := smithyhttp.NewStackRequest().(*smithyhttp.Request) @@ -110,15 +109,8 @@ func TestComputeInputPayloadChecksum(t *testing.T) { }, expectContentLength: 11, expectPayload: []byte("hello world"), - expectChecksumMetadata: map[string]string{ - "CRC32": "AAAAAA==", - }, }, - "http user config require checksum but no algorithm set": { - optionsFn: func(o *computeInputPayloadChecksum) { - o.RequireChecksum = aws.RequireChecksumPending - o.RequestChecksumCalculation = aws.RequestChecksumCalculationWhenRequired - }, + "http no algorithm set": { buildInput: middleware.BuildInput{ Request: func() *smithyhttp.Request { r := smithyhttp.NewStackRequest().(*smithyhttp.Request) @@ -132,48 +124,7 @@ func TestComputeInputPayloadChecksum(t *testing.T) { expectHeader: http.Header{}, expectPayload: []byte("hello world"), }, - "http not require checksum calculation": { - optionsFn: func(o *computeInputPayloadChecksum) { - o.RequireChecksum = aws.RequireChecksumFalse - }, - buildInput: middleware.BuildInput{ - Request: func() *smithyhttp.Request { - r := smithyhttp.NewStackRequest().(*smithyhttp.Request) - r.URL, _ = url.Parse("http://example.aws") - r = requestMust(r.SetStream(strings.NewReader("hello world"))) - r.ContentLength = 11 - return r - }(), - }, - expectContentLength: 11, - expectHeader: http.Header{}, - expectPayload: []byte("hello world"), - }, - "http set algorithm not require checksum calculation": { - initContext: func(ctx context.Context) context.Context { - return internalcontext.SetChecksumInputAlgorithm(ctx, string(AlgorithmCRC32C)) - }, - optionsFn: func(o *computeInputPayloadChecksum) { - o.RequireChecksum = aws.RequireChecksumFalse - }, - buildInput: middleware.BuildInput{ - Request: func() *smithyhttp.Request { - r := smithyhttp.NewStackRequest().(*smithyhttp.Request) - r.URL, _ = url.Parse("http://example.aws") - r = requestMust(r.SetStream(strings.NewReader("hello world"))) - r.ContentLength = 11 - return r - }(), - }, - expectContentLength: 11, - expectHeader: http.Header{}, - expectPayload: []byte("hello world"), - }, - "https user config require checksum but no algorithm set": { - optionsFn: func(o *computeInputPayloadChecksum) { - o.RequireChecksum = aws.RequireChecksumPending - o.RequestChecksumCalculation = aws.RequestChecksumCalculationWhenRequired - }, + "https no algorithm set": { buildInput: middleware.BuildInput{ Request: func() *smithyhttp.Request { r := smithyhttp.NewStackRequest().(*smithyhttp.Request) @@ -187,43 +138,6 @@ func TestComputeInputPayloadChecksum(t *testing.T) { expectHeader: http.Header{}, expectPayload: []byte("hello world"), }, - "https not require checksum calculation": { - optionsFn: func(o *computeInputPayloadChecksum) { - o.RequireChecksum = aws.RequireChecksumFalse - }, - buildInput: middleware.BuildInput{ - Request: func() *smithyhttp.Request { - r := smithyhttp.NewStackRequest().(*smithyhttp.Request) - r.URL, _ = url.Parse("https://example.aws") - r = requestMust(r.SetStream(strings.NewReader("hello world"))) - r.ContentLength = -1 - return r - }(), - }, - expectContentLength: -1, - expectHeader: http.Header{}, - expectPayload: []byte("hello world"), - }, - "https set algorithm not require checksum calculation": { - initContext: func(ctx context.Context) context.Context { - return internalcontext.SetChecksumInputAlgorithm(ctx, string(AlgorithmSHA1)) - }, - optionsFn: func(o *computeInputPayloadChecksum) { - o.RequireChecksum = aws.RequireChecksumFalse - }, - buildInput: middleware.BuildInput{ - Request: func() *smithyhttp.Request { - r := smithyhttp.NewStackRequest().(*smithyhttp.Request) - r.URL, _ = url.Parse("https://example.aws") - r = requestMust(r.SetStream(strings.NewReader("hello world"))) - r.ContentLength = -1 - return r - }(), - }, - expectContentLength: -1, - expectHeader: http.Header{}, - expectPayload: []byte("hello world"), - }, }, "build handled": { @@ -357,26 +271,6 @@ func TestComputeInputPayloadChecksum(t *testing.T) { "CRC32": "AAAAAA==", }, }, - "http no algorithm require checksum": { - buildInput: middleware.BuildInput{ - Request: func() *smithyhttp.Request { - r := smithyhttp.NewStackRequest().(*smithyhttp.Request) - r.URL, _ = url.Parse("http://example.aws") - r.ContentLength = 11 - r = requestMust(r.SetStream(bytes.NewReader([]byte("hello world")))) - return r - }(), - }, - expectHeader: http.Header{ - "X-Amz-Checksum-Crc32": []string{"DUoRhQ=="}, - }, - expectContentLength: 11, - expectPayload: []byte("hello world"), - expectPayloadHash: "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", - expectChecksumMetadata: map[string]string{ - "CRC32": "DUoRhQ==", - }, - }, "http seekable": { initContext: func(ctx context.Context) context.Context { return internalcontext.SetChecksumInputAlgorithm(ctx, string(AlgorithmCRC32C)) @@ -400,84 +294,6 @@ func TestComputeInputPayloadChecksum(t *testing.T) { "CRC32C": "crUfeA==", }, }, - "http no algorithm user config allow checksum": { - optionsFn: func(o *computeInputPayloadChecksum) { - o.RequireChecksum = aws.RequireChecksumPending - o.RequestChecksumCalculation = aws.RequestChecksumCalculationWhenSupported - }, - buildInput: middleware.BuildInput{ - Request: func() *smithyhttp.Request { - r := smithyhttp.NewStackRequest().(*smithyhttp.Request) - r.URL, _ = url.Parse("http://example.aws") - r.ContentLength = 11 - r = requestMust(r.SetStream(bytes.NewReader([]byte("hello world")))) - return r - }(), - }, - expectHeader: http.Header{ - "X-Amz-Checksum-Crc32": []string{"DUoRhQ=="}, - }, - expectContentLength: 11, - expectPayload: []byte("hello world"), - expectPayloadHash: "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", - expectChecksumMetadata: map[string]string{ - "CRC32": "DUoRhQ==", - }, - }, - "http user config allow checksum": { - initContext: func(ctx context.Context) context.Context { - return internalcontext.SetChecksumInputAlgorithm(ctx, string(AlgorithmCRC32C)) - }, - optionsFn: func(o *computeInputPayloadChecksum) { - o.RequireChecksum = aws.RequireChecksumPending - o.RequestChecksumCalculation = aws.RequestChecksumCalculationWhenSupported - }, - buildInput: middleware.BuildInput{ - Request: func() *smithyhttp.Request { - r := smithyhttp.NewStackRequest().(*smithyhttp.Request) - r.URL, _ = url.Parse("http://example.aws") - r.ContentLength = 11 - r = requestMust(r.SetStream(bytes.NewReader([]byte("Hello world")))) - return r - }(), - }, - expectHeader: http.Header{ - "X-Amz-Checksum-Crc32c": []string{"crUfeA=="}, - }, - expectContentLength: 11, - expectPayload: []byte("Hello world"), - expectPayloadHash: "64ec88ca00b268e5ba1a35678a1b5316d212f4f366b2477232534a8aeca37f3c", - expectChecksumMetadata: map[string]string{ - "CRC32C": "crUfeA==", - }, - }, - "http set algorithm user config require checksum": { - initContext: func(ctx context.Context) context.Context { - return internalcontext.SetChecksumInputAlgorithm(ctx, string(AlgorithmCRC32C)) - }, - optionsFn: func(o *computeInputPayloadChecksum) { - o.RequireChecksum = aws.RequireChecksumPending - o.RequestChecksumCalculation = aws.RequestChecksumCalculationWhenRequired - }, - buildInput: middleware.BuildInput{ - Request: func() *smithyhttp.Request { - r := smithyhttp.NewStackRequest().(*smithyhttp.Request) - r.URL, _ = url.Parse("http://example.aws") - r.ContentLength = 11 - r = requestMust(r.SetStream(bytes.NewReader([]byte("Hello world")))) - return r - }(), - }, - expectHeader: http.Header{ - "X-Amz-Checksum-Crc32c": []string{"crUfeA=="}, - }, - expectContentLength: 11, - expectPayload: []byte("Hello world"), - expectPayloadHash: "64ec88ca00b268e5ba1a35678a1b5316d212f4f366b2477232534a8aeca37f3c", - expectChecksumMetadata: map[string]string{ - "CRC32C": "crUfeA==", - }, - }, "http payload hash already set": { initContext: func(ctx context.Context) context.Context { ctx = internalcontext.SetChecksumInputAlgorithm(ctx, string(AlgorithmCRC32)) @@ -621,18 +437,6 @@ func TestComputeInputPayloadChecksum(t *testing.T) { expectErr: "failed to parse algorithm", expectBuildErr: true, }, - "no algorithm require checksum unseekable stream": { - buildInput: middleware.BuildInput{ - Request: func() *smithyhttp.Request { - r := smithyhttp.NewStackRequest().(*smithyhttp.Request) - r.URL, _ = url.Parse("http://example.aws") - r = requestMust(r.SetStream(bytes.NewBuffer([]byte("hello world")))) - return r - }(), - }, - expectErr: "unseekable stream is not supported", - expectBuildErr: true, - }, "http unseekable stream": { initContext: func(ctx context.Context) context.Context { return internalcontext.SetChecksumInputAlgorithm(ctx, string(AlgorithmSHA1)) @@ -808,94 +612,10 @@ func TestComputeInputPayloadChecksum(t *testing.T) { "CRC32C": "crUfeA==", }, }, - "https no algorithm user config allow checksum": { - optionsFn: func(o *computeInputPayloadChecksum) { - o.RequireChecksum = aws.RequireChecksumPending - o.RequestChecksumCalculation = aws.RequestChecksumCalculationWhenSupported - }, - buildInput: middleware.BuildInput{ - Request: func() *smithyhttp.Request { - r := smithyhttp.NewStackRequest().(*smithyhttp.Request) - r.URL, _ = url.Parse("https://example.aws") - r.ContentLength = 11 - r = requestMust(r.SetStream(bytes.NewReader([]byte("hello world")))) - return r - }(), - }, - expectHeader: http.Header{ - "Content-Encoding": []string{"aws-chunked"}, - "X-Amz-Decoded-Content-Length": []string{"11"}, - "X-Amz-Trailer": []string{"x-amz-checksum-crc32"}, - }, - expectContentLength: 52, - expectPayload: []byte("b\r\nhello world\r\n0\r\nx-amz-checksum-crc32:DUoRhQ==\r\n\r\n"), - expectPayloadHash: "STREAMING-UNSIGNED-PAYLOAD-TRAILER", - expectDeferToFinalize: true, - expectChecksumMetadata: map[string]string{ - "CRC32": "DUoRhQ==", - }, - }, - "https user config allow checksum": { - initContext: func(ctx context.Context) context.Context { - return internalcontext.SetChecksumInputAlgorithm(ctx, string(AlgorithmSHA1)) - }, - optionsFn: func(o *computeInputPayloadChecksum) { - o.RequireChecksum = aws.RequireChecksumPending - o.RequestChecksumCalculation = aws.RequestChecksumCalculationWhenSupported - }, - buildInput: middleware.BuildInput{ - Request: func() *smithyhttp.Request { - r := smithyhttp.NewStackRequest().(*smithyhttp.Request) - r.URL, _ = url.Parse("https://example.aws") - r.ContentLength = 11 - r = requestMust(r.SetStream(bytes.NewReader([]byte("Hello world")))) - return r - }(), - }, - expectHeader: http.Header{ - "Content-Encoding": []string{"aws-chunked"}, - "X-Amz-Decoded-Content-Length": []string{"11"}, - "X-Amz-Trailer": []string{"x-amz-checksum-sha1"}, - }, - expectContentLength: 71, - expectPayload: []byte("b\r\nHello world\r\n0\r\nx-amz-checksum-sha1:e1AsOh9IyGCa4hLN+2Od7jlnP14=\r\n\r\n"), - expectPayloadHash: "STREAMING-UNSIGNED-PAYLOAD-TRAILER", - expectDeferToFinalize: true, - expectChecksumMetadata: map[string]string{ - "SHA1": "e1AsOh9IyGCa4hLN+2Od7jlnP14=", - }, - }, - "https set algorithm user config require checksum": { + "https no compute payload hash": { initContext: func(ctx context.Context) context.Context { - return internalcontext.SetChecksumInputAlgorithm(ctx, string(AlgorithmSHA1)) - }, - optionsFn: func(o *computeInputPayloadChecksum) { - o.RequireChecksum = aws.RequireChecksumPending - o.RequestChecksumCalculation = aws.RequestChecksumCalculationWhenRequired - }, - buildInput: middleware.BuildInput{ - Request: func() *smithyhttp.Request { - r := smithyhttp.NewStackRequest().(*smithyhttp.Request) - r.URL, _ = url.Parse("https://example.aws") - r.ContentLength = 11 - r = requestMust(r.SetStream(bytes.NewReader([]byte("Hello world")))) - return r - }(), - }, - expectHeader: http.Header{ - "Content-Encoding": []string{"aws-chunked"}, - "X-Amz-Decoded-Content-Length": []string{"11"}, - "X-Amz-Trailer": []string{"x-amz-checksum-sha1"}, - }, - expectContentLength: 71, - expectPayload: []byte("b\r\nHello world\r\n0\r\nx-amz-checksum-sha1:e1AsOh9IyGCa4hLN+2Od7jlnP14=\r\n\r\n"), - expectPayloadHash: "STREAMING-UNSIGNED-PAYLOAD-TRAILER", - expectDeferToFinalize: true, - expectChecksumMetadata: map[string]string{ - "SHA1": "e1AsOh9IyGCa4hLN+2Od7jlnP14=", + return internalcontext.SetChecksumInputAlgorithm(ctx, string(AlgorithmCRC32)) }, - }, - "https no compute payload hash": { optionsFn: func(o *computeInputPayloadChecksum) { o.EnableComputePayloadHash = false }, @@ -924,6 +644,9 @@ func TestComputeInputPayloadChecksum(t *testing.T) { optionsFn: func(o *computeInputPayloadChecksum) { o.EnableDecodedContentLengthHeader = false }, + initContext: func(ctx context.Context) context.Context { + return internalcontext.SetChecksumInputAlgorithm(ctx, string(AlgorithmCRC32)) + }, buildInput: middleware.BuildInput{ Request: func() *smithyhttp.Request { r := smithyhttp.NewStackRequest().(*smithyhttp.Request) @@ -946,6 +669,9 @@ func TestComputeInputPayloadChecksum(t *testing.T) { }, }, "with content encoding set": { + initContext: func(ctx context.Context) context.Context { + return internalcontext.SetChecksumInputAlgorithm(ctx, string(AlgorithmCRC32)) + }, buildInput: middleware.BuildInput{ Request: func() *smithyhttp.Request { r := smithyhttp.NewStackRequest().(*smithyhttp.Request) @@ -980,7 +706,6 @@ func TestComputeInputPayloadChecksum(t *testing.T) { EnableTrailingChecksum: true, EnableComputePayloadHash: true, EnableDecodedContentLengthHeader: true, - RequireChecksum: aws.RequireChecksumTrue, } if c.optionsFn != nil { @@ -988,7 +713,6 @@ func TestComputeInputPayloadChecksum(t *testing.T) { } trailerMiddleware := &addInputChecksumTrailer{ EnableTrailingChecksum: m.EnableTrailingChecksum, - RequireChecksum: m.RequireChecksum, EnableComputePayloadHash: m.EnableComputePayloadHash, EnableDecodedContentLengthHeader: m.EnableDecodedContentLengthHeader, } diff --git a/service/internal/checksum/middleware_setup_context.go b/service/internal/checksum/middleware_setup_context.go index 3db73afe7e8..8fc97d5d8de 100644 --- a/service/internal/checksum/middleware_setup_context.go +++ b/service/internal/checksum/middleware_setup_context.go @@ -2,6 +2,7 @@ package checksum import ( "context" + "github.com/aws/aws-sdk-go-v2/aws" internalcontext "github.com/aws/aws-sdk-go-v2/internal/context" "github.com/aws/smithy-go/middleware" @@ -17,6 +18,14 @@ type setupInputContext struct { // Given the input parameter value, the function must return the algorithm // and true, or false if no algorithm is specified. GetAlgorithm func(interface{}) (string, bool) + + // States that a checksum is required to be calculated for the operation. + // If input does not specify a checksum, fallback to built in CRC32 checksum is used. + // Replaces smithy-go's ContentChecksum middleware. + RequireChecksum bool + + // States user config to opt-in/out checksum calculation + RequestChecksumCalculation aws.RequestChecksumCalculation } // ID for the middleware @@ -31,13 +40,17 @@ func (m *setupInputContext) HandleInitialize( ) ( out middleware.InitializeOutput, metadata middleware.Metadata, err error, ) { - // Check if validation algorithm is specified. + var algorithm string + var ok bool if m.GetAlgorithm != nil { - // check is input resource has a checksum algorithm - algorithm, ok := m.GetAlgorithm(in.Parameters) - if ok && len(algorithm) != 0 { - ctx = internalcontext.SetChecksumInputAlgorithm(ctx, algorithm) + algorithm, ok = m.GetAlgorithm(in.Parameters) + } + + if m.RequireChecksum || m.RequestChecksumCalculation == aws.RequestChecksumCalculationWhenSupported || ok { + if !ok { + algorithm = "CRC32" } + ctx = internalcontext.SetChecksumInputAlgorithm(ctx, algorithm) } return next.HandleInitialize(ctx, in) @@ -47,9 +60,11 @@ type setupOutputContext struct { // GetValidationMode is a function to get the checksum validation // mode of the output payload from the input parameters. // - // Given the input parameter value, the function must return the validation - // mode and true, or false if no mode is specified. + // Given the input parameter value, the function must return the validation mode GetValidationMode func(interface{}) (string, bool) + + // ResponseChecksumValidation states user config to opt-in/out checksum validation + ResponseChecksumValidation aws.ResponseChecksumValidation } // ID for the middleware @@ -64,13 +79,15 @@ func (m *setupOutputContext) HandleInitialize( ) ( out middleware.InitializeOutput, metadata middleware.Metadata, err error, ) { + var mode string // Check if validation mode is specified. if m.GetValidationMode != nil { // check is input resource has a checksum algorithm - mode, ok := m.GetValidationMode(in.Parameters) - if ok && len(mode) != 0 { - ctx = setContextOutputValidationMode(ctx, mode) - } + mode, _ = m.GetValidationMode(in.Parameters) + } + + if m.ResponseChecksumValidation == aws.ResponseChecksumValidationWhenSupported || mode == "ENABLED" { + ctx = setContextOutputValidationMode(ctx, "ENABLED") } return next.HandleInitialize(ctx, in) diff --git a/service/internal/checksum/middleware_setup_context_test.go b/service/internal/checksum/middleware_setup_context_test.go index e629ee088d7..eae9f8aee91 100644 --- a/service/internal/checksum/middleware_setup_context_test.go +++ b/service/internal/checksum/middleware_setup_context_test.go @@ -5,6 +5,7 @@ package checksum import ( "context" + "github.com/aws/aws-sdk-go-v2/aws" "testing" internalcontext "github.com/aws/aws-sdk-go-v2/internal/context" @@ -17,42 +18,93 @@ func TestSetupInput(t *testing.T) { } cases := map[string]struct { - inputParams interface{} - getAlgorithm func(interface{}) (string, bool) - expectValue string + inputParams interface{} + getAlgorithm func(interface{}) (string, bool) + RequireChecksum bool + RequestChecksumCalculation aws.RequestChecksumCalculation + expectValue string }{ - "nil accessor": { + "not require checksum and nil accessor": { expectValue: "", }, - "found empty": { + "not require checksum and algorithm unset": { inputParams: Params{Value: ""}, + getAlgorithm: func(v interface{}) (string, bool) { + return "", false + }, + expectValue: "", + }, + "user config require checksum and algorithm unset": { + RequestChecksumCalculation: aws.RequestChecksumCalculationWhenRequired, + getAlgorithm: func(v interface{}) (string, bool) { + return "", false + }, + expectValue: "", + }, + "require checksum found empty": { + RequireChecksum: true, + inputParams: Params{Value: ""}, getAlgorithm: func(v interface{}) (string, bool) { vv := v.(Params) return vv.Value, true }, expectValue: "", }, - "found not set": { - inputParams: Params{Value: ""}, + "user config require checksum found empty": { + RequestChecksumCalculation: aws.RequestChecksumCalculationWhenRequired, + inputParams: Params{Value: ""}, getAlgorithm: func(v interface{}) (string, bool) { - return "", false + vv := v.(Params) + return vv.Value, true }, expectValue: "", }, - "found": { - inputParams: Params{Value: "abc123"}, + "require checksum and found": { + RequireChecksum: true, + inputParams: Params{Value: "abc123"}, getAlgorithm: func(v interface{}) (string, bool) { vv := v.(Params) return vv.Value, true }, expectValue: "abc123", }, + "user config support checksum and found": { + RequestChecksumCalculation: aws.RequestChecksumCalculationWhenSupported, + inputParams: Params{Value: "abc123"}, + getAlgorithm: func(v interface{}) (string, bool) { + vv := v.(Params) + return vv.Value, true + }, + expectValue: "abc123", + }, + "user config require checksum and found": { + RequestChecksumCalculation: aws.RequestChecksumCalculationWhenRequired, + inputParams: Params{Value: "abc123"}, + getAlgorithm: func(v interface{}) (string, bool) { + vv := v.(Params) + return vv.Value, true + }, + expectValue: "abc123", + }, + "require checksum unset and use default": { + RequireChecksum: true, + getAlgorithm: func(v interface{}) (string, bool) { + return "", false + }, + expectValue: "CRC32", + }, + "user config support checksum unset and use default": { + RequestChecksumCalculation: aws.RequestChecksumCalculationWhenSupported, + expectValue: "CRC32", + }, } for name, c := range cases { t.Run(name, func(t *testing.T) { m := setupInputContext{ - GetAlgorithm: c.getAlgorithm, + GetAlgorithm: c.getAlgorithm, + RequireChecksum: c.RequireChecksum, + RequestChecksumCalculation: c.RequestChecksumCalculation, } _, _, err := m.HandleInitialize(context.Background(), @@ -83,9 +135,10 @@ func TestSetupOutput(t *testing.T) { } cases := map[string]struct { - inputParams interface{} - getValidationMode func(interface{}) (string, bool) - expectValue string + inputParams interface{} + ResponseChecksumValidation aws.ResponseChecksumValidation + getValidationMode func(interface{}) (string, bool) + expectValue string }{ "nil accessor": { expectValue: "", @@ -105,20 +158,33 @@ func TestSetupOutput(t *testing.T) { }, expectValue: "", }, - "found": { + "require checksum": { + ResponseChecksumValidation: aws.ResponseChecksumValidationWhenSupported, + expectValue: "ENABLED", + }, + "found invalid value": { inputParams: Params{Value: "abc123"}, getValidationMode: func(v interface{}) (string, bool) { vv := v.(Params) return vv.Value, true }, - expectValue: "abc123", + expectValue: "", + }, + "found valid value": { + inputParams: Params{Value: "ENABLED"}, + getValidationMode: func(v interface{}) (string, bool) { + vv := v.(Params) + return vv.Value, true + }, + expectValue: "ENABLED", }, } for name, c := range cases { t.Run(name, func(t *testing.T) { m := setupOutputContext{ - GetValidationMode: c.getValidationMode, + GetValidationMode: c.getValidationMode, + ResponseChecksumValidation: c.ResponseChecksumValidation, } _, _, err := m.HandleInitialize(context.Background(), diff --git a/service/internal/checksum/middleware_validate_output.go b/service/internal/checksum/middleware_validate_output.go index 567d984eaec..feb5015a1bf 100644 --- a/service/internal/checksum/middleware_validate_output.go +++ b/service/internal/checksum/middleware_validate_output.go @@ -5,7 +5,6 @@ import ( "fmt" "strings" - "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/smithy-go" "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" @@ -38,13 +37,6 @@ type validateOutputPayloadChecksum struct { // headers. Algorithms []Algorithm - // States that a checksum is required to be validated for the operation. - // If no checksum algorithm matches response header, no checksum will be validated - RequireChecksum aws.RequireChecksum - - // States user config to opt-in/out checksum validation - ResponseChecksumValidation aws.ResponseChecksumValidation - // IgnoreMultipartValidation indicates multipart checksums ending with "-#" // will be ignored. IgnoreMultipartValidation bool @@ -74,14 +66,7 @@ func (m *validateOutputPayloadChecksum) HandleDeserialize( return out, metadata, err } - mode := getContextOutputValidationMode(ctx) - if m.RequireChecksum == aws.RequireChecksumPending && - m.ResponseChecksumValidation == aws.ResponseChecksumValidationWhenRequired && - mode != "ENABLED" { - m.RequireChecksum = aws.RequireChecksumFalse - } - - if m.RequireChecksum == aws.RequireChecksumFalse { + if mode := getContextOutputValidationMode(ctx); mode != "ENABLED" { return out, metadata, err } @@ -104,8 +89,6 @@ func (m *validateOutputPayloadChecksum) HandleDeserialize( algorithmToUse = algorithm } - // TODO this must validate the validation mode is set to enabled. - logger := middleware.GetLogger(ctx) // Skip validation if no checksum algorithm or checksum is available. diff --git a/service/internal/checksum/middleware_validate_output_test.go b/service/internal/checksum/middleware_validate_output_test.go index e059ca48e95..618c233dc6f 100644 --- a/service/internal/checksum/middleware_validate_output_test.go +++ b/service/internal/checksum/middleware_validate_output_test.go @@ -7,7 +7,6 @@ import ( "bytes" "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" "io/ioutil" "net/http" "strings" @@ -32,6 +31,9 @@ func TestValidateOutputPayloadChecksum(t *testing.T) { expectPayload []byte }{ "success": { + modifyContext: func(ctx context.Context) context.Context { + return setContextOutputValidationMode(ctx, "ENABLED") + }, response: &smithyhttp.Response{ Response: &http.Response{ StatusCode: 200, @@ -47,57 +49,7 @@ func TestValidateOutputPayloadChecksum(t *testing.T) { expectAlgorithmsUsed: []string{"CRC32"}, expectPayload: []byte("hello world"), }, - "user cfg allow checksum": { - validateOptions: func(m *validateOutputPayloadChecksum) { - m.RequireChecksum = aws.RequireChecksumPending - m.ResponseChecksumValidation = aws.ResponseChecksumValidationWhenSupported - }, - response: &smithyhttp.Response{ - Response: &http.Response{ - StatusCode: 200, - Header: func() http.Header { - h := http.Header{} - h.Set(AlgorithmHTTPHeader(AlgorithmSHA256), "uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=") - return h - }(), - Body: ioutil.NopCloser(strings.NewReader("hello world")), - }, - }, - expectHaveAlgorithmsUsed: true, - expectAlgorithmsUsed: []string{"SHA256"}, - expectPayload: []byte("hello world"), - }, - "user cfg require checksum and validation mode set": { - validateOptions: func(m *validateOutputPayloadChecksum) { - m.RequireChecksum = aws.RequireChecksumPending - m.ResponseChecksumValidation = aws.ResponseChecksumValidationWhenRequired - }, - modifyContext: func(ctx context.Context) context.Context { - return setContextOutputValidationMode(ctx, "ENABLED") - }, - response: &smithyhttp.Response{ - Response: &http.Response{ - StatusCode: 200, - Header: func() http.Header { - h := http.Header{} - h.Set(AlgorithmHTTPHeader(AlgorithmCRC32C), "crUfeA==") - return h - }(), - Body: ioutil.NopCloser(strings.NewReader("Hello world")), - }, - }, - expectHaveAlgorithmsUsed: true, - expectAlgorithmsUsed: []string{"CRC32C"}, - expectPayload: []byte("Hello world"), - }, "no checksum required": { - validateOptions: func(m *validateOutputPayloadChecksum) { - m.RequireChecksum = aws.RequireChecksumFalse - m.ResponseChecksumValidation = aws.ResponseChecksumValidationWhenSupported - }, - modifyContext: func(ctx context.Context) context.Context { - return setContextOutputValidationMode(ctx, "ENABLED") - }, response: &smithyhttp.Response{ Response: &http.Response{ StatusCode: 200, @@ -112,6 +64,9 @@ func TestValidateOutputPayloadChecksum(t *testing.T) { expectPayload: []byte("Hello world"), }, "checksum mismatch failure": { + modifyContext: func(ctx context.Context) context.Context { + return setContextOutputValidationMode(ctx, "ENABLED") + }, response: &smithyhttp.Response{ Response: &http.Response{ StatusCode: 200, @@ -126,6 +81,9 @@ func TestValidateOutputPayloadChecksum(t *testing.T) { expectReadErr: "checksum did not match", }, "read error": { + modifyContext: func(ctx context.Context) context.Context { + return setContextOutputValidationMode(ctx, "ENABLED") + }, response: &smithyhttp.Response{ Response: &http.Response{ StatusCode: 200, @@ -140,6 +98,9 @@ func TestValidateOutputPayloadChecksum(t *testing.T) { expectReadErr: "some read error", }, "unsupported algorithm": { + modifyContext: func(ctx context.Context) context.Context { + return setContextOutputValidationMode(ctx, "ENABLED") + }, response: &smithyhttp.Response{ Response: &http.Response{ StatusCode: 200, @@ -154,31 +115,10 @@ func TestValidateOutputPayloadChecksum(t *testing.T) { expectLogged: "no supported checksum", expectPayload: []byte("hello world"), }, - "user cfg require checksum but no output validation mode": { - validateOptions: func(m *validateOutputPayloadChecksum) { - m.RequireChecksum = aws.RequireChecksumPending - m.ResponseChecksumValidation = aws.ResponseChecksumValidationWhenRequired - }, - response: &smithyhttp.Response{ - Response: &http.Response{ - StatusCode: 200, - Header: func() http.Header { - h := http.Header{} - return h - }(), - Body: ioutil.NopCloser(strings.NewReader("hello world")), - }, - }, - expectPayload: []byte("hello world"), - }, "unknown output validation model": { modifyContext: func(ctx context.Context) context.Context { return setContextOutputValidationMode(ctx, "something else") }, - validateOptions: func(m *validateOutputPayloadChecksum) { - m.RequireChecksum = aws.RequireChecksumPending - m.ResponseChecksumValidation = aws.ResponseChecksumValidationWhenRequired - }, response: &smithyhttp.Response{ Response: &http.Response{ StatusCode: 200, @@ -192,6 +132,9 @@ func TestValidateOutputPayloadChecksum(t *testing.T) { expectPayload: []byte("hello world"), }, "success ignore multipart checksum": { + modifyContext: func(ctx context.Context) context.Context { + return setContextOutputValidationMode(ctx, "ENABLED") + }, response: &smithyhttp.Response{ Response: &http.Response{ StatusCode: 200, @@ -211,6 +154,9 @@ func TestValidateOutputPayloadChecksum(t *testing.T) { expectPayload: []byte("hello world"), }, "success skip ignore multipart checksum": { + modifyContext: func(ctx context.Context) context.Context { + return setContextOutputValidationMode(ctx, "ENABLED") + }, response: &smithyhttp.Response{ Response: &http.Response{ StatusCode: 200, @@ -246,7 +192,6 @@ func TestValidateOutputPayloadChecksum(t *testing.T) { Algorithms: []Algorithm{ AlgorithmSHA1, AlgorithmCRC32, AlgorithmCRC32C, AlgorithmSHA256, }, - RequireChecksum: aws.RequireChecksumTrue, LogValidationSkipped: true, LogMultipartValidationSkipped: true, } diff --git a/service/s3/api_op_DeleteObjects.go b/service/s3/api_op_DeleteObjects.go index 911824e81e9..438ada291c7 100644 --- a/service/s3/api_op_DeleteObjects.go +++ b/service/s3/api_op_DeleteObjects.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -427,7 +426,7 @@ func getDeleteObjectsRequestAlgorithmMember(input interface{}) (string, bool) { func addDeleteObjectsInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getDeleteObjectsRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_GetObject.go b/service/s3/api_op_GetObject.go index 0cb852fa1f9..00c48e9ff97 100644 --- a/service/s3/api_op_GetObject.go +++ b/service/s3/api_op_GetObject.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -795,7 +794,6 @@ func getGetObjectRequestValidationModeMember(input interface{}) (string, bool) { func addGetObjectOutputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddOutputMiddleware(stack, internalChecksum.OutputMiddlewareOptions{ GetValidationMode: getGetObjectRequestValidationModeMember, - RequireChecksum: aws.RequireChecksumPending, ResponseChecksumValidation: options.ResponseChecksumValidation, ValidationAlgorithms: []string{"CRC32", "CRC32C", "SHA256", "SHA1"}, IgnoreMultipartValidation: true, diff --git a/service/s3/api_op_PutBucketAccelerateConfiguration.go b/service/s3/api_op_PutBucketAccelerateConfiguration.go index 3b64d984e6e..4e5ce8ba633 100644 --- a/service/s3/api_op_PutBucketAccelerateConfiguration.go +++ b/service/s3/api_op_PutBucketAccelerateConfiguration.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -265,7 +264,7 @@ func getPutBucketAccelerateConfigurationRequestAlgorithmMember(input interface{} func addPutBucketAccelerateConfigurationInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getPutBucketAccelerateConfigurationRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumPending, + RequireChecksum: false, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_PutBucketAcl.go b/service/s3/api_op_PutBucketAcl.go index ddfa2041266..ec57b045421 100644 --- a/service/s3/api_op_PutBucketAcl.go +++ b/service/s3/api_op_PutBucketAcl.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -412,7 +411,7 @@ func getPutBucketAclRequestAlgorithmMember(input interface{}) (string, bool) { func addPutBucketAclInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getPutBucketAclRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_PutBucketCors.go b/service/s3/api_op_PutBucketCors.go index c330946b319..88ba2ed1755 100644 --- a/service/s3/api_op_PutBucketCors.go +++ b/service/s3/api_op_PutBucketCors.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -290,7 +289,7 @@ func getPutBucketCorsRequestAlgorithmMember(input interface{}) (string, bool) { func addPutBucketCorsInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getPutBucketCorsRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_PutBucketEncryption.go b/service/s3/api_op_PutBucketEncryption.go index 4afebab2ba0..c1220f74986 100644 --- a/service/s3/api_op_PutBucketEncryption.go +++ b/service/s3/api_op_PutBucketEncryption.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -365,7 +364,7 @@ func getPutBucketEncryptionRequestAlgorithmMember(input interface{}) (string, bo func addPutBucketEncryptionInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getPutBucketEncryptionRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_PutBucketLifecycleConfiguration.go b/service/s3/api_op_PutBucketLifecycleConfiguration.go index 62f878d16f3..7b9a717bd11 100644 --- a/service/s3/api_op_PutBucketLifecycleConfiguration.go +++ b/service/s3/api_op_PutBucketLifecycleConfiguration.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -298,7 +297,7 @@ func getPutBucketLifecycleConfigurationRequestAlgorithmMember(input interface{}) func addPutBucketLifecycleConfigurationInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getPutBucketLifecycleConfigurationRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_PutBucketLogging.go b/service/s3/api_op_PutBucketLogging.go index 8be5a791239..71a3c8d4c87 100644 --- a/service/s3/api_op_PutBucketLogging.go +++ b/service/s3/api_op_PutBucketLogging.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -297,7 +296,7 @@ func getPutBucketLoggingRequestAlgorithmMember(input interface{}) (string, bool) func addPutBucketLoggingInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getPutBucketLoggingRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_PutBucketOwnershipControls.go b/service/s3/api_op_PutBucketOwnershipControls.go index d04ff048ca1..1e1e997de8e 100644 --- a/service/s3/api_op_PutBucketOwnershipControls.go +++ b/service/s3/api_op_PutBucketOwnershipControls.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -229,7 +228,7 @@ func newServiceMetadataMiddleware_opPutBucketOwnershipControls(region string) *a func addPutBucketOwnershipControlsInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: nil, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_PutBucketPolicy.go b/service/s3/api_op_PutBucketPolicy.go index 7678ff333cc..bfe3d202c30 100644 --- a/service/s3/api_op_PutBucketPolicy.go +++ b/service/s3/api_op_PutBucketPolicy.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -337,7 +336,7 @@ func getPutBucketPolicyRequestAlgorithmMember(input interface{}) (string, bool) func addPutBucketPolicyInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getPutBucketPolicyRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_PutBucketReplication.go b/service/s3/api_op_PutBucketReplication.go index f55ef9699d2..ed997618143 100644 --- a/service/s3/api_op_PutBucketReplication.go +++ b/service/s3/api_op_PutBucketReplication.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -308,7 +307,7 @@ func getPutBucketReplicationRequestAlgorithmMember(input interface{}) (string, b func addPutBucketReplicationInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getPutBucketReplicationRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_PutBucketRequestPayment.go b/service/s3/api_op_PutBucketRequestPayment.go index fc68f5c4207..f53a284d733 100644 --- a/service/s3/api_op_PutBucketRequestPayment.go +++ b/service/s3/api_op_PutBucketRequestPayment.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -255,7 +254,7 @@ func getPutBucketRequestPaymentRequestAlgorithmMember(input interface{}) (string func addPutBucketRequestPaymentInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getPutBucketRequestPaymentRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_PutBucketTagging.go b/service/s3/api_op_PutBucketTagging.go index 12425431ac5..08b34887784 100644 --- a/service/s3/api_op_PutBucketTagging.go +++ b/service/s3/api_op_PutBucketTagging.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -287,7 +286,7 @@ func getPutBucketTaggingRequestAlgorithmMember(input interface{}) (string, bool) func addPutBucketTaggingInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getPutBucketTaggingRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_PutBucketVersioning.go b/service/s3/api_op_PutBucketVersioning.go index c7efd88e62b..d3e17fdae4e 100644 --- a/service/s3/api_op_PutBucketVersioning.go +++ b/service/s3/api_op_PutBucketVersioning.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -289,7 +288,7 @@ func getPutBucketVersioningRequestAlgorithmMember(input interface{}) (string, bo func addPutBucketVersioningInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getPutBucketVersioningRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_PutBucketWebsite.go b/service/s3/api_op_PutBucketWebsite.go index 991282be181..665e05dc314 100644 --- a/service/s3/api_op_PutBucketWebsite.go +++ b/service/s3/api_op_PutBucketWebsite.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -310,7 +309,7 @@ func getPutBucketWebsiteRequestAlgorithmMember(input interface{}) (string, bool) func addPutBucketWebsiteInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getPutBucketWebsiteRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_PutObject.go b/service/s3/api_op_PutObject.go index 861b0ddeae2..d063ee93da7 100644 --- a/service/s3/api_op_PutObject.go +++ b/service/s3/api_op_PutObject.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" @@ -876,7 +875,7 @@ func getPutObjectRequestAlgorithmMember(input interface{}) (string, bool) { func addPutObjectInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getPutObjectRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumPending, + RequireChecksum: false, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: true, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_PutObjectAcl.go b/service/s3/api_op_PutObjectAcl.go index c93fda5c2c2..f0d9678a2cd 100644 --- a/service/s3/api_op_PutObjectAcl.go +++ b/service/s3/api_op_PutObjectAcl.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -464,7 +463,7 @@ func getPutObjectAclRequestAlgorithmMember(input interface{}) (string, bool) { func addPutObjectAclInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getPutObjectAclRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_PutObjectLegalHold.go b/service/s3/api_op_PutObjectLegalHold.go index 78a5451544a..14830434d00 100644 --- a/service/s3/api_op_PutObjectLegalHold.go +++ b/service/s3/api_op_PutObjectLegalHold.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -279,7 +278,7 @@ func getPutObjectLegalHoldRequestAlgorithmMember(input interface{}) (string, boo func addPutObjectLegalHoldInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getPutObjectLegalHoldRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_PutObjectLockConfiguration.go b/service/s3/api_op_PutObjectLockConfiguration.go index 2436507b4a0..b866576ad87 100644 --- a/service/s3/api_op_PutObjectLockConfiguration.go +++ b/service/s3/api_op_PutObjectLockConfiguration.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -270,7 +269,7 @@ func getPutObjectLockConfigurationRequestAlgorithmMember(input interface{}) (str func addPutObjectLockConfigurationInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getPutObjectLockConfigurationRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_PutObjectRetention.go b/service/s3/api_op_PutObjectRetention.go index d202552a4a5..248b9cd1f30 100644 --- a/service/s3/api_op_PutObjectRetention.go +++ b/service/s3/api_op_PutObjectRetention.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -286,7 +285,7 @@ func getPutObjectRetentionRequestAlgorithmMember(input interface{}) (string, boo func addPutObjectRetentionInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getPutObjectRetentionRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_PutObjectTagging.go b/service/s3/api_op_PutObjectTagging.go index 2cc344f6e0e..34fec9f1dca 100644 --- a/service/s3/api_op_PutObjectTagging.go +++ b/service/s3/api_op_PutObjectTagging.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -322,7 +321,7 @@ func getPutObjectTaggingRequestAlgorithmMember(input interface{}) (string, bool) func addPutObjectTaggingInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getPutObjectTaggingRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_PutPublicAccessBlock.go b/service/s3/api_op_PutPublicAccessBlock.go index 4fc4b0e8580..1f26e90b654 100644 --- a/service/s3/api_op_PutPublicAccessBlock.go +++ b/service/s3/api_op_PutPublicAccessBlock.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -273,7 +272,7 @@ func getPutPublicAccessBlockRequestAlgorithmMember(input interface{}) (string, b func addPutPublicAccessBlockInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getPutPublicAccessBlockRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumTrue, + RequireChecksum: true, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_RestoreObject.go b/service/s3/api_op_RestoreObject.go index 00e87c6de3b..d206f6fa935 100644 --- a/service/s3/api_op_RestoreObject.go +++ b/service/s3/api_op_RestoreObject.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum" @@ -426,7 +425,7 @@ func getRestoreObjectRequestAlgorithmMember(input interface{}) (string, bool) { func addRestoreObjectInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getRestoreObjectRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumPending, + RequireChecksum: false, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: false, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/api_op_UploadPart.go b/service/s3/api_op_UploadPart.go index 48439e2d3ca..f990e529daf 100644 --- a/service/s3/api_op_UploadPart.go +++ b/service/s3/api_op_UploadPart.go @@ -5,7 +5,6 @@ package s3 import ( "context" "fmt" - "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" @@ -595,7 +594,7 @@ func getUploadPartRequestAlgorithmMember(input interface{}) (string, bool) { func addUploadPartInputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddInputMiddleware(stack, internalChecksum.InputMiddlewareOptions{ GetAlgorithm: getUploadPartRequestAlgorithmMember, - RequireChecksum: aws.RequireChecksumPending, + RequireChecksum: false, RequestChecksumCalculation: options.RequestChecksumCalculation, EnableTrailingChecksum: true, EnableComputeSHA256PayloadHash: true, diff --git a/service/s3/internal/customizations/presign_test.go b/service/s3/internal/customizations/presign_test.go index f5be986957b..80bf5ccfaff 100644 --- a/service/s3/internal/customizations/presign_test.go +++ b/service/s3/internal/customizations/presign_test.go @@ -74,7 +74,20 @@ func TestPutObject_PresignURL(t *testing.T) { Key: aws.String("mockkey"), Body: bytes.NewBuffer([]byte(`hello-world`)), }, - expectError: "unseekable stream is not supported without TLS and trailing checksum", + expectPresignedURLHost: "https://mock-bucket.s3.us-west-2.amazonaws.com/mockkey?", + expectRequestURIQuery: []string{ + "X-Amz-Expires=900", + "X-Amz-Credential", + "X-Amz-Date", + "x-id=PutObject", + "X-Amz-Signature", + }, + expectMethod: "PUT", + expectSignedHeader: http.Header{ + "Content-Length": []string{"11"}, + "Content-Type": []string{"application/octet-stream"}, + "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, + }, }, "empty body": { input: s3.PutObjectInput{ @@ -341,8 +354,22 @@ func TestUploadPart_PresignURL(t *testing.T) { UploadId: aws.String("123456"), Body: bytes.NewBuffer([]byte(`hello-world`)), }, - expectError: "unseekable stream is not supported without TLS and trailing checksum", - }, + expectPresignedURLHost: "https://mock-bucket.s3.us-west-2.amazonaws.com/mockkey?", + expectRequestURIQuery: []string{ + "X-Amz-Expires=900", + "X-Amz-Credential", + "X-Amz-Date", + "partNumber=1", + "uploadId=123456", + "x-id=UploadPart", + "X-Amz-Signature", + }, + expectMethod: "PUT", + expectSignedHeader: http.Header{ + "Content-Length": []string{"11"}, + "Content-Type": []string{"application/octet-stream"}, + "Host": []string{"mock-bucket.s3.us-west-2.amazonaws.com"}, + }}, "empty body": { input: s3.UploadPartInput{ Bucket: aws.String("mock-bucket"),