-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
assertions: coarseStringLike #29593
Comments
Hi @nag0yan thanks for the feature request. I think what you're trying to do can accomplished by capturing values, for example: import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { Capture } from 'aws-cdk-lib/assertions';
import { Template } from 'aws-cdk-lib/assertions';
export class AssertionCdkStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
let templateObject = {
"Resources": {
"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"
]
]
}
}
}
]
}
}
}
}
}
const template = Template.fromString(JSON.stringify(templateObject));
const principalCapture = new Capture();
template.hasResourceProperties('AWS::S3::BucketPolicy', {
PolicyDocument: {
Statement: [
{
Action: ['s3:GetObject'],
Effect: 'Allow',
Principal: principalCapture,
},
],
},
});
const capturedPrincipal = JSON.stringify(principalCapture.asObject());
console.log(capturedPrincipal.includes('some-user'));
if (!capturedPrincipal.includes('some-user')) {
throw new Error('Expected Principal to contain "some-user"');
}
}
} |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
Hello, @tim-finnigan. Thank you for replying. |
Describe the feature
Checking if some string is in specific property JSON string
For example,
To check this template, we can check as below.
Use Case
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
CDK version used
2.124.0
Environment details (OS name and version, etc.)
Windows WSL2
The text was updated successfully, but these errors were encountered: