Skip to content

Commit

Permalink
Add restXml protocol test for http label escaping
Browse files Browse the repository at this point in the history
Adds an httpRequestTests case to restXml protocol tests to verify
that httpLabel bindings in the request URI are percent-encoded.
restJson1 had an existing test case for this, but was updated to
verify the space character is encoded. An operation was also added
to the testing S3 service model with httpRequestTests to verify the
same thing, but with S3's virtual host addressing. No other protocols
had tests added, because restJson1 and restXml are the only protocols
that support httpLabel bindings.

Changes were tested by generating and running protocol tests in
aws-sdk-go-v2 and aws-sdk-js-v3, confirming the new test case is
generated and runs successfully.
  • Loading branch information
milesziemer committed May 4, 2023
1 parent 44e3fdf commit 674628e
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 2 deletions.
4 changes: 2 additions & 2 deletions smithy-aws-protocol-tests/model/restJson1/http-labels.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ apply HttpRequestWithLabels @httpRequestTests([
documentation: "Sends a GET request that uses URI label bindings",
protocol: restJson1,
method: "GET",
uri: "/HttpRequestWithLabels/%25%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D%F0%9F%98%B9/1/2/3/4.1/5.1/true/2019-12-16T23%3A48%3A18Z",
uri: "/HttpRequestWithLabels/%20%25%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D%F0%9F%98%B9/1/2/3/4.1/5.1/true/2019-12-16T23%3A48%3A18Z",
body: "",
params: {
string: "%:/?#[]@!$&'()*+,;=😹",
string: " %:/?#[]@!$&'()*+,;=😹",
short: 1,
integer: 2,
long: 3,
Expand Down
18 changes: 18 additions & 0 deletions smithy-aws-protocol-tests/model/restXml/http-labels.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ apply HttpRequestWithLabels @httpRequestTests([
timestamp: 1576540098
}
},
{
id: "HttpRequestLabelEscaping",
documentation: "Sends a GET request that uses URI label bindings",
protocol: restXml,
method: "GET",
uri: "/HttpRequestWithLabels/%20%25%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D%F0%9F%98%B9/1/2/3/4.1/5.1/true/2019-12-16T23%3A48%3A18Z",
body: "",
params: {
string: " %:/?#[]@!$&'()*+,;=😹",
short: 1,
integer: 2,
long: 3,
float: 4.1,
double: 5.1,
boolean: true,
timestamp: 1576540098
}
},
])

structure HttpRequestWithLabelsInput {
Expand Down
98 changes: 98 additions & 0 deletions smithy-aws-protocol-tests/model/restXml/services/s3.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use aws.api#service
use aws.auth#sigv4
use aws.customizations#s3UnwrappedXmlOutput
use aws.protocols#restXml
use aws.protocols#httpChecksum
use smithy.test#httpRequestTests
use smithy.test#httpResponseTests

Expand All @@ -42,6 +43,7 @@ service AmazonS3 {
operations: [
ListObjectsV2,
GetBucketLocation,
DeleteObjectTagging
],
}

Expand Down Expand Up @@ -272,6 +274,76 @@ operation ListObjectsV2 {
}


@httpRequestTests([
{
id: "S3EscapeObjectKeyInUriLabel",
documentation: """
S3 clients should escape special characters in Object Keys
when the Object Key is used as a URI label binding.
""",
protocol: restXml,
method: "DELETE",
uri: "/my%20key.txt",
host: "s3.us-west-2.amazonaws.com",
resolvedHost: "mybucket.s3.us-west-2.amazonaws.com",
body: "",
queryParams: [
"tagging"
],
params: {
Bucket: "mybucket",
Key: "my key.txt"
},
vendorParamsShape: aws.protocoltests.config#AwsConfig,
vendorParams: {
scopedConfig: {
client: {
region: "us-west-2",
},
},
},
},
{
id: "S3EscapePathObjectKeyInUriLabel",
documentation: """
S3 clients should preserve an Object Key representing a path
when the Object Key is used as a URI label binding, but still
escape special characters.
""",
protocol: restXml,
method: "DELETE",
uri: "/foo/bar/my%20key.txt",
host: "s3.us-west-2.amazonaws.com",
resolvedHost: "mybucket.s3.us-west-2.amazonaws.com",
body: "",
queryParams: [
"tagging"
],
params: {
Bucket: "mybucket",
Key: "foo/bar/my key.txt"
},
vendorParamsShape: aws.protocoltests.config#AwsConfig,
vendorParams: {
scopedConfig: {
client: {
region: "us-west-2",
},
},
},
}
])
@http(
method: "DELETE",
uri: "/{Bucket}/{Key+}?tagging",
code: 204
)
operation DeleteObjectTagging {
input: DeleteObjectTaggingRequest
output: DeleteObjectTaggingOutput
}


@httpResponseTests([{
id: "GetBucketLocationUnwrappedOutput",
documentation: """
Expand Down Expand Up @@ -369,6 +441,29 @@ structure ListObjectsV2Output {
StartAfter: StartAfter,
}

@input
structure DeleteObjectTaggingRequest {
@httpLabel
@required
Bucket: BucketName

@httpLabel
@required
Key: ObjectKey

@httpQuery("versionId")
VersionId: ObjectVersionId

@httpHeader("x-amz-expected-bucket-owner")
ExpectedBucketOwner: AccountId
}

@output
structure DeleteObjectTaggingOutput {
@httpHeader("x-amz-version-id")
VersionId: ObjectVersionId
}

@error("client")
structure NoSuchBucket {}

Expand Down Expand Up @@ -462,3 +557,6 @@ enum BucketLocationConstraint {
@suppress(["EnumShape"])
us_west_2 = "us-west-2"
}

string ObjectVersionId

0 comments on commit 674628e

Please sign in to comment.