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

Update protocol tests with datetime offset coverage #1502

Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions docs/source-2.0/spec/protocol-traits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ Smithy defines the following built-in timestamp formats:
:rfc:`3339#section-5.6`
with no UTC offset and optional fractional precision (for example,
``1985-04-12T23:20:50.52Z``).
*However*, offsets will still be parsed gracefully, but the datetime
will be normalized to an offset of zero (i.e. converted to UTC)
* - http-date
- An HTTP date as defined by the ``IMF-fixdate`` production in
:rfc:`7231#section-7.1.1.1` (for example,
Expand Down
118 changes: 118 additions & 0 deletions smithy-aws-protocol-tests/model/awsJson1_1/datetime-offsets.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
$version: "2.0"

namespace aws.protocoltests.json

use aws.protocols#awsJson1_1
use aws.protocoltests.shared#DateTime
use smithy.test#httpRequestTests
use smithy.test#httpResponseTests

// These tests are for verifying the client can correctly parse
// the `DateTime` timestamp with an offset
@tags(["client-only"])
@http(uri: "/DatetimeOffsets", method: "POST")
operation DatetimeOffsets {
output: DatetimeOffsetsOutput
}

apply DatetimeOffsets @httpResponseTests([
{
id: "AwsJson11DateTimeWithNegativeOffset",
documentation: """
Ensures that clients can correctly parse datetime (timestamps) with offsets""",
protocol: awsJson1_1,
code: 200,
body:
"""
{
"datetime": "2019-12-16T22:48:18-01:00"
}
""",
params: { datetime: 1576540098 }
bodyMediaType: "application/json",
headers: {
"Content-Type": "application/x-amz-json-1.1"
},
appliesTo: "client"
},
{
id: "AwsJson11DateTimeWithPositiveOffset",
documentation: """
Ensures that clients can correctly parse datetime (timestamps) with offsets""",
protocol: awsJson1_1,
code: 200,
body:
"""
{
"datetime": "2019-12-17T00:48:18+01:00"
}
""",
params: { datetime: 1576540098 }
bodyMediaType: "application/json",
headers: {
"Content-Type": "application/x-amz-json-1.1"
},
appliesTo: "client"
},
])

structure DatetimeOffsetsOutput {
datetime: DateTime
}

// These tests are for verifying the server can correctly parse
// the `DateTime` timestamp with an offset
@tags(["server-only"])
@http(uri: "/OffsetDatetimes", method: "POST")
operation OffsetDatetimes {
input: OffsetDatetimesInput
}

apply OffsetDatetimes @httpRequestTests([
{
id: "AwsJson11NegativeOffsetDatetimes",
documentation: """
Ensures that servers can correctly parse datetime (timestamps) with offsets""",
protocol: awsJson1_1,
method: "POST",
uri: "/",
body:
"""
{
"datetime": "2019-12-16T22:48:18-01:00"
}
""",
params: { datetime: 1576540098 }
bodyMediaType: "application/json",
headers: {
"Content-Type": "application/x-amz-json-1.1",
"X-Amz-Target": "JsonProtocol.OffsetDatetimes",
},
appliesTo: "server"
},
{
id: "AwsJson11PositiveOffsetDatetimes",
documentation: """
Ensures that servers can correctly parse datetime (timestamps) with offsets""",
protocol: awsJson1_1,
method: "POST",
uri: "/",
body:
"""
{
"datetime": "2019-12-17T00:48:18+01:00"
}
""",
params: { datetime: 1576540098 }
bodyMediaType: "application/json",
headers: {
"Content-Type": "application/x-amz-json-1.1",
"X-Amz-Target": "JsonProtocol.OffsetDatetimes",
},
appliesTo: "server"
}
])

structure OffsetDatetimesInput {
datetime: DateTime
}
3 changes: 3 additions & 0 deletions smithy-aws-protocol-tests/model/awsJson1_1/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ service JsonProtocol {

// custom endpoints with paths
HostWithPathOperation,

DatetimeOffsets,
OffsetDatetimes
],
}

Expand Down
114 changes: 114 additions & 0 deletions smithy-aws-protocol-tests/model/awsQuery/datetime-offsets.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
$version: "2.0"

namespace aws.protocoltests.query

use aws.protocols#awsQuery
use aws.protocoltests.shared#DateTime
use smithy.test#httpRequestTests
use smithy.test#httpResponseTests

// These tests are for verifying the client can correctly parse
// the `DateTime` timestamp with an offset
@tags(["client-only"])
operation DatetimeOffsets {
output: DatetimeOffsetsOutput
}

apply DatetimeOffsets @httpResponseTests([
{
id: "AwsQueryDateTimeWithNegativeOffset",
documentation: """
Ensures that clients can correctly parse datetime (timestamps) with offsets""",
protocol: awsQuery,
code: 200,
body: """
<DatetimeOffsetsResponse xmlns="https://example.com/">
<DatetimeOffsetsResult>
<datetime>2019-12-16T22:48:18-01:00</datetime>
</DatetimeOffsetsResult>
</DatetimeOffsetsResponse>
""",
params: { datetime: 1576540098 }
bodyMediaType: "application/xml",
headers: {
"Content-Type": "text/xml"
},
appliesTo: "client"
},
{
id: "AwsQueryDateTimeWithPositiveOffset",
documentation: """
Ensures that clients can correctly parse datetime (timestamps) with offsets""",
protocol: awsQuery,
code: 200,
body: """
<DatetimeOffsetsResponse xmlns="https://example.com/">
<DatetimeOffsetsResult>
<datetime>2019-12-17T00:48:18+01:00</datetime>
</DatetimeOffsetsResult>
</DatetimeOffsetsResponse>
""",
params: { datetime: 1576540098 }
bodyMediaType: "application/xml",
headers: {
"Content-Type": "text/xml"
},
appliesTo: "client"
},
])

