Skip to content

Commit b53fd37

Browse files
Add protocol tests for awsQueryCompatible
This adds protocol tests for the [awsQueryCompatible trait](https://smithy.io/2.0/aws/protocols/aws-query-protocol.html#aws-protocols-awsquerycompatible-trait) for both `rpcv2Cbor` and `awsJson1_0`. These tests may be successfully run by existing protocol test implementations, but changes must be made to get the full effect. Protocol test implementations must be updated to support the `ErrorCodeParams` vendor params if they generically expose error code or query error type.
1 parent 71b0651 commit b53fd37

File tree

7 files changed

+280
-0
lines changed

7 files changed

+280
-0
lines changed

smithy-aws-protocol-tests/model/aws-config.smithy

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,30 @@ enum RetryMode {
109109
STANDARD = "standard"
110110
ADAPTIVE = "adaptive"
111111
}
112+
113+
/// Vendor params to use when making assertions about error code or query
114+
/// error type.
115+
structure ErrorCodeParams {
116+
/// The error code exposed to the customer.
117+
///
118+
/// If the SDK exposes the error code to customers, this value MUST be
119+
/// asserted to match the exposed error code.
120+
///
121+
/// This is modifiable by the awsQueryError trait. For services with
122+
/// awsQueryCompatible, it will be exposed in the `x-amzn-query-error`
123+
/// header which takes the form `Code;Fault`. This value represents
124+
/// the `Code` portion.
125+
@required
126+
code: String
127+
128+
/// The query error type exposed to the customer.
129+
///
130+
/// If the SDK exposes the query error type to customers, this value MUST be
131+
/// asserted to match the exposed query error type.
132+
///
133+
/// This is modifiable by the awsQueryError trait. For services with
134+
/// awsQueryCompatible, it will be exposed in the `x-amzn-query-error`
135+
/// header which takes the form `Code;Fault`. This value represents
136+
/// the `Fault` portion.
137+
type: String
138+
}

smithy-aws-protocol-tests/model/awsJson1_0/main.smithy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace aws.protocoltests.json10
55
use aws.api#service
66
use aws.auth#sigv4
77
use aws.protocols#awsJson1_0
8+
use aws.protocols#awsQueryCompatible
89
use smithy.test#httpRequestTests
910
use smithy.test#httpResponseTests
1011

@@ -42,5 +43,20 @@ service JsonRpc10 {
4243
OperationWithRequiredMembers,
4344
OperationWithNestedStructure
4445
OperationWithRequiredMembersWithDefaults
46+
47+
QueryIncompatibleOperation
48+
]
49+
}
50+
51+
52+
@service(sdkId: "Query Compatible JSON RPC 10")
53+
@sigv4(name: "query-compatible-jsonrpc10")
54+
@awsJson1_0
55+
@title("Query Compatible Json 1.0 Protocol Service")
56+
@awsQueryCompatible
57+
service QueryCompatibleJsonRpc10 {
58+
version: "2020-07-14",
59+
operations: [
60+
QueryCompatibleOperation
4561
]
4662
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
$version: "2.0"
2+
3+
namespace aws.protocoltests.json10
4+
5+
use aws.protocols#awsJson1_0
6+
use aws.protocols#awsQueryError
7+
use aws.protocoltests.config#ErrorCodeParams
8+
use smithy.test#httpRequestTests
9+
use smithy.test#httpResponseTests
10+
11+
@httpRequestTests([
12+
{
13+
id: "NonQueryCompatibleAwsJson10ForbidsQueryModeHeader"
14+
documentation: "The query mode header MUST NOT be set on non-query-compatible services."
15+
protocol: awsJson1_0
16+
method: "POST"
17+
headers: { "Content-Type": "application/x-amz-json-1.0", "X-Amz-Target": "JsonRpc10.QueryIncompatibleOperation" }
18+
uri: "/"
19+
body: "{}"
20+
bodyMediaType: "application/json"
21+
}
22+
])
23+
@idempotent
24+
operation QueryIncompatibleOperation {}
25+
26+
@idempotent
27+
operation QueryCompatibleOperation {
28+
errors: [
29+
NoCustomCodeError
30+
CustomCodeError
31+
]
32+
}
33+
34+
apply QueryCompatibleOperation @httpRequestTests([
35+
{
36+
id: "QueryCompatibleAwsJson10CborSendsQueryModeHeader"
37+
documentation: "Clients for query-compatible services MUST send the x-amzn-query-mode header."
38+
protocol: awsJson1_0
39+
method: "POST"
40+
headers: { "Content-Type": "application/x-amz-json-1.0", "x-amzn-query-mode": "true", "X-Amz-Target": "QueryCompatibleJsonRpc10.QueryCompatibleOperation" }
41+
uri: "/"
42+
body: "{}"
43+
bodyMediaType: "application/json"
44+
}
45+
])
46+
47+
@error("client")
48+
structure NoCustomCodeError {
49+
message: String
50+
}
51+
52+
apply NoCustomCodeError @httpResponseTests([
53+
{
54+
id: "QueryCompatibleAwsJson10CborNoCustomCodeError"
55+
documentation: "Parses simple errors with no query error code"
56+
protocol: awsJson1_0
57+
params: { message: "Hi" }
58+
code: 400
59+
headers: { "Content-Type": "application/x-amz-json-1.0" }
60+
body: """
61+
{
62+
"__type": "aws.protocoltests.json10#NoCustomCodeError",
63+
"Message": "Hi"
64+
}"""
65+
bodyMediaType: "application/json"
66+
vendorParamsShape: ErrorCodeParams
67+
vendorParams: { code: "NoCustomCodeError" }
68+
}
69+
])
70+
71+
@awsQueryError(code: "Customized", httpResponseCode: 402)
72+
@error("client")
73+
structure CustomCodeError {
74+
message: String
75+
}
76+
77+
apply CustomCodeError @httpResponseTests([
78+
{
79+
id: "QueryCompatibleAwsJson10CustomCodeError"
80+
documentation: "Parses simple errors with query error code"
81+
protocol: awsJson1_0
82+
params: { message: "Hi" }
83+
code: 400
84+
headers: { "Content-Type": "application/x-amz-json-1.0", "x-amzn-query-error": "Customized;Sender" }
85+
body: """
86+
{
87+
"__type": "aws.protocoltests.json10#CustomCodeError",
88+
"Message": "Hi"
89+
}"""
90+
bodyMediaType: "application/json"
91+
vendorParamsShape: ErrorCodeParams
92+
vendorParams: { code: "Customized", type: "Sender" }
93+
}
94+
])

smithy-aws-protocol-tests/model/awsQuery/xml-errors.smithy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace aws.protocoltests.query
2929

3030
use aws.protocols#awsQueryError
3131
use aws.protocols#awsQuery
32+
use aws.protocoltests.config#ErrorCodeParams
3233
use smithy.test#httpResponseTests
3334

3435
/// This operation has three possible return values:
@@ -97,6 +98,11 @@ apply InvalidGreeting @httpResponseTests([
9798
</ErrorResponse>
9899
""",
99100
bodyMediaType: "application/xml",
101+
vendorParamsShape: ErrorCodeParams
102+
vendorParams: {
103+
code: "InvalidGreeting"
104+
type: "Sender"
105+
}
100106
}
101107
])
102108

@@ -136,6 +142,11 @@ apply ComplexError @httpResponseTests([
136142
</ErrorResponse>
137143
""",
138144
bodyMediaType: "application/xml",
145+
vendorParamsShape: ErrorCodeParams
146+
vendorParams: {
147+
code: "ComplexError"
148+
type: "Sender"
149+
}
139150
}
140151
])
141152

