Skip to content

Commit

Permalink
service/internal/checksum: Fix handling of require checksum
Browse files Browse the repository at this point in the history
Fixes SDK's checksum handling of require checksum with unseekable
streams. Adds additional unit tests to validate the expected behavior of
empty streams that are unseekable.

Related to aws/smithy-go#357
  • Loading branch information
jasdel committed Mar 8, 2022
1 parent dfc3d8c commit 606578d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion modman.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

[dependencies]
"github.com/aws/smithy-go" = "v1.11.0"
"github.com/aws/smithy-go" = "v1.11.1-0.20220308004241-26b41c98827"
"github.com/google/go-cmp" = "v0.5.7"
"github.com/jmespath/go-jmespath" = "v0.4.0"
"golang.org/x/net" = "v0.0.0-20220127200216-cd36cc0744dd"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,12 @@ func setMD5Checksum(ctx context.Context, req *smithyhttp.Request) (string, error
if stream == nil {
return "", nil
}

if !req.IsStreamSeekable() {
return "", fmt.Errorf(
"unseekable stream is not supported for computing md5 checksum")
}

v, err := computeMD5Checksum(stream)
if err != nil {
return "", err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,52 @@ func TestComputeInputPayloadChecksum(t *testing.T) {
"CRC32": "AAAAAA==",
},
},
"https empty stream unseekable": {
initContext: func(ctx context.Context) context.Context {
return setContextInputAlgorithm(ctx, string(AlgorithmCRC32))
},
buildInput: middleware.BuildInput{
Request: func() *smithyhttp.Request {
r := smithyhttp.NewStackRequest().(*smithyhttp.Request)
r.URL, _ = url.Parse("https://example.aws")
r.ContentLength = 0
r = requestMust(r.SetStream(&bytes.Buffer{}))
return r
}(),
},
expectHeader: http.Header{
"X-Amz-Checksum-Crc32": []string{"AAAAAA=="},
},
expectContentLength: 0,
expectPayload: nil,
expectPayloadHash: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
expectChecksumMetadata: map[string]string{
"CRC32": "AAAAAA==",
},
},
"http empty stream unseekable": {
initContext: func(ctx context.Context) context.Context {
return setContextInputAlgorithm(ctx, string(AlgorithmCRC32))
},
buildInput: middleware.BuildInput{
Request: func() *smithyhttp.Request {
r := smithyhttp.NewStackRequest().(*smithyhttp.Request)
r.URL, _ = url.Parse("http://example.aws")
r.ContentLength = 0
r = requestMust(r.SetStream(&bytes.Buffer{}))
return r
}(),
},
expectHeader: http.Header{
"X-Amz-Checksum-Crc32": []string{"AAAAAA=="},
},
expectContentLength: 0,
expectPayload: nil,
expectPayloadHash: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
expectChecksumMetadata: map[string]string{
"CRC32": "AAAAAA==",
},
},
"https nil stream": {
initContext: func(ctx context.Context) context.Context {
return setContextInputAlgorithm(ctx, string(AlgorithmCRC32))
Expand Down Expand Up @@ -430,7 +476,7 @@ func TestComputeInputPayloadChecksum(t *testing.T) {
return r
}(),
},
expectErr: "failed to rewind stream",
expectErr: "unseekable stream is not supported",
expectBuildErr: true,
},
"http unseekable stream": {
Expand Down

0 comments on commit 606578d

Please sign in to comment.