Skip to content

Commit 977ee1d

Browse files
authored
don't perform checksum validation in non-200 responses (#3075)
1 parent b06fd66 commit 977ee1d

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "498b8f56-2400-4975-8f82-d8ee7a827ccd",
3+
"type": "bugfix",
4+
"description": "Don't emit warnings about lack of checksum validation for non-200 responses.",
5+
"modules": [
6+
"service/internal/checksum"
7+
]
8+
}

service/internal/checksum/middleware_validate_output.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ func (m *validateOutputPayloadChecksum) HandleDeserialize(
7878
}
7979
}
8080

81+
// this runs BEFORE the deserializer, so we have to preemptively check for
82+
// non-200, in which case there is no checksum to validate
83+
if response.StatusCode != 200 {
84+
return out, metadata, err
85+
}
86+
8187
var expectedChecksum string
8288
var algorithmToUse Algorithm
8389
for _, algorithm := range m.Algorithms {
@@ -94,7 +100,7 @@ func (m *validateOutputPayloadChecksum) HandleDeserialize(
94100

95101
// Skip validation if no checksum algorithm or checksum is available.
96102
if len(expectedChecksum) == 0 || len(algorithmToUse) == 0 {
97-
if response.StatusCode != 404 && response.Body != http.NoBody && m.LogValidationSkipped {
103+
if response.Body != http.NoBody && m.LogValidationSkipped {
98104
// TODO this probably should have more information about the
99105
// operation output that won't be validated.
100106
logger.Logf(logging.Warn,

service/internal/checksum/middleware_validate_output_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ func TestValidateOutputPayloadChecksum(t *testing.T) {
153153
expectAlgorithmsUsed: []string{"CRC32"},
154154
expectPayload: []byte("hello world"),
155155
},
156+
"skip non-200": {
157+
modifyContext: func(ctx context.Context) context.Context {
158+
return setContextOutputValidationMode(ctx, "ENABLED")
159+
},
160+
response: &smithyhttp.Response{
161+
Response: &http.Response{
162+
StatusCode: 400,
163+
Body: ioutil.NopCloser(strings.NewReader("error")),
164+
},
165+
},
166+
// does not log
167+
expectHaveAlgorithmsUsed: false,
168+
expectPayload: []byte("error"),
169+
},
156170
"success skip ignore multipart checksum": {
157171
modifyContext: func(ctx context.Context) context.Context {
158172
return setContextOutputValidationMode(ctx, "ENABLED")

0 commit comments

Comments
 (0)