structure DatetimeOffsetsOutput {
datetime: DateTime
}

// These tests are for verifying the server can correctly parse
// the `DateTime` timestamp with an offset
@tags(["server-only"])
operation OffsetDatetimes {
input: OffsetDatetimesInput
}

apply OffsetDatetimes @httpRequestTests([
{
id: "AwsQueryNegativeOffsetDatetimes",
documentation: """
Ensures that servers can correctly parse datetime (timestamps) with offsets""",
protocol: awsQuery,
method: "POST",
uri: "/",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
requireHeaders: [
"Content-Length"
],
body: "Action=OffsetDatetimes&Version=2020-01-08&datetime=2019-12-16T22%3A48%3A18-01%3A00",
bodyMediaType: "application/x-www-form-urlencoded",
params: {
datetime: 1576540098,
}
},
{
id: "AwsQueryPositiveOffsetDatetimes",
documentation: """
Ensures that servers can correctly parse datetime (timestamps) with offsets""",
protocol: awsQuery,
method: "POST",
uri: "/",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
requireHeaders: [
"Content-Length"
],
body: "Action=OffsetDatetimes&Version=2020-01-08&datetime=2019-12-17T00%3A48%3A18%2B01%3A00",
bodyMediaType: "application/x-www-form-urlencoded",
params: {
datetime: 1576540098,
}
},
])

structure OffsetDatetimesInput {
datetime: DateTime
}
3 changes: 3 additions & 0 deletions smithy-aws-protocol-tests/model/awsQuery/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,8 @@ service AwsQuery {

// custom endpoints with paths
HostWithPathOperation,

DatetimeOffsets,
OffsetDatetimes,
]
}
110 changes: 110 additions & 0 deletions smithy-aws-protocol-tests/model/ec2Query/datetime-offsets.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
$version: "2.0"

namespace aws.protocoltests.ec2

use aws.protocols#ec2Query
use aws.protocoltests.shared#DateTime
use smithy.test#httpRequestTests
use smithy.test#httpResponseTests

// These tests are for verifying the client can correctly parse
// the `DateTime` timestamp with an offset
@tags(["client-only"])
operation DatetimeOffsets {
output: DatetimeOffsetsOutput
}

apply DatetimeOffsets @httpResponseTests([
{
id: "Ec2QueryDateTimeWithNegativeOffset",
documentation: """
Ensures that clients can correctly parse datetime (timestamps) with offsets""",
protocol: ec2Query,
code: 200,
body: """
<DatetimeOffsetsResponse xmlns="https://example.com/">
<datetime>2019-12-16T22:48:18-01:00</datetime>
<RequestId>requestid</RequestId>
</DatetimeOffsetsResponse>
""",
bodyMediaType: "application/xml",
headers: {
"Content-Type": "text/xml;charset=UTF-8"
},
params: { datetime: 1576540098 }
},
{
id: "Ec2QueryDateTimeWithPositiveOffset",
documentation: """
Ensures that clients can correctly parse datetime (timestamps) with offsets""",
protocol: ec2Query,
code: 200,
body: """
<DatetimeOffsetsResponse xmlns="https://example.com/">
<datetime>2019-12-17T00:48:18+01:00</datetime>
<RequestId>requestid</RequestId>
</DatetimeOffsetsResponse>
""",
bodyMediaType: "application/xml",
headers: {
"Content-Type": "text/xml;charset=UTF-8"
},
params: { datetime: 1576540098 }
}
])

structure DatetimeOffsetsOutput {
datetime: DateTime
}

// These tests are for verifying the server can correctly parse
// the `DateTime` timestamp with an offset
@tags(["server-only"])
operation OffsetDatetimes {
input: OffsetDatetimesInput
}

apply OffsetDatetimes @httpRequestTests([
{
id: "Ec2QueryNegativeOffsetDatetimes",
documentation: """
Ensures that servers can correctly parse datetime (timestamps) with offsets""",
protocol: ec2Query,
method: "POST",
uri: "/",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
requireHeaders: [
"Content-Length"
],
body: "Action=OffsetDatetimes&Version=2020-01-08&Datetime=2019-12-16T22%3A48%3A18-01%3A00",
bodyMediaType: "application/x-www-form-urlencoded",
params: {
datetime: 1576540098,
}
},
{
id: "Ec2QueryPositiveOffsetDatetimes",
documentation: """
Ensures that servers can correctly parse datetime (timestamps) with offsets""",
protocol: ec2Query,
method: "POST",
uri: "/",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
requireHeaders: [
"Content-Length"
],
body: "Action=OffsetDatetimes&Version=2020-01-08&Datetime=2019-12-17T00%3A48%3A18%2B01%3A00",
bodyMediaType: "application/x-www-form-urlencoded",
params: {
datetime: 1576540098,
}
},
])

structure OffsetDatetimesInput {
datetime: DateTime
}
3 changes: 3 additions & 0 deletions smithy-aws-protocol-tests/model/ec2Query/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,8 @@ service AwsEc2 {

// custom endpoints with paths
HostWithPathOperation,

DatetimeOffsets,
OffsetDatetimes,
]
}
Loading