diff --git a/.changelog/df93fff8f662441fa12dac87614a5064.json b/.changelog/df93fff8f662441fa12dac87614a5064.json new file mode 100644 index 00000000000..c71e8b12562 --- /dev/null +++ b/.changelog/df93fff8f662441fa12dac87614a5064.json @@ -0,0 +1,9 @@ +{ + "id": "df93fff8-f662-441f-a12d-ac87614a5064", + "type": "bugfix", + "description": "Enable request checksum validation mode by default", + "modules": [ + "service/internal/checksum", + "service/s3" + ] +} \ No newline at end of file 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 fae961e343f..43e5001042a 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 @@ -26,6 +26,7 @@ import software.amazon.smithy.model.Model; import software.amazon.smithy.model.knowledge.TopDownIndex; import software.amazon.smithy.model.shapes.MemberShape; +import software.amazon.smithy.model.shapes.ShapeType; import software.amazon.smithy.model.shapes.OperationShape; import software.amazon.smithy.model.shapes.ServiceShape; import software.amazon.smithy.aws.traits.HttpChecksumTrait; @@ -54,6 +55,10 @@ private static String getRequestValidationModeAccessorFuncName(String operationN return String.format("get%s%s", operationName, "RequestValidationModeMember"); } + private static String setRequestValidationModeAccessorFuncName(String operationName) { + return String.format("set%s%s", operationName, "RequestValidationModeMember"); + } + private static String getAddInputMiddlewareFuncName(String operationName) { return String.format("add%sInputChecksumMiddlewares", operationName); } @@ -158,7 +163,7 @@ public void writeAdditionalFiles( goDelegator.useShapeWriter(operation, writer -> { // generate getter helper function to access input member value - writeGetInputMemberAccessorHelper(writer, model, symbolProvider, operation); + writeInputMemberAccessorHelper(writer, model, symbolProvider, operation); // generate middleware helper function if (generateComputeInputChecksums) { @@ -212,7 +217,7 @@ public static boolean hasInputChecksumTrait(Model model, ServiceShape service) { return false; } - private static boolean hasOutputChecksumTrait(Model model, ServiceShape service, OperationShape operation) { + private static boolean hasOutputChecksumTrait(Model model, ServiceShape service, OperationShape operation) { if (!hasChecksumTrait(model, service, operation)) { return false; } @@ -356,6 +361,7 @@ private void writeOutputMiddlewareHelper( writer.write(""" return $T(stack, $T{ GetValidationMode: $L, + SetValidationMode: $L, ResponseChecksumValidation: options.ResponseChecksumValidation, ValidationAlgorithms: $L, IgnoreMultipartValidation: $L, @@ -367,6 +373,7 @@ private void writeOutputMiddlewareHelper( SymbolUtils.createValueSymbolBuilder("OutputMiddlewareOptions", AwsGoDependency.SERVICE_INTERNAL_CHECKSUM).build(), getRequestValidationModeAccessorFuncName(operationName), + setRequestValidationModeAccessorFuncName(operationName), convertToGoStringList(responseAlgorithms), ignoreMultipartChecksumValidationMap.getOrDefault( service.toShapeId(), new HashSet<>()).contains(operation.toShapeId()) @@ -389,7 +396,7 @@ private String convertToGoStringList(List list) { return sb.toString(); } - private void writeGetInputMemberAccessorHelper( + private void writeInputMemberAccessorHelper( GoWriter writer, Model model, SymbolProvider symbolProvider, @@ -438,6 +445,9 @@ private void writeGetInputMemberAccessorHelper( String.format("%s gets the request checksum validation mode provided as input.", funcName)); getInputTemplate(writer, symbolProvider, input, funcName, memberName); writer.insertTrailingNewline(); + funcName = setRequestValidationModeAccessorFuncName(operationSymbol.getName()); + setInputTemplate(writer, symbolProvider, input, funcName, memberName); + writer.insertTrailingNewline(); } } @@ -459,6 +469,26 @@ private void getInputTemplate( writer.write(""); } + private void setInputTemplate( + GoWriter writer, + SymbolProvider symbolProvider, + StructureShape input, + String funcName, + String memberName + ) { + writer.write(GoWriter.goTemplate(""" + func $fn:L(input interface{}, mode string) { + in := input.(*$inputType:L) + in.$member:L = types.$member:L(mode) + }""", + Map.of( + "fn", funcName, + "inputType", symbolProvider.toSymbol(input).getName(), + "member", memberName + ))); + writer.write(""); + } + private void generateInputComputedChecksumMetadataHelpers( GoWriter writer, Model model, diff --git a/service/internal/checksum/middleware_add.go b/service/internal/checksum/middleware_add.go index fbb094ab635..274d649fb53 100644 --- a/service/internal/checksum/middleware_add.go +++ b/service/internal/checksum/middleware_add.go @@ -113,6 +113,9 @@ type OutputMiddlewareOptions struct { // mode and true, or false if no mode is specified. GetValidationMode func(interface{}) (string, bool) + // SetValidationMode is a function to set the checksum validation mode of input parameters + SetValidationMode func(interface{}, string) + // ResponseChecksumValidation is the user config to opt-in/out response checksum validation ResponseChecksumValidation aws.ResponseChecksumValidation @@ -141,6 +144,7 @@ type OutputMiddlewareOptions struct { func AddOutputMiddleware(stack *middleware.Stack, options OutputMiddlewareOptions) error { err := stack.Initialize.Add(&setupOutputContext{ GetValidationMode: options.GetValidationMode, + SetValidationMode: options.SetValidationMode, ResponseChecksumValidation: options.ResponseChecksumValidation, }, middleware.Before) if err != nil { diff --git a/service/internal/checksum/middleware_setup_context.go b/service/internal/checksum/middleware_setup_context.go index 01494abe2cc..3347e88cceb 100644 --- a/service/internal/checksum/middleware_setup_context.go +++ b/service/internal/checksum/middleware_setup_context.go @@ -70,6 +70,9 @@ type setupOutputContext struct { // mode and true, or false if no mode is specified. GetValidationMode func(interface{}) (string, bool) + // SetValidationMode is a function to set the checksum validation mode of input parameters + SetValidationMode func(interface{}, string) + // ResponseChecksumValidation states user config to opt-in/out checksum validation ResponseChecksumValidation aws.ResponseChecksumValidation } @@ -90,6 +93,7 @@ func (m *setupOutputContext) HandleInitialize( mode, _ := m.GetValidationMode(in.Parameters) if m.ResponseChecksumValidation == aws.ResponseChecksumValidationWhenSupported || mode == checksumValidationModeEnabled { + m.SetValidationMode(in.Parameters, checksumValidationModeEnabled) ctx = setContextOutputValidationMode(ctx, checksumValidationModeEnabled) } diff --git a/service/internal/checksum/middleware_setup_context_test.go b/service/internal/checksum/middleware_setup_context_test.go index a3660c63504..38ed8f7ae7c 100644 --- a/service/internal/checksum/middleware_setup_context_test.go +++ b/service/internal/checksum/middleware_setup_context_test.go @@ -131,43 +131,66 @@ func TestSetupOutput(t *testing.T) { inputParams interface{} ResponseChecksumValidation aws.ResponseChecksumValidation getValidationMode func(interface{}) (string, bool) - expectValue string + setValidationMode func(interface{}, string) + expectCtxValue string + expectInputValue string }{ "user config support checksum found empty": { ResponseChecksumValidation: aws.ResponseChecksumValidationWhenSupported, - inputParams: Params{Value: ""}, + inputParams: &Params{Value: ""}, getValidationMode: func(v interface{}) (string, bool) { - vv := v.(Params) + vv := v.(*Params) return vv.Value, true }, - expectValue: "ENABLED", + setValidationMode: func(v interface{}, m string) { + vv := v.(*Params) + vv.Value = m + }, + expectCtxValue: "ENABLED", + expectInputValue: "ENABLED", }, "user config support checksum found invalid value": { ResponseChecksumValidation: aws.ResponseChecksumValidationWhenSupported, - inputParams: Params{Value: "abc123"}, + inputParams: &Params{Value: "abc123"}, getValidationMode: func(v interface{}) (string, bool) { - vv := v.(Params) + vv := v.(*Params) return vv.Value, true + }, - expectValue: "ENABLED", + setValidationMode: func(v interface{}, m string) { + vv := v.(*Params) + vv.Value = m + }, + expectCtxValue: "ENABLED", + expectInputValue: "ENABLED", }, "user config require checksum found invalid value": { ResponseChecksumValidation: aws.ResponseChecksumValidationWhenRequired, - inputParams: Params{Value: "abc123"}, + inputParams: &Params{Value: "abc123"}, getValidationMode: func(v interface{}) (string, bool) { - vv := v.(Params) + vv := v.(*Params) return vv.Value, true }, - expectValue: "", + setValidationMode: func(v interface{}, m string) { + vv := v.(*Params) + vv.Value = m + }, + expectCtxValue: "", + expectInputValue: "abc123", }, "user config require checksum found valid value": { ResponseChecksumValidation: aws.ResponseChecksumValidationWhenRequired, - inputParams: Params{Value: "ENABLED"}, + inputParams: &Params{Value: "ENABLED"}, getValidationMode: func(v interface{}) (string, bool) { - vv := v.(Params) + vv := v.(*Params) return vv.Value, true }, - expectValue: "ENABLED", + setValidationMode: func(v interface{}, m string) { + vv := v.(*Params) + vv.Value = m + }, + expectCtxValue: "ENABLED", + expectInputValue: "ENABLED", }, } @@ -175,6 +198,7 @@ func TestSetupOutput(t *testing.T) { t.Run(name, func(t *testing.T) { m := setupOutputContext{ GetValidationMode: c.getValidationMode, + SetValidationMode: c.setValidationMode, ResponseChecksumValidation: c.ResponseChecksumValidation, } @@ -185,10 +209,14 @@ func TestSetupOutput(t *testing.T) { out middleware.InitializeOutput, metadata middleware.Metadata, err error, ) { v := getContextOutputValidationMode(ctx) - if e, a := c.expectValue, v; e != a { - t.Errorf("expect value %v, got %v", e, a) + if e, a := c.expectCtxValue, v; e != a { + t.Errorf("expect ctx checksum validation mode to be %v, got %v", e, a) } - + in := input.Parameters.(*Params) + if e, a := c.expectInputValue, in.Value; e != a { + t.Errorf("expect input checksum validation mode to be %v, got %v", e, a) + } + return out, metadata, nil }, )) diff --git a/service/internal/integrationtest/s3/checksum_test.go b/service/internal/integrationtest/s3/checksum_test.go index 9d7551870a1..16975b06ea9 100644 --- a/service/internal/integrationtest/s3/checksum_test.go +++ b/service/internal/integrationtest/s3/checksum_test.go @@ -46,12 +46,12 @@ func (c *retryClient) Do(req *http.Request) (*http.Response, error) { func TestInteg_ObjectChecksums(t *testing.T) { cases := map[string]map[string]struct { - disableHTTPS bool - retry bool - params *s3.PutObjectInput - expectErr string + disableHTTPS bool + retry bool + requestChecksumCalculation aws.RequestChecksumCalculation + params *s3.PutObjectInput - getObjectChecksumMode s3types.ChecksumMode + expectErr string expectReadErr string expectLogged string expectChecksumAlgorithms s3types.ChecksumAlgorithm @@ -60,12 +60,11 @@ func TestInteg_ObjectChecksums(t *testing.T) { expectAlgorithmsUsed *s3.ChecksumValidationMetadata }{ "seekable": { - "no checksum": { + "no checksum algorithm passed": { params: &s3.PutObjectInput{ Body: strings.NewReader("abc123"), }, - getObjectChecksumMode: s3types.ChecksumModeEnabled, - expectPayload: []byte("abc123"), + expectPayload: []byte("abc123"), expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ ComputedChecksums: map[string]string{ "CRC32": "zwK7XA==", @@ -75,14 +74,21 @@ func TestInteg_ObjectChecksums(t *testing.T) { AlgorithmsUsed: []string{"CRC32"}, }, }, + "no checksum calculation": { + params: &s3.PutObjectInput{ + Body: strings.NewReader("abc123"), + }, + requestChecksumCalculation: aws.RequestChecksumCalculationWhenRequired, + expectPayload: []byte("abc123"), + expectLogged: "Response has no supported checksum", + }, "preset checksum": { params: &s3.PutObjectInput{ Body: strings.NewReader("hello world"), ChecksumAlgorithm: s3types.ChecksumAlgorithmCrc32c, ChecksumCRC32C: aws.String("yZRlqg=="), }, - getObjectChecksumMode: s3types.ChecksumModeEnabled, - expectPayload: []byte("hello world"), + expectPayload: []byte("hello world"), expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ ComputedChecksums: map[string]string{ "CRC32C": "yZRlqg==", @@ -92,14 +98,26 @@ func TestInteg_ObjectChecksums(t *testing.T) { AlgorithmsUsed: []string{"CRC32C"}, }, }, + "preset crc64 checksum": { + params: &s3.PutObjectInput{ + Body: strings.NewReader("Hello, precomputed checksum!"), + ChecksumCRC64NVME: aws.String("uxBNEklueLQ="), + }, + expectPayload: []byte("Hello, precomputed checksum!"), + expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ + ComputedChecksums: map[string]string{ + "CRC64NVME": "uxBNEklueLQ=", + }, + }, + expectLogged: "Response has no supported checksum", + }, "wrong preset checksum": { params: &s3.PutObjectInput{ Body: strings.NewReader("hello world"), ChecksumAlgorithm: s3types.ChecksumAlgorithmCrc32c, ChecksumCRC32C: aws.String("RZRlqg=="), }, - getObjectChecksumMode: s3types.ChecksumModeEnabled, - expectErr: "BadDigest", + expectErr: "BadDigest", }, "without TLS autofill header checksum": { disableHTTPS: true, @@ -107,8 +125,7 @@ func TestInteg_ObjectChecksums(t *testing.T) { Body: strings.NewReader("hello world"), ChecksumAlgorithm: s3types.ChecksumAlgorithmCrc32c, }, - getObjectChecksumMode: s3types.ChecksumModeEnabled, - expectPayload: []byte("hello world"), + expectPayload: []byte("hello world"), expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ ComputedChecksums: map[string]string{ "CRC32C": "yZRlqg==", @@ -124,8 +141,7 @@ func TestInteg_ObjectChecksums(t *testing.T) { Body: strings.NewReader("hello world"), ChecksumAlgorithm: s3types.ChecksumAlgorithmCrc32c, }, - getObjectChecksumMode: s3types.ChecksumModeEnabled, - expectPayload: []byte("hello world"), + expectPayload: []byte("hello world"), expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ ComputedChecksums: map[string]string{ "CRC32C": "yZRlqg==", @@ -141,8 +157,7 @@ func TestInteg_ObjectChecksums(t *testing.T) { ContentLength: aws.Int64(11), ChecksumAlgorithm: s3types.ChecksumAlgorithmCrc32c, }, - getObjectChecksumMode: s3types.ChecksumModeEnabled, - expectPayload: []byte("hello world"), + expectPayload: []byte("hello world"), expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ ComputedChecksums: map[string]string{ "CRC32C": "yZRlqg==", @@ -158,8 +173,7 @@ func TestInteg_ObjectChecksums(t *testing.T) { ChecksumAlgorithm: s3types.ChecksumAlgorithmCrc32c, ContentEncoding: aws.String("gzip"), }, - getObjectChecksumMode: s3types.ChecksumModeEnabled, - expectPayload: []byte("hello world"), + expectPayload: []byte("hello world"), expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ ComputedChecksums: map[string]string{ "CRC32C": "yZRlqg==", @@ -171,12 +185,11 @@ func TestInteg_ObjectChecksums(t *testing.T) { }, }, "unseekable": { - "no checksum": { + "no checksum algorithm passed": { params: &s3.PutObjectInput{ Body: bytes.NewBuffer([]byte("abc123")), }, - getObjectChecksumMode: s3types.ChecksumModeEnabled, - expectPayload: []byte("abc123"), + expectPayload: []byte("abc123"), expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ ComputedChecksums: map[string]string{ "CRC32": "zwK7XA==", @@ -186,14 +199,21 @@ func TestInteg_ObjectChecksums(t *testing.T) { AlgorithmsUsed: []string{"CRC32"}, }, }, + "no checksum calculation": { + params: &s3.PutObjectInput{ + Body: bytes.NewBuffer([]byte("abc123")), + }, + requestChecksumCalculation: aws.RequestChecksumCalculationWhenRequired, + expectPayload: []byte("abc123"), + expectLogged: "Response has no supported checksum", + }, "preset checksum": { params: &s3.PutObjectInput{ Body: bytes.NewBuffer([]byte("hello world")), ChecksumAlgorithm: s3types.ChecksumAlgorithmCrc32c, ChecksumCRC32C: aws.String("yZRlqg=="), }, - getObjectChecksumMode: s3types.ChecksumModeEnabled, - expectPayload: []byte("hello world"), + expectPayload: []byte("hello world"), expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ ComputedChecksums: map[string]string{ "CRC32C": "yZRlqg==", @@ -203,22 +223,33 @@ func TestInteg_ObjectChecksums(t *testing.T) { AlgorithmsUsed: []string{"CRC32C"}, }, }, + "preset crc64 checksum": { + params: &s3.PutObjectInput{ + Body: bytes.NewBuffer([]byte("Hello, precomputed checksum!")), + ChecksumCRC64NVME: aws.String("uxBNEklueLQ="), + }, + expectPayload: []byte("Hello, precomputed checksum!"), + expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ + ComputedChecksums: map[string]string{ + "CRC64NVME": "uxBNEklueLQ=", + }, + }, + expectLogged: "Response has no supported checksum", + }, "wrong preset checksum": { params: &s3.PutObjectInput{ Body: bytes.NewBuffer([]byte("hello world")), ChecksumAlgorithm: s3types.ChecksumAlgorithmCrc32c, ChecksumCRC32C: aws.String("RZRlqg=="), }, - getObjectChecksumMode: s3types.ChecksumModeEnabled, - expectErr: "BadDigest", + expectErr: "BadDigest", }, "autofill trailing checksum": { params: &s3.PutObjectInput{ Body: bytes.NewBuffer([]byte("hello world")), ChecksumAlgorithm: s3types.ChecksumAlgorithmCrc32c, }, - getObjectChecksumMode: s3types.ChecksumModeEnabled, - expectPayload: []byte("hello world"), + expectPayload: []byte("hello world"), expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ ComputedChecksums: map[string]string{ "CRC32C": "yZRlqg==", @@ -242,8 +273,7 @@ func TestInteg_ObjectChecksums(t *testing.T) { ContentLength: aws.Int64(11), ChecksumAlgorithm: s3types.ChecksumAlgorithmCrc32c, }, - getObjectChecksumMode: s3types.ChecksumModeEnabled, - expectPayload: []byte("hello world"), + expectPayload: []byte("hello world"), expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ ComputedChecksums: map[string]string{ "CRC32C": "yZRlqg==", @@ -262,9 +292,8 @@ func TestInteg_ObjectChecksums(t *testing.T) { }, }, "nil body": { - "no checksum": { - params: &s3.PutObjectInput{}, - getObjectChecksumMode: s3types.ChecksumModeEnabled, + "no checksum algorithm passed": { + params: &s3.PutObjectInput{}, expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ ComputedChecksums: map[string]string{ "CRC32": "AAAAAA==", @@ -274,12 +303,16 @@ func TestInteg_ObjectChecksums(t *testing.T) { AlgorithmsUsed: []string{"CRC32"}, }, }, + "no checksum calculation": { + params: &s3.PutObjectInput{}, + requestChecksumCalculation: aws.RequestChecksumCalculationWhenRequired, + expectLogged: "Response has no supported checksum", + }, "preset checksum": { params: &s3.PutObjectInput{ ChecksumAlgorithm: s3types.ChecksumAlgorithmCrc32c, ChecksumCRC32C: aws.String("AAAAAA=="), }, - getObjectChecksumMode: s3types.ChecksumModeEnabled, expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ ComputedChecksums: map[string]string{ "CRC32C": "AAAAAA==", @@ -293,7 +326,6 @@ func TestInteg_ObjectChecksums(t *testing.T) { params: &s3.PutObjectInput{ ChecksumAlgorithm: s3types.ChecksumAlgorithmCrc32c, }, - getObjectChecksumMode: s3types.ChecksumModeEnabled, expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ ComputedChecksums: map[string]string{ "CRC32C": "AAAAAA==", @@ -308,7 +340,6 @@ func TestInteg_ObjectChecksums(t *testing.T) { params: &s3.PutObjectInput{ ChecksumAlgorithm: s3types.ChecksumAlgorithmCrc32c, }, - getObjectChecksumMode: s3types.ChecksumModeEnabled, expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ ComputedChecksums: map[string]string{ "CRC32C": "AAAAAA==", @@ -320,11 +351,10 @@ func TestInteg_ObjectChecksums(t *testing.T) { }, }, "empty body": { - "no checksum": { + "no checksum algorithm passed": { params: &s3.PutObjectInput{ Body: bytes.NewBuffer([]byte{}), }, - getObjectChecksumMode: s3types.ChecksumModeEnabled, expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ ComputedChecksums: map[string]string{ "CRC32": "AAAAAA==", @@ -334,13 +364,19 @@ func TestInteg_ObjectChecksums(t *testing.T) { AlgorithmsUsed: []string{"CRC32"}, }, }, + "no checksum calculation": { + params: &s3.PutObjectInput{ + Body: bytes.NewBuffer([]byte{}), + }, + requestChecksumCalculation: aws.RequestChecksumCalculationWhenRequired, + expectLogged: "Response has no supported checksum", + }, "preset checksum": { params: &s3.PutObjectInput{ Body: bytes.NewBuffer([]byte{}), ChecksumAlgorithm: s3types.ChecksumAlgorithmCrc32c, ChecksumCRC32C: aws.String("AAAAAA=="), }, - getObjectChecksumMode: s3types.ChecksumModeEnabled, expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ ComputedChecksums: map[string]string{ "CRC32C": "AAAAAA==", @@ -355,7 +391,6 @@ func TestInteg_ObjectChecksums(t *testing.T) { Body: bytes.NewBuffer([]byte{}), ChecksumAlgorithm: s3types.ChecksumAlgorithmCrc32c, }, - getObjectChecksumMode: s3types.ChecksumModeEnabled, expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ ComputedChecksums: map[string]string{ "CRC32C": "AAAAAA==", @@ -371,7 +406,6 @@ func TestInteg_ObjectChecksums(t *testing.T) { Body: bytes.NewBuffer([]byte{}), ChecksumAlgorithm: s3types.ChecksumAlgorithmCrc32c, }, - getObjectChecksumMode: s3types.ChecksumModeEnabled, expectComputedChecksums: &s3.ComputedInputChecksumsMetadata{ ComputedChecksums: map[string]string{ "CRC32C": "AAAAAA==", @@ -396,6 +430,9 @@ func TestInteg_ObjectChecksums(t *testing.T) { s3Options := func(o *s3.Options) { o.Logger = logger o.EndpointOptions.DisableHTTPS = c.disableHTTPS + if c.requestChecksumCalculation != 0 { + o.RequestChecksumCalculation = c.requestChecksumCalculation + } } if c.retry { @@ -432,9 +469,8 @@ func TestInteg_ObjectChecksums(t *testing.T) { } getResult, err := s3client.GetObject(ctx, &s3.GetObjectInput{ - Bucket: c.params.Bucket, - Key: c.params.Key, - ChecksumMode: c.getObjectChecksumMode, + Bucket: c.params.Bucket, + Key: c.params.Key, }, s3Options) if err != nil { t.Fatalf("expect no error, got %v", err) diff --git a/service/s3/api_op_GetObject.go b/service/s3/api_op_GetObject.go index 71dbc4beccf..7d0786c9bd7 100644 --- a/service/s3/api_op_GetObject.go +++ b/service/s3/api_op_GetObject.go @@ -814,9 +814,15 @@ func getGetObjectRequestValidationModeMember(input interface{}) (string, bool) { return string(in.ChecksumMode), true } +func setGetObjectRequestValidationModeMember(input interface{}, mode string) { + in := input.(*GetObjectInput) + in.ChecksumMode = types.ChecksumMode(mode) +} + func addGetObjectOutputChecksumMiddlewares(stack *middleware.Stack, options Options) error { return internalChecksum.AddOutputMiddleware(stack, internalChecksum.OutputMiddlewareOptions{ GetValidationMode: getGetObjectRequestValidationModeMember, + SetValidationMode: setGetObjectRequestValidationModeMember, ResponseChecksumValidation: options.ResponseChecksumValidation, ValidationAlgorithms: []string{"CRC64NVME", "CRC32", "CRC32C", "SHA256", "SHA1"}, IgnoreMultipartValidation: true,