Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some initial malformed request tests #879

Merged
merged 1 commit into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions smithy-aws-protocol-tests/model/restJson1/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,20 @@ service RestJson {

// checksum(s)
HttpChecksumRequired,

// malformed request tests
MalformedRequestBody,
MalformedInteger,
MalformedUnion,
MalformedBoolean,
MalformedSet,
MalformedList,
MalformedMap,
MalformedBlob,
MalformedByte,
MalformedShort,
MalformedLong,
MalformedFloat,
MalformedDouble
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
$version: "1.0"

namespace aws.protocoltests.restjson

use aws.protocols#restJson1
use smithy.test#httpMalformedRequestTests

@http(uri: "/MalformedBlob", method: "POST")
operation MalformedBlob {
input: MalformedBlobInput
}

apply MalformedBlob @httpMalformedRequestTests([
{
id: "RestJsonBodyMalformedBlobInvalidBase64",
documentation: """
When a blob member is not properly base64 encoded, or not encoded at
all, the response should be a 400 SerializationException.""",
protocol: restJson1,
request: {
method: "POST",
uri: "/MalformedBlob",
body: """
{ "blob" : $value:L }""",
headers: {
"content-type": "application/json"
}
},
response: {
code: 400,
headers: {
"x-amzn-errortype": "SerializationException"
}
},
testParameters: {
value: ["blob", "\"xyz\"", "\"YmxvYg=\"", "[98, 108, 11, 98]",
"[\"b\", \"l\",\"o\",\"b\"]", "981081198", "true"]
}
},
])

structure MalformedBlobInput {
blob: Blob,
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
$version: "1.0"

namespace aws.protocoltests.restjson

use aws.protocols#restJson1
use smithy.test#httpMalformedRequestTests

@http(uri: "/MalformedBoolean/{booleanInPath}", method: "POST")
operation MalformedBoolean {
input: MalformedBooleanInput
}

apply MalformedBoolean @httpMalformedRequestTests([
{
id: "RestJsonBodyBooleanStringCoercion",
documentation: """
Attempted string coercion should result in SerializationException""",
protocol: restJson1,
request: {
method: "POST",
uri: "/MalformedBoolean/true",
body: """
{ "booleanInBody" : $value:S }""",
headers: {
"content-type": "application/json"
}
},
response: {
code: 400,
headers: {
"x-amzn-errortype": "SerializationException"
}
},
testParameters: {
"value" : ["true", "True", "TRUE", "y", "Y", "yes", "Yes", "YES", "1", "on", "On", "ON",
"false", "False", "FALSE", "n", "N", "no", "No", "NO", "0", "off", "Off", "OFF"]
}
},
{
id: "RestJsonBodyBooleanBadLiteral",
documentation: """
YAML-style alternate boolean literals should result in SerializationException""",
protocol: restJson1,
request: {
method: "POST",
uri: "/MalformedBoolean/true",
body: """
{ "booleanInBody" : $value:L }""",
headers: {
"content-type": "application/json"
}
},
response: {
code: 400,
headers: {
"x-amzn-errortype": "SerializationException"
}
},
testParameters: {
"value" : ["True", "TRUE", "y", "Y", "yes", "Yes", "YES", "1", "on", "On", "ON",
"False", "FALSE", "n", "N", "no", "No", "NO", "0", "off", "Off", "OFF"]
}
},
{
id: "RestJsonPathBooleanStringCoercion",
documentation: """
Attempted string coercion should result in SerializationException""",
protocol: restJson1,
request: {
method: "POST",
uri: "/MalformedBoolean/$value:L"
},
response: {
code: 400,
headers: {
"x-amzn-errortype": "SerializationException"
}
},
testParameters: {
"value" : ["True", "TRUE", "y", "Y", "yes", "Yes", "YES", "1", "on", "On", "ON",
"False", "FALSE", "n", "N", "no", "No", "NO", "0", "off", "Off", "OFF"]
}
},
{
id: "RestJsonQueryBooleanStringCoercion",
documentation: """
Attempted string coercion should result in SerializationException""",
protocol: restJson1,
request: {
method: "POST",
uri: "/MalformedBoolean/true",
queryParams: [
"booleanInQuery=$value:L"
]
},
response: {
code: 400,
headers: {
"x-amzn-errortype": "SerializationException"
}
},
testParameters: {
"value" : ["True", "TRUE", "y", "Y", "yes", "Yes", "YES", "1", "on", "On", "ON",
"False", "FALSE", "n", "N", "no", "No", "NO", "0", "off", "Off", "OFF"]
}
},
{
id: "RestJsonHeaderBooleanStringCoercion",
documentation: """
Attempted string coercion should result in SerializationException""",
protocol: restJson1,
request: {
method: "POST",
uri: "/MalformedBoolean/true",
headers: {
"booleanInHeader" : "$value:L"
}
},
response: {
code: 400,
headers: {
"x-amzn-errortype": "SerializationException"
}
},
testParameters: {
"value" : ["True", "TRUE", "y", "Y", "yes", "Yes", "YES", "1", "on", "On", "ON",
"False", "FALSE", "n", "N", "no", "No", "NO", "0", "off", "Off", "OFF"]
}
}
])

structure MalformedBooleanInput {
booleanInBody: Boolean,

@httpLabel
@required
booleanInPath: Boolean,

@httpQuery("booleanInQuery")
booleanInQuery: Boolean,

@httpHeader("booleanInHeader")
booleanInHeader: Boolean
}

Loading