Open
Description
Describe the feature
Checking if some string is in specific property JSON string
For example,
BucketPolicy01:
Type: AWS::S3::BucketPolicy
Properties:
Bucket:
Ref: Bucket01
PolicyDocument:
Statement:
- Action:
- s3:GetObject
Effect: Allow
Principal:
AWS:
Fn::Join:
- ""
- - "arn:"
- Ref: AWS::Partition
- :iam::${account-id}:user/some-user
...
To check this template, we can check as below.
template.hasResourceProperties("AWS::S3::BucketPolicy", {
PolicyDocument: {
Statement: [
{
Action: ["s3:GetObject"],
Effect: "Allow",
Principal: Match.coarseStringLike("some-user") // new method
},
],
},
});
Use Case
const principal = new Capture();
template.hasResourceProperties("AWS::S3::BucketPolicy", {
PolicyDocument: {
Statement: [
{
Action: ["s3:GetObject"],
Effect: "Allow",
Principal: principal,
},
],
},
});
expect(JSON.stringify(principal.asObject())).toMatch(
"some-user",
);
For many cases, it may be useful to check only partial string in JSON string.
Proposed Solution
I don't dived into assertions module yet, so I don't know this solution is feasible.
However, json utility tools( such as, JSON.stringify, json.dumps, json.Marshal ... ) would be helpful, I thought.
Other Information
No response
Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
CDK version used
2.124.0
Environment details (OS name and version, etc.)
Windows WSL2