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

Fix validation tests #933

Merged
merged 2 commits into from
Oct 11, 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ service RestJsonValidation {
MalformedEnum,
MalformedLength,
MalformedLengthOverride,
MalformedLengthQueryString,
MalformedPattern,
MalformedPatternOverride,
MalformedRange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ operation MalformedLengthOverride {
errors: [ValidationException]
}

@http(uri: "/MalformedLengthQueryString", method: "POST")
operation MalformedLengthQueryString {
input: MalformedLengthQueryStringInput,
errors: [ValidationException]
}

apply MalformedLength @httpMalformedRequestTests([
{
id: "RestJsonMalformedLengthBlob",
Expand Down Expand Up @@ -366,7 +372,7 @@ apply MalformedLengthOverride @httpMalformedRequestTests([
}
},
testParameters: {
value: ["YWJj", "YWJjZGVmZw==="],
value: ["YWJj", "YWJjZGVmZw=="],
inputLength: ["3", "7"]
}
},
Expand Down Expand Up @@ -542,6 +548,43 @@ apply MalformedLengthOverride @httpMalformedRequestTests([
}
])

// query strings that have unspecified value are treated as being an empty string
// which means length validation is as important as required validation for ensuring a specified value
apply MalformedLengthQueryString @httpMalformedRequestTests([
{
id: "RestJsonMalformedLengthQueryStringNoValue",
documentation: """
When a required member has no value in the query string,
the response should be a 400 ValidationException.""",
protocol: restJson1,
request: {
method: "POST",
uri: "/MalformedLengthQueryString",
body: "{}",
queryParams: [
"string"
],
headers: {
"content-type": "application/json"
},
},
response: {
code: 400,
headers: {
"x-amzn-errortype": "ValidationException"
},
body: {
mediaType: "application/json",
assertion: {
contents: """
{ "message" : "1 validation error detected. Value with length 0 at '/string' failed to satisfy constraint: Member must have length between 2 and 8, inclusive",
"fieldList" : [{"message": "Value with length 0 at '/string' failed to satisfy constraint: Member must have length between 2 and 8, inclusive", "path": "/string"}]}"""
}
}
}
},
])

structure MalformedLengthInput {
blob: LengthBlob,
string: LengthString,
Expand Down Expand Up @@ -571,6 +614,11 @@ structure MalformedLengthOverrideInput {
map: LengthMap
}

structure MalformedLengthQueryStringInput {
@httpQuery("string")
string: LengthString
}

@length(min:2, max:8)
blob LengthBlob

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,40 +82,6 @@ apply MalformedRequired @httpMalformedRequestTests([
}
}
},
{
id: "RestJsonMalformedRequiredQueryNoValue",
documentation: """
When a required member has no value in the query string,
the response should be a 400 ValidationException.""",
protocol: restJson1,
request: {
method: "POST",
uri: "/MalformedRequired",
body: """
{ "string": "abc" }""",
queryParams: [
"stringInQuery"
],
headers: {
"content-type": "application/json",
"string-in-headers": "abc"
},
},
response: {
code: 400,
headers: {
"x-amzn-errortype": "ValidationException"
},
body: {
mediaType: "application/json",
assertion: {
contents: """
{ "message" : "1 validation error detected. Value null at '/string' failed to satisfy constraint: Member must not be null",
"fieldList" : [{"message": "Value null at '/string' failed to satisfy constraint: Member must not be null", "path": "/string"}]}"""
}
}
}
},
{
id: "RestJsonMalformedRequiredHeaderUnset",
documentation: """
Expand Down