Skip to content

Commit

Permalink
Add more base64 malformed request tests
Browse files Browse the repository at this point in the history
This adds more base64 tests, including ones for strings that use
mediaType in places where they need to be encoded.
  • Loading branch information
JordonPhillips committed Sep 14, 2021
1 parent bc8939b commit fdf5340
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions smithy-aws-protocol-tests/model/restJson1/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ service RestJson {
MalformedLong,
MalformedFloat,
MalformedDouble,
MalformedString,
MalformedTimestampPathDefault,
MalformedTimestampPathHttpDate,
MalformedTimestampPathEpoch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ apply MalformedBlob @httpMalformedRequestTests([
},
testParameters: {
value: ["blob", "\"xyz\"", "\"YmxvYg=\"", "[98, 108, 11, 98]",
"[\"b\", \"l\",\"o\",\"b\"]", "981081198", "true"]
"[\"b\", \"l\",\"o\",\"b\"]", "981081198", "true", "[][]", "-_=="]
}
},
])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
$version: "1.0"

namespace aws.protocoltests.restjson

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

@http(uri: "/MalformedString", method: "POST")
operation MalformedString {
input: MalformedStringInput
}

apply MalformedString @httpMalformedRequestTests([
{
id: "RestJsonHeaderMalformedStringInvalidBase64MediaType",
documentation: """
When string with the mediaType trait is bound to a header, its value
must be base64 encoded. The server should reject values that aren't
valid base64 out of hand.""",
protocol: restJson1,
request: {
method: "POST",
uri: "/MalformedString",
body: """
{ "blob" : $value:L }""",
headers: {
"content-type": "application/json",
"amz-media-typed-header": "$value:L",
}
},
response: {
code: 400,
headers: {
"x-amzn-errortype": "SerializationException"
}
},
testParameters: {
value: [
// Insufficient padding
"xyz",
// Extant, but also insufficient padding
"YmxvYg=",
// Invalid characters
"[][]",
// Invalid characters which are commonly used as filename-safe
// alternatives to + and /
"-_=="
]
}
},
])

structure MalformedStringInput {
@httpHeader("x-media-typed-header")
blob: JsonHeaderString,
}

@mediaType("application/json")
string JsonHeaderString

0 comments on commit fdf5340

Please sign in to comment.