Skip to content

Commit

Permalink
Update protocol tests with datetime offset coverage (#1502)
Browse files Browse the repository at this point in the history
* Clarify offsets behavior for timestampFormat and add test coverage

While the datetime specification mentions that UTC offsets are not allowed,
they should still be parsed gracefully and normalized to zero (no offset).
These changes add tests to verify the correct serialization/deserialization
behavior of client protocol implementations. Servers protocol implementations
are not expected to handle datetimes with offsets.
  • Loading branch information
haydenbaker authored Dec 21, 2022
1 parent 4928d71 commit 0b9d0e3
Show file tree
Hide file tree
Showing 11 changed files with 305 additions and 0 deletions.
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
61 changes: 61 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,61 @@
$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
}
2 changes: 2 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,8 @@ service JsonProtocol {

// custom endpoints with paths
HostWithPathOperation,

DatetimeOffsets,
],
}

Expand Down
62 changes: 62 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,62 @@
$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
}
2 changes: 2 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,7 @@ service AwsQuery {

// custom endpoints with paths
HostWithPathOperation,

DatetimeOffsets,
]
}
58 changes: 58 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,58 @@
$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
}
2 changes: 2 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,7 @@ service AwsEc2 {

// custom endpoints with paths
HostWithPathOperation,

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

namespace aws.protocoltests.restjson

use aws.protocols#restJson1
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: "RestJsonDateTimeWithNegativeOffset",
documentation: """
Ensures that clients can correctly parse datetime (timestamps) with offsets""",
protocol: restJson1,
code: 200,
body:
"""
{
"datetime": "2019-12-16T22:48:18-01:00"
}
""",
params: { datetime: 1576540098 }
bodyMediaType: "application/json",
appliesTo: "client"
},
{
id: "RestJsonDateTimeWithPositiveOffset",
documentation: """
Ensures that clients can correctly parse datetime (timestamps) with offsets""",
protocol: restJson1,
code: 200,
body:
"""
{
"datetime": "2019-12-17T00:48:18+01:00"
}
""",
params: { datetime: 1576540098 }
bodyMediaType: "application/json",
appliesTo: "client"
},
])

structure DatetimeOffsetsOutput {
datetime: DateTime
}
2 changes: 2 additions & 0 deletions smithy-aws-protocol-tests/model/restJson1/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,7 @@ service RestJson {
TestPayloadStructure,
TestPayloadBlob,
TestNoPayload,

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

namespace aws.protocoltests.restxml

use aws.protocols#restXml
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: "RestXmlDateTimeWithNegativeOffset",
documentation: """
Ensures that clients can correctly parse datetime (timestamps) with offsets""",
protocol: restXml,
code: 200,
body: """
<DateTime>
<datetime>2019-12-16T22:48:18-01:00</datetime>
</DateTime>
""",
bodyMediaType: "application/xml",
headers: {
"Content-Type": "application/xml"
},
params: { datetime: 1576540098 }
},
{
id: "RestXmlDateTimeWithPositiveOffset",
documentation: """
Ensures that clients can correctly parse datetime (timestamps) with offsets""",
protocol: restXml,
code: 200,
body: """
<DateTime>
<datetime>2019-12-17T00:48:18+01:00</datetime>
</DateTime>
""",
bodyMediaType: "application/xml",
headers: {
"Content-Type": "application/xml"
},
params: { datetime: 1576540098 }
},
])

structure DatetimeOffsetsOutput {
datetime: DateTime
}
2 changes: 2 additions & 0 deletions smithy-aws-protocol-tests/model/restXml/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,7 @@ service RestXml {
EndpointOperation,
EndpointWithHostLabelOperation,
EndpointWithHostLabelHeaderOperation,

DatetimeOffsets,
]
}

0 comments on commit 0b9d0e3

Please sign in to comment.