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 malformed request tests for validation #898

Merged
merged 1 commit into from
Aug 25, 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/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ dependencies {
implementation project(":smithy-cli")
implementation project(":smithy-protocol-test-traits")
implementation project(":smithy-aws-traits")
api project(":smithy-validation-model")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
$version: "1.0"

namespace aws.protocoltests.restjson.validation

use aws.api#service
use aws.protocols#restJson1

/// A REST JSON service that sends JSON requests and responses with validation applied
@service(sdkId: "Rest Json Validation Protocol")
@restJson1
service RestJsonValidation {
version: "2021-08-19",
operations: [
MalformedEnum,
MalformedLength,
MalformedLengthOverride,
MalformedPattern,
MalformedPatternOverride,
MalformedRange,
MalformedRangeOverride,
MalformedRequired,
RecursiveStructures,
SensitiveValidation
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
$version: "1.0"

namespace aws.protocoltests.restjson.validation

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

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

apply MalformedEnum @httpMalformedRequestTests([
{
id: "RestJsonMalformedEnumString",
documentation: """
When a string member does not contain a valid enum value,
the response should be a 400 ValidationException.""",
protocol: restJson1,
request: {
method: "POST",
uri: "/MalformedEnum",
body: """
{ "string" : $value:S }""",
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 $value:L at '/string' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]",
"fieldList" : [{"message": "Value $value:L at '/string' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]", "path": "/string"}]}"""
}
}
},
testParameters: {
value: ["ABC", "XYZ"]
}
},
{
id: "RestJsonMalformedEnumList",
documentation: """
When a list member value does not contain a valid enum value,
the response should be a 400 ValidationException.""",
protocol: restJson1,
request: {
method: "POST",
uri: "/MalformedEnum",
body: """
{ "list" : [$value:S] }""",
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 $value:L at '/list/0' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]",
"fieldList" : [{"message": "Value $value:L at '/list/0' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]", "path": "/list/0"}]}"""
}
}
},
testParameters: {
value: ["ABC", "XYZ"]
}
},
{
id: "RestJsonMalformedEnumMapKey",
documentation: """
When a map member's key does not contain a valid enum value,
the response should be a 400 ValidationException.""",
protocol: restJson1,
request: {
method: "POST",
uri: "/MalformedEnum",
body: """
{ "map" : { $value:S : "abc" } }""",
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 $value:L at '/map' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]",
"fieldList" : [{"message": "Value $value:L at '/map' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]", "path": "/map"}]}"""
}
}
},
testParameters: {
value: ["ABC", "XYZ"]
}
},
{
id: "RestJsonMalformedEnumMapValue",
documentation: """
When a map member's value does not contain a valid enum value,
the response should be a 400 ValidationException.""",
protocol: restJson1,
request: {
method: "POST",
uri: "/MalformedEnum",
body: """
{ "map" : { "abc": $value:S } }""",
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 $value:L at '/map/abc' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]",
"fieldList" : [{"message": "Value $value:L at '/map/abc' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]", "path": "/map/abc"}]}"""
}
}
},
testParameters: {
value: ["ABC", "XYZ"]
}
},
{
id: "RestJsonMalformedEnumUnion",
documentation: """
When a union member's value does not contain a valid enum value,
the response should be a 400 ValidationException.""",
protocol: restJson1,
request: {
method: "POST",
uri: "/MalformedEnum",
body: """
{ "union" : { "first": $value:S } }""",
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 $value:L at '/union/first' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]",
"fieldList" : [{"message": "Value $value:L at '/union/first' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]", "path": "/union/first"}]}"""
}
}
},
testParameters: {
value: ["ABC", "XYZ"]
}
},
])

structure MalformedEnumInput {
string: EnumString,

list: EnumList,

map: EnumMap,

union: EnumUnion
}

@enum([{value: "abc", name: "ABC"}, {value: "def", name: "DEF"}])
string EnumString

list EnumList {
member: EnumString
}

map EnumMap {
key: EnumString,
value: EnumString
}

union EnumUnion {
first: EnumString,
second: EnumString
}
Loading