Skip to content

Commit dfc3d8c

Browse files
authored
service/internal/checksum: Fix opt-in to checksum output validation (#1607)
Updates the SDK's checksum validation logic to require opt-in to output response payload validation. The SDK was always preforming output response payload checksum validation, not respecting the output validation model option. Fixes #1606
1 parent e643282 commit dfc3d8c

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "239ee1b1-0e40-41c4-84cf-14e5e4c25337",
3+
"type": "feature",
4+
"description": " Updates the SDK's checksum validation logic to require opt-in to output response payload validation. The SDK was always preforming output response payload checksum validation, not respecting the output validation model option. Fixes [#1606](https://github.com/aws/aws-sdk-go-v2/issues/1606)",
5+
"modules": [
6+
"service/internal/checksum"
7+
]
8+
}

service/internal/checksum/middleware_validate_output.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ func (m *validateOutputPayloadChecksum) HandleDeserialize(
6666
return out, metadata, err
6767
}
6868

69+
// If there is no validation mode specified nothing is supported.
70+
if mode := getContextOutputValidationMode(ctx); mode != "ENABLED" {
71+
return out, metadata, err
72+
}
73+
6974
response, ok := out.RawResponse.(*smithyhttp.Response)
7075
if !ok {
7176
return out, metadata, &smithy.DeserializationError{

service/internal/checksum/middleware_validate_output_test.go

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func TestValidateOutputPayloadChecksum(t *testing.T) {
2323
cases := map[string]struct {
2424
response *smithyhttp.Response
2525
validateOptions func(*validateOutputPayloadChecksum)
26+
modifyContext func(context.Context) context.Context
2627
expectHaveAlgorithmsUsed bool
2728
expectAlgorithmsUsed []string
2829
expectErr string
@@ -31,6 +32,9 @@ func TestValidateOutputPayloadChecksum(t *testing.T) {
3132
expectPayload []byte
3233
}{
3334
"success": {
35+
modifyContext: func(ctx context.Context) context.Context {
36+
return setContextOutputValidationMode(ctx, "ENABLED")
37+
},
3438
response: &smithyhttp.Response{
3539
Response: &http.Response{
3640
StatusCode: 200,
@@ -47,6 +51,9 @@ func TestValidateOutputPayloadChecksum(t *testing.T) {
4751
expectPayload: []byte("hello world"),
4852
},
4953
"failure": {
54+
modifyContext: func(ctx context.Context) context.Context {
55+
return setContextOutputValidationMode(ctx, "ENABLED")
56+
},
5057
response: &smithyhttp.Response{
5158
Response: &http.Response{
5259
StatusCode: 200,
@@ -61,6 +68,9 @@ func TestValidateOutputPayloadChecksum(t *testing.T) {
6168
expectReadErr: "checksum did not match",
6269
},
6370
"read error": {
71+
modifyContext: func(ctx context.Context) context.Context {
72+
return setContextOutputValidationMode(ctx, "ENABLED")
73+
},
6474
response: &smithyhttp.Response{
6575
Response: &http.Response{
6676
StatusCode: 200,
@@ -75,6 +85,9 @@ func TestValidateOutputPayloadChecksum(t *testing.T) {
7585
expectReadErr: "some read error",
7686
},
7787
"unsupported algorithm": {
88+
modifyContext: func(ctx context.Context) context.Context {
89+
return setContextOutputValidationMode(ctx, "ENABLED")
90+
},
7891
response: &smithyhttp.Response{
7992
Response: &http.Response{
8093
StatusCode: 200,
@@ -89,7 +102,39 @@ func TestValidateOutputPayloadChecksum(t *testing.T) {
89102
expectLogged: "no supported checksum",
90103
expectPayload: []byte("hello world"),
91104
},
105+
"no output validation model": {
106+
response: &smithyhttp.Response{
107+
Response: &http.Response{
108+
StatusCode: 200,
109+
Header: func() http.Header {
110+
h := http.Header{}
111+
return h
112+
}(),
113+
Body: ioutil.NopCloser(strings.NewReader("hello world")),
114+
},
115+
},
116+
expectPayload: []byte("hello world"),
117+
},
118+
"unknown output validation model": {
119+
modifyContext: func(ctx context.Context) context.Context {
120+
return setContextOutputValidationMode(ctx, "something else")
121+
},
122+
response: &smithyhttp.Response{
123+
Response: &http.Response{
124+
StatusCode: 200,
125+
Header: func() http.Header {
126+
h := http.Header{}
127+
return h
128+
}(),
129+
Body: ioutil.NopCloser(strings.NewReader("hello world")),
130+
},
131+
},
132+
expectPayload: []byte("hello world"),
133+
},
92134
"success ignore multipart checksum": {
135+
modifyContext: func(ctx context.Context) context.Context {
136+
return setContextOutputValidationMode(ctx, "ENABLED")
137+
},
93138
response: &smithyhttp.Response{
94139
Response: &http.Response{
95140
StatusCode: 200,
@@ -109,6 +154,9 @@ func TestValidateOutputPayloadChecksum(t *testing.T) {
109154
expectPayload: []byte("hello world"),
110155
},
111156
"success skip ignore multipart checksum": {
157+
modifyContext: func(ctx context.Context) context.Context {
158+
return setContextOutputValidationMode(ctx, "ENABLED")
159+
},
112160
response: &smithyhttp.Response{
113161
Response: &http.Response{
114162
StatusCode: 200,
@@ -136,6 +184,10 @@ func TestValidateOutputPayloadChecksum(t *testing.T) {
136184
fmt.Fprintf(&logged, format, v...)
137185
}))
138186

187+
if c.modifyContext != nil {
188+
ctx = c.modifyContext(ctx)
189+
}
190+
139191
validateOutput := validateOutputPayloadChecksum{
140192
Algorithms: []Algorithm{
141193
AlgorithmSHA1, AlgorithmCRC32, AlgorithmCRC32C,
@@ -187,10 +239,8 @@ func TestValidateOutputPayloadChecksum(t *testing.T) {
187239
return
188240
}
189241

190-
if c.expectLogged != "" {
191-
if e, a := c.expectLogged, logged.String(); !strings.Contains(a, e) {
192-
t.Errorf("expected %q logged in:\n%s", e, a)
193-
}
242+
if e, a := c.expectLogged, logged.String(); !strings.Contains(a, e) || !((e == "") == (a == "")) {
243+
t.Errorf("expected %q logged in:\n%s", e, a)
194244
}
195245

196246
if diff := cmp.Diff(string(c.expectPayload), string(actualPayload)); diff != "" {

0 commit comments

Comments
 (0)