-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from aws4embeddedlinux/cdk-nag-tests
Add cdk-nag tests.
- Loading branch information
Showing
12 changed files
with
488 additions
and
1 deletion.
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,76 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import { BuildImageDataStack } from '../lib/build-image-data'; | ||
|
||
import { Annotations, Match } from 'aws-cdk-lib/assertions'; | ||
import { App, Aspects, Stack } from 'aws-cdk-lib'; | ||
import { AwsSolutionsChecks, NagSuppressions } from 'cdk-nag'; | ||
|
||
describe('BuildImageDataStack cdk-nag AwsSolutions Pack', () => { | ||
let stack: Stack; | ||
let app: App; | ||
|
||
beforeAll(() => { | ||
// GIVEN | ||
app = new App(); | ||
const props = { | ||
bucketName: 'test-bucket', | ||
removalPolicy: cdk.RemovalPolicy.DESTROY, | ||
autoDeleteObjects: true, | ||
env: { account: '111111111111', region: 'eu-central-1' }, | ||
}; | ||
stack = new BuildImageDataStack(app, 'MyTestStack', props); | ||
|
||
NagSuppressions.addStackSuppressions(stack, [ | ||
{ | ||
id: 'AwsSolutions-IAM4', | ||
reason: 'TODO: Re-evaluate managed policies per resources.', | ||
}, | ||
{ | ||
id: 'AwsSolutions-IAM5', | ||
reason: 'TODO: Re-evaluate "*" per resources.', | ||
}, | ||
]); | ||
|
||
NagSuppressions.addResourceSuppressionsByPath( | ||
stack, | ||
'/MyTestStack/Custom::CDKBucketDeployment8693BB64968944B69AAFB0CC9EB8756C/Resource', | ||
[ | ||
{ | ||
id: 'AwsSolutions-L1', | ||
reason: 'This Lambda function is 3rd Party (from CDK libs)', | ||
}, | ||
] | ||
); | ||
|
||
NagSuppressions.addResourceSuppressionsByPath( | ||
stack, | ||
'/MyTestStack/BuildImageDataBucket/Resource', | ||
[ | ||
{ | ||
id: 'AwsSolutions-S1', | ||
reason: 'TODO: Add Access Logging', | ||
}, | ||
] | ||
); | ||
|
||
// WHEN | ||
Aspects.of(stack).add(new AwsSolutionsChecks({ verbose: true })); | ||
}); | ||
|
||
// THEN | ||
test('No unsuppressed Warnings', () => { | ||
const warnings = Annotations.fromStack(stack).findWarning( | ||
'*', | ||
Match.stringLikeRegexp('AwsSolutions-.*') | ||
); | ||
expect(warnings).toHaveLength(0); | ||
}); | ||
|
||
test('No unsuppressed Errors', () => { | ||
const errors = Annotations.fromStack(stack).findError( | ||
'*', | ||
Match.stringLikeRegexp('AwsSolutions-.*') | ||
); | ||
expect(errors).toHaveLength(0); | ||
}); | ||
}); |
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,73 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import { | ||
BuildImagePipelineStack, | ||
ImageKind, | ||
} from '../lib/build-image-pipeline'; | ||
import { Repository } from 'aws-cdk-lib/aws-ecr'; | ||
import { Bucket } from 'aws-cdk-lib/aws-s3'; | ||
|
||
import { Annotations, Match } from 'aws-cdk-lib/assertions'; | ||
import { App, Aspects, Stack } from 'aws-cdk-lib'; | ||
import { AwsSolutionsChecks, NagSuppressions } from 'cdk-nag'; | ||
|
||
describe('BuildImagePipelineStack cdk-nag AwsSolutions Pack', () => { | ||
let stack: Stack; | ||
let app: App; | ||
|
||
beforeAll(() => { | ||
// GIVEN | ||
const env = { account: '111111111111', region: 'eu-central-1' }; | ||
app = new cdk.App(); | ||
const repoStack = new cdk.Stack(app, 'RepoStack', { env }); | ||
const repository = new Repository(repoStack, 'Repository', {}); | ||
const dataBucket = new Bucket(repoStack, 'Bucket', {}); | ||
|
||
const props = { | ||
env, | ||
imageKind: ImageKind.Ubuntu22_04, | ||
repository, | ||
dataBucket, | ||
}; | ||
|
||
stack = new BuildImagePipelineStack(repoStack, 'MyTestStack', props); | ||
NagSuppressions.addStackSuppressions(stack, [ | ||
{ | ||
id: 'AwsSolutions-CB3', | ||
reason: 'Privilege Mode Required To Build Docker Containers.', | ||
}, | ||
{ | ||
id: 'AwsSolutions-IAM5', | ||
reason: 'TODO: Re-evaluate "*" per resources.', | ||
}, | ||
{ | ||
id: 'AwsSolutions-S1', | ||
reason: 'TODO: Re-evaluate bucket access logging.', | ||
}, | ||
{ | ||
id: 'AwsSolutions-KMS5', | ||
reason: 'TODO: Re-evaluate key rotation.', | ||
}, | ||
]); | ||
// WHEN | ||
Aspects.of(stack).add(new AwsSolutionsChecks({ verbose: true })); | ||
}); | ||
|
||
// THEN | ||
test('No unsuppressed Warnings', () => { | ||
const warnings = Annotations.fromStack(stack).findWarning( | ||
'*', | ||
Match.stringLikeRegexp('AwsSolutions-.*') | ||
); | ||
|
||
expect(warnings).toHaveLength(0); | ||
}); | ||
|
||
test('No unsuppressed Errors', () => { | ||
const errors = Annotations.fromStack(stack).findError( | ||
'*', | ||
Match.stringLikeRegexp('AwsSolutions-.*') | ||
); | ||
|
||
expect(errors).toHaveLength(0); | ||
}); | ||
}); |
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,36 @@ | ||
import { BuildImageRepoStack } from '../lib/build-image-repo'; | ||
import { Annotations, Match } from 'aws-cdk-lib/assertions'; | ||
import { App, Aspects, Stack } from 'aws-cdk-lib'; | ||
import { AwsSolutionsChecks } from 'cdk-nag'; | ||
|
||
describe('Build Image Repository cdk-nag AwsSolutions Pack', () => { | ||
const props = { | ||
env: { account: '111111111111', region: 'eu-central-1' }, | ||
}; | ||
let stack: Stack; | ||
let app: App; | ||
|
||
beforeAll(() => { | ||
// GIVEN | ||
app = new App(); | ||
stack = new BuildImageRepoStack(app, 'MyTestStack', props); | ||
// WHEN | ||
Aspects.of(stack).add(new AwsSolutionsChecks({ verbose: true })); | ||
}); | ||
// THEN | ||
test('No unsuppressed Warnings', () => { | ||
const warnings = Annotations.fromStack(stack).findWarning( | ||
'*', | ||
Match.stringLikeRegexp('AwsSolutions-.*') | ||
); | ||
expect(warnings).toHaveLength(0); | ||
}); | ||
|
||
test('No unsuppressed Errors', () => { | ||
const errors = Annotations.fromStack(stack).findError( | ||
'*', | ||
Match.stringLikeRegexp('AwsSolutions-.*') | ||
); | ||
expect(errors).toHaveLength(0); | ||
}); | ||
}); |
Oops, something went wrong.