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

Add more base64 malformed request tests #905

Merged
merged 1 commit into from
Sep 14, 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
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 /
"-_=="
Comment on lines +45 to +47
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to accept these or not? They're often used for uri-safe and filename-safe encoding. They can also be percent encoded in the uri case.

This also raises the question of whether media-typed strings should be encoded when used in a URI. Percent encoding should be sufficient there, I think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, percent encoding sounds right to me.

]
}
},
])

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

@mediaType("application/json")
string JsonHeaderString