|
| 1 | +import * as iam from 'aws-cdk-lib/aws-iam'; |
| 2 | +import * as cdk from 'aws-cdk-lib'; |
| 3 | +import * as integ from '@aws-cdk/integ-tests-alpha'; |
| 4 | + |
| 5 | +/** |
| 6 | + * Integration test to verify that PolicyStatements with valid alphanumeric SIDs |
| 7 | + * can be successfully deployed to AWS. |
| 8 | + * |
| 9 | + * This test validates that the SID validation logic doesn't interfere with |
| 10 | + * actual CloudFormation deployment of valid PolicyStatements. |
| 11 | + */ |
| 12 | + |
| 13 | +const app = new cdk.App(); |
| 14 | +const stack = new cdk.Stack(app, 'PolicyStatementSidTest'); |
| 15 | + |
| 16 | +// Create a role with a policy that has valid alphanumeric SIDs |
| 17 | +const role = new iam.Role(stack, 'TestRole', { |
| 18 | + assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'), |
| 19 | + inlinePolicies: { |
| 20 | + TestPolicy: new iam.PolicyDocument({ |
| 21 | + statements: [ |
| 22 | + new iam.PolicyStatement({ |
| 23 | + sid: 'ValidSid123', |
| 24 | + effect: iam.Effect.ALLOW, |
| 25 | + actions: ['s3:GetObject'], |
| 26 | + resources: ['arn:aws:s3:::example-bucket/*'], |
| 27 | + }), |
| 28 | + new iam.PolicyStatement({ |
| 29 | + sid: 'ALLCAPS', |
| 30 | + effect: iam.Effect.ALLOW, |
| 31 | + actions: ['s3:ListBucket'], |
| 32 | + resources: ['arn:aws:s3:::example-bucket'], |
| 33 | + }), |
| 34 | + new iam.PolicyStatement({ |
| 35 | + sid: '123456', |
| 36 | + effect: iam.Effect.ALLOW, |
| 37 | + actions: ['logs:CreateLogGroup'], |
| 38 | + resources: ['*'], |
| 39 | + }), |
| 40 | + new iam.PolicyStatement({ |
| 41 | + sid: 'abc123DEF', |
| 42 | + effect: iam.Effect.ALLOW, |
| 43 | + actions: ['logs:CreateLogStream'], |
| 44 | + resources: ['*'], |
| 45 | + }), |
| 46 | + // Test statement without SID (should still work) |
| 47 | + new iam.PolicyStatement({ |
| 48 | + effect: iam.Effect.ALLOW, |
| 49 | + actions: ['logs:PutLogEvents'], |
| 50 | + resources: ['*'], |
| 51 | + }), |
| 52 | + ], |
| 53 | + }), |
| 54 | + }, |
| 55 | +}); |
| 56 | + |
| 57 | +// Create a managed policy with valid SIDs |
| 58 | +new iam.ManagedPolicy(stack, 'TestManagedPolicy', { |
| 59 | + statements: [ |
| 60 | + new iam.PolicyStatement({ |
| 61 | + sid: 'ManagedPolicySid1', |
| 62 | + effect: iam.Effect.ALLOW, |
| 63 | + actions: ['dynamodb:GetItem'], |
| 64 | + resources: ['*'], |
| 65 | + }), |
| 66 | + ], |
| 67 | +}); |
| 68 | + |
| 69 | +new integ.IntegTest(app, 'PolicyStatementSidIntegTest', { |
| 70 | + testCases: [stack], |
| 71 | +}); |
0 commit comments