-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update protocol tests with datetime offset coverage (#1502)
* 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
1 parent
4928d71
commit 0b9d0e3
Showing
11 changed files
with
305 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
smithy-aws-protocol-tests/model/awsJson1_1/datetime-offsets.smithy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,8 @@ service JsonProtocol { | |
|
||
// custom endpoints with paths | ||
HostWithPathOperation, | ||
|
||
DatetimeOffsets, | ||
], | ||
} | ||
|
||
|
62 changes: 62 additions & 0 deletions
62
smithy-aws-protocol-tests/model/awsQuery/datetime-offsets.smithy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,5 +62,7 @@ service AwsQuery { | |
|
||
// custom endpoints with paths | ||
HostWithPathOperation, | ||
|
||
DatetimeOffsets, | ||
] | ||
} |
58 changes: 58 additions & 0 deletions
58
smithy-aws-protocol-tests/model/ec2Query/datetime-offsets.smithy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,5 +78,7 @@ service AwsEc2 { | |
|
||
// custom endpoints with paths | ||
HostWithPathOperation, | ||
|
||
DatetimeOffsets, | ||
] | ||
} |
55 changes: 55 additions & 0 deletions
55
smithy-aws-protocol-tests/model/restJson1/datetime-offsets.smithy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,5 +137,7 @@ service RestJson { | |
TestPayloadStructure, | ||
TestPayloadBlob, | ||
TestNoPayload, | ||
|
||
DatetimeOffsets, | ||
] | ||
} |
57 changes: 57 additions & 0 deletions
57
smithy-aws-protocol-tests/model/restXml/datetime-offsets.smithy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters