Skip to content

Commit

Permalink
private/protocol/query: Fix deserialize error code with spaces (#4525)
Browse files Browse the repository at this point in the history
Fixes the ec2query and query protocol error deserializers to trim
leading and trailing spaces from error code and message parameters. JSON
based protocol's don't need this change, because the values are quoted.
  • Loading branch information
jasdel committed Aug 17, 2022
1 parent f519aeb commit ad2ea9b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
3 changes: 2 additions & 1 deletion private/protocol/ec2query/unmarshal.go
Expand Up @@ -4,6 +4,7 @@ package ec2query

import (
"encoding/xml"
"strings"

"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/request"
Expand Down Expand Up @@ -70,7 +71,7 @@ func UnmarshalError(r *request.Request) {
}

r.Error = awserr.NewRequestFailure(
awserr.New(respErr.Code, respErr.Message, nil),
awserr.New(strings.TrimSpace(respErr.Code), strings.TrimSpace(respErr.Message), nil),
r.HTTPResponse.StatusCode,
respErr.RequestID,
)
Expand Down
24 changes: 24 additions & 0 deletions private/protocol/ec2query/unmarshal_error_test.go
Expand Up @@ -40,6 +40,30 @@ func TestUnmarshalError(t *testing.T) {
Code: "codeAbc", Msg: "msg123",
Status: 400, ReqID: "reqID123",
},
"ErrorResponse with spaces": {
Request: &request.Request{
HTTPResponse: &http.Response{
StatusCode: 400,
Header: http.Header{},
Body: ioutil.NopCloser(strings.NewReader(
`<Response>
<Errors>
<Error>
<Code>
codeAbc
</Code>
<Message>
msg123
</Message>
</Error>
</Errors>
<RequestID>reqID123</RequestID>
</Response>`)),
},
},
Code: "codeAbc", Msg: "msg123",
Status: 400, ReqID: "reqID123",
},
"unknown tag": {
Request: &request.Request{
HTTPResponse: &http.Response{
Expand Down
3 changes: 2 additions & 1 deletion private/protocol/query/unmarshal_error.go
Expand Up @@ -3,6 +3,7 @@ package query
import (
"encoding/xml"
"fmt"
"strings"

"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/request"
Expand Down Expand Up @@ -62,7 +63,7 @@ func UnmarshalError(r *request.Request) {
}

r.Error = awserr.NewRequestFailure(
awserr.New(respErr.Code, respErr.Message, nil),
awserr.New(strings.TrimSpace(respErr.Code), strings.TrimSpace(respErr.Message), nil),
r.HTTPResponse.StatusCode,
reqID,
)
Expand Down
21 changes: 21 additions & 0 deletions private/protocol/query/unmarshal_error_test.go
Expand Up @@ -37,6 +37,27 @@ func TestUnmarshalError(t *testing.T) {
Code: "codeAbc", Msg: "msg123",
Status: 400, ReqID: "reqID123",
},
"ErrorResponse with spaces": {
Request: &request.Request{
HTTPResponse: &http.Response{
StatusCode: 400,
Header: http.Header{},
Body: ioutil.NopCloser(strings.NewReader(
`<ErrorResponse>
<Error>
<Code>
codeAbc
</Code><Message>
msg123
</Message>
</Error>
<RequestId>reqID123</RequestId>
</ErrorResponse>`)),
},
},
Code: "codeAbc", Msg: "msg123",
Status: 400, ReqID: "reqID123",
},
"ServiceUnavailableException": {
Request: &request.Request{
HTTPResponse: &http.Response{
Expand Down

0 comments on commit ad2ea9b

Please sign in to comment.