Skip to content

Commit

Permalink
Some initial malformed request tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamthom-amzn committed Aug 4, 2021
1 parent bdc32a2 commit 5c8af3e
Show file tree
Hide file tree
Showing 14 changed files with 1,723 additions and 0 deletions.
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

0 comments on commit 5c8af3e

Please sign in to comment.