@@ -175,5 +186,10 @@ apply CustomCodeError @httpResponseTests([
175186
</ErrorResponse>
176187
""",
177188
bodyMediaType: "application/xml",
189+
vendorParamsShape: ErrorCodeParams
190+
vendorParams: {
191+
code: "Customized"
192+
type: "Sender"
193+
}
178194
}
179195
])

smithy-aws-protocol-tests/model/ec2Query/xml-errors.smithy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ $version: "2.0"
2323
namespace aws.protocoltests.ec2
2424

2525
use aws.protocols#ec2Query
26+
use aws.protocoltests.config#ErrorCodeParams
2627
use smithy.test#httpResponseTests
2728

2829
/// This operation has three possible return values:
@@ -91,6 +92,10 @@ apply InvalidGreeting @httpResponseTests([
9192
params: {
9293
Message: "Hi"
9394
},
95+
vendorParamsShape: ErrorCodeParams
96+
vendorParams: {
97+
code: "InvalidGreeting"
98+
}
9499
}
95100
])
96101

@@ -132,6 +137,10 @@ apply ComplexError @httpResponseTests([
132137
</Response>
133138
""",
134139
bodyMediaType: "application/xml",
140+
vendorParamsShape: ErrorCodeParams
141+
vendorParams: {
142+
code: "ComplexError"
143+
}
135144
}
136145
])
137146

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
$version: "2"
2+
3+
namespace aws.protocoltests.rpcv2cbor
4+
5+
use aws.api#service
6+
use aws.auth#sigv4
7+
use aws.protocols#awsQueryCompatible
8+
use smithy.protocols#rpcv2Cbor
9+
10+
@service(sdkId: "Query Compatible RpcV2 Protocol")
11+
@sigv4(name: "query-compatible-rpcv2")
12+
@rpcv2Cbor
13+
@title("Query Compatible RpcV2 Protocol Service")
14+
@awsQueryCompatible
15+
service QueryCompatibleRpcV2Protocol {
16+
version: "2025-06-20"
17+
operations: [
18+
QueryCompatibleOperation
19+
]
20+
}
21+
22+
@service(sdkId: "Non Query Compatible RpcV2 Protocol")
23+
@sigv4(name: "non-query-compatible-rpcv2")
24+
@rpcv2Cbor
25+
@title("Non Query Compatible RpcV2 Protocol Service")
26+
service NonQueryCompatibleRpcV2Protocol {
27+
version: "2025-06-20"
28+
operations: [
29+
QueryIncompatibleOperation
30+
]
31+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
$version: "2"
2+
3+
namespace aws.protocoltests.rpcv2cbor
4+
5+
use aws.protocols#awsQueryError
6+
use aws.protocoltests.config#ErrorCodeParams
7+
use smithy.protocols#rpcv2Cbor
8+
use smithy.test#httpRequestTests
9+
use smithy.test#httpResponseTests
10+
11+
@httpRequestTests([
12+
{
13+
id: "NonQueryCompatibleRpcV2CborForbidsQueryModeHeader"
14+
documentation: "The query mode header MUST NOT be set on non-query-compatible services."
15+
protocol: rpcv2Cbor
16+
method: "POST"
17+
headers: { "smithy-protocol": "rpc-v2-cbor", Accept: "application/cbor" }
18+
forbidHeaders: ["x-amzn-query-mode"]
19+
uri: "/service/NonQueryCompatibleRpcV2Protocol/operation/QueryIncompatibleOperation"
20+
body: "{}"
21+
bodyMediaType: "application/json"
22+
}
23+
])
24+
@idempotent
25+
operation QueryIncompatibleOperation {}
26+
27+
@idempotent
28+
operation QueryCompatibleOperation {
29+
errors: [
30+
NoCustomCodeError
31+
CustomCodeError
32+
]
33+
}
34+
35+
apply QueryCompatibleOperation @httpRequestTests([
36+
{
37+
id: "QueryCompatibleRpcV2CborSendsQueryModeHeader"
38+
documentation: "Clients for query-compatible services MUST send the x-amzn-query-mode header."
39+
protocol: rpcv2Cbor
40+
method: "POST"
41+
headers: { "smithy-protocol": "rpc-v2-cbor", Accept: "application/cbor", "x-amzn-query-mode": "true" }
42+
forbidHeaders: ["Content-Type", "X-Amz-Target"]
43+
uri: "/service/QueryCompatibleRpcV2Protocol/operation/QueryCompatibleOperation"
44+
body: ""
45+
}
46+
])
47+
48+
@error("client")
49+
structure NoCustomCodeError {
50+
message: String
51+
}
52+
53+
apply NoCustomCodeError @httpResponseTests([
54+
{
55+
id: "QueryCompatibleRpcV2CborNoCustomCodeError"
56+
documentation: "Parses simple RpcV2 CBOR errors with no query error code"
57+
protocol: rpcv2Cbor
58+
params: { message: "Hi" }
59+
code: 400
60+
headers: { "smithy-protocol": "rpc-v2-cbor", "Content-Type": "application/cbor" }
61+
body: "v2ZfX3R5cGV4MHNtaXRoeS5wcm90b2NvbHRlc3RzLnJwY3YyQ2JvciNOb0N1c3RvbUNvZGVFcnJvcmdNZXNzYWdlYkhp/w=="
62+
bodyMediaType: "application/cbor"
63+
vendorParamsShape: ErrorCodeParams
64+
vendorParams: { code: "NoCustomCodeError" }
65+
}
66+
])
67+
68+
@awsQueryError(code: "Customized", httpResponseCode: 402)
69+
@error("client")
70+
structure CustomCodeError {
71+
message: String
72+
}
73+
74+
apply CustomCodeError @httpResponseTests([
75+
{
76+
id: "QueryCompatibleRpcV2CborCustomCodeError"
77+
documentation: "Parses simple RpcV2 CBOR errors with query error code"
78+
protocol: rpcv2Cbor
79+
params: { message: "Hi" }
80+
code: 400
81+
headers: { "smithy-protocol": "rpc-v2-cbor", "Content-Type": "application/cbor", "x-amzn-query-error": "Customized;Sender" }
82+
body: "v2ZfX3R5cGV4LnNtaXRoeS5wcm90b2NvbHRlc3RzLnJwY3YyQ2JvciNDdXN0b21Db2RlRXJyb3JnTWVzc2FnZWJIaf8="
83+
bodyMediaType: "application/cbor"
84+
vendorParamsShape: ErrorCodeParams
85+
vendorParams: { code: "Customized", type: "Sender" }
86+
}
87+
])

0 commit comments

Comments
 (0)