-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dontet): iso-8601 date strings get turned into DateTime (#2058)
When a ISO-8601-encoded date is passed from JavaScript to the .NET app, the JSON deserializer would interpret that as a `DateTime` instead of passing the string un-touched. This is a problem, since the jsii kernel protocol has a dedicated wrapper key for DateTime values (`$jsii$date`). This PR adds a compliance test around this particular scenario, and disabled `DateTime` handling from the standard deserializer (the wrapped values are still processed correctly). > This PR also changes the way the .NET test package generates the > tested libraries (`jsii-calc` & dependencies) so that instead of > generating NuGet packages, it only generates C# projects. This makes > the experience of debugging the tests **much** nicer, and reduces the > likelihood of cached build artifacts getting in the way. Fixes aws/aws-cdk#10513
- Loading branch information
1 parent
891b011
commit 52d7382
Showing
17 changed files
with
838 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
test="./test" | ||
genRoot="${test}/generated" | ||
|
||
# Generate NuGet packages for jsii-calc and its dependencies. | ||
jsii-pacmak -t dotnet --recurse -o ${test}/generated ../../jsii-calc | ||
# Clean up before we start working | ||
rm -rf ${genRoot} | ||
|
||
# Generate .NET projects for jsii-calc and its dependencies. | ||
jsii-pacmak -t dotnet --code-only --recurse -o ${genRoot} ../../jsii-calc | ||
|
||
# Hack around project references to de-duplicate Amazon.JSII.Runtime in generated code. | ||
for csproj in ${genRoot}/dotnet/*/*.csproj | ||
do | ||
dotnet remove ${csproj} package Amazon.JSII.Runtime | ||
dotnet add ${csproj} reference ../dotnet-runtime/src/Amazon.JSII.Runtime/Amazon.JSII.Runtime.csproj | ||
done | ||
|
||
# Generate Directory.Build.props | ||
/usr/bin/env node ./Directory.Build.props.t.js > ${test}/Directory.Build.props |
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
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
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
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
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
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
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
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 @@ | ||
/** | ||
* This class is used to validate that serialization and deserialization does | ||
* not interpret ISO-8601-formatted timestampts to the native date/time object, | ||
* as the jsii protocol has a $jsii$date wrapper for this purpose (node's JSON | ||
* parsing does *NOT* detect dates automatically in this way, so host libraries | ||
* should not either). | ||
*/ | ||
export abstract class Entropy { | ||
/** | ||
* Creates a new instance of Entropy. | ||
* | ||
* @param clock your implementation of `WallClock` | ||
*/ | ||
public constructor(private readonly clock: IWallClock) {} | ||
|
||
/** | ||
* Increases entropy by consuming time from the clock (yes, this is a long | ||
* shot, please don't judge). | ||
* | ||
* @returns the time from the `WallClock`. | ||
*/ | ||
public increase(): string { | ||
const now = this.clock.iso8601Now(); | ||
|
||
if (typeof now !== 'string') { | ||
throw new Error( | ||
`Now should have been a string, is a ${typeof now}. Check your (de)serializer`, | ||
); | ||
} | ||
|
||
const result = this.repeat(now); | ||
|
||
if (typeof result !== 'string') { | ||
throw new Error( | ||
`Repeat should return a string, but returned a ${typeof result}. Check your (de)serializer`, | ||
); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Implement this method such that it returns `word`. | ||
* @param word the value to return. | ||
* @returns `word`. | ||
*/ | ||
public abstract repeat(word: string): string; | ||
} | ||
|
||
/** | ||
* Implement this interface. | ||
*/ | ||
export interface IWallClock { | ||
/** | ||
* Returns the current time, formatted as an ISO-8601 string. | ||
*/ | ||
iso8601Now(): string; | ||
} |
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
Oops, something went wrong.