From ad2ea9bba8734c8981bcda3e2a1b4761bf537c3d Mon Sep 17 00:00:00 2001
From: Jason Del Ponte <961963+jasdel@users.noreply.github.com>
Date: Wed, 17 Aug 2022 15:00:05 -0700
Subject: [PATCH] private/protocol/query: Fix deserialize error code with
spaces (#4525)
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.
---
private/protocol/ec2query/unmarshal.go | 3 ++-
.../protocol/ec2query/unmarshal_error_test.go | 24 +++++++++++++++++++
private/protocol/query/unmarshal_error.go | 3 ++-
.../protocol/query/unmarshal_error_test.go | 21 ++++++++++++++++
4 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/private/protocol/ec2query/unmarshal.go b/private/protocol/ec2query/unmarshal.go
index c42b04a8d55..0be67be5907 100644
--- a/private/protocol/ec2query/unmarshal.go
+++ b/private/protocol/ec2query/unmarshal.go
@@ -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"
@@ -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,
)
diff --git a/private/protocol/ec2query/unmarshal_error_test.go b/private/protocol/ec2query/unmarshal_error_test.go
index ad83dc4a354..80734be5e6d 100644
--- a/private/protocol/ec2query/unmarshal_error_test.go
+++ b/private/protocol/ec2query/unmarshal_error_test.go
@@ -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(
+ `
+
+
+
+ codeAbc
+
+
+ msg123
+
+
+
+ reqID123
+ `)),
+ },
+ },
+ Code: "codeAbc", Msg: "msg123",
+ Status: 400, ReqID: "reqID123",
+ },
"unknown tag": {
Request: &request.Request{
HTTPResponse: &http.Response{
diff --git a/private/protocol/query/unmarshal_error.go b/private/protocol/query/unmarshal_error.go
index 831b0110c54..2c0cbba909b 100644
--- a/private/protocol/query/unmarshal_error.go
+++ b/private/protocol/query/unmarshal_error.go
@@ -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"
@@ -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,
)
diff --git a/private/protocol/query/unmarshal_error_test.go b/private/protocol/query/unmarshal_error_test.go
index 34bf1a56486..7e317004d5c 100644
--- a/private/protocol/query/unmarshal_error_test.go
+++ b/private/protocol/query/unmarshal_error_test.go
@@ -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(
+ `
+
+
+ codeAbc
+
+ msg123
+
+
+ reqID123
+ `)),
+ },
+ },
+ Code: "codeAbc", Msg: "msg123",
+ Status: 400, ReqID: "reqID123",
+ },
"ServiceUnavailableException": {
Request: &request.Request{
HTTPResponse: &http.Response{