Skip to content

Commit

Permalink
Add protocol tests for validation
Browse files Browse the repository at this point in the history
  • Loading branch information
adamthom-amzn committed Aug 24, 2021
1 parent a239b87 commit 4371ecf
Show file tree
Hide file tree
Showing 9 changed files with 2,033 additions and 0 deletions.
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")
}
25 changes: 25 additions & 0 deletions smithy-aws-protocol-tests/model/restJson1/validation/main.smithy
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

0 comments on commit 4371ecf

Please sign in to comment.