Skip to content
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

test(s3): add test cases for buckets and kms keys #26191

Merged
merged 3 commits into from
Jul 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 59 additions & 3 deletions packages/aws-cdk-lib/aws-s3/test/bucket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ describe('bucket', () => {
'Resources': {
'MyBucketF68F3FF0': {
'Type': 'AWS::S3::Bucket',
'Properties': {
'BucketEncryption': {
'ServerSideEncryptionConfiguration': [
{
'ServerSideEncryptionByDefault': {
'SSEAlgorithm': 'AES256',
},
},
],
},
},
'DeletionPolicy': 'Retain',
'UpdateReplacePolicy': 'Retain',
},
Expand Down Expand Up @@ -340,6 +351,34 @@ describe('bucket', () => {
});
});

test('KMS key is generated if encryption is KMS and no encryptionKey is specified', () => {
const stack = new cdk.Stack();

new s3.Bucket(stack, 'MyBucket', { encryption: s3.BucketEncryption.KMS });

Template.fromStack(stack).hasResourceProperties('AWS::KMS::Key', {
'Description': 'Created by Default/MyBucket',
});

Template.fromStack(stack).hasResourceProperties('AWS::S3::Bucket', {
'BucketEncryption': {
'ServerSideEncryptionConfiguration': [
{
'ServerSideEncryptionByDefault': {
'KMSMasterKeyID': {
'Fn::GetAtt': [
'MyBucketKeyC17130CF',
'Arn',
],
},
'SSEAlgorithm': 'aws:kms',
},
},
],
},
});
});

test('enforceSsl can be enabled', () => {
const stack = new cdk.Stack();
new s3.Bucket(stack, 'MyBucket', { enforceSSL: true });
Expand Down Expand Up @@ -2651,10 +2690,27 @@ describe('bucket', () => {
test('if a kms key is specified, it implies bucket is encrypted with kms (dah)', () => {
// GIVEN
const stack = new cdk.Stack();
const key = new kms.Key(stack, 'k');

const key = new kms.Key(stack, 'MyKey');
// WHEN
new s3.Bucket(stack, 'MyBucket', { encryptionKey: key });
// THEN
new s3.Bucket(stack, 'b', { encryptionKey: key });
Template.fromStack(stack).hasResourceProperties('AWS::S3::Bucket', {
'BucketEncryption': {
'ServerSideEncryptionConfiguration': [
{
'ServerSideEncryptionByDefault': {
'KMSMasterKeyID': {
'Fn::GetAtt': [
'MyKey6AB29FA6',
'Arn',
],
},
'SSEAlgorithm': 'aws:kms',
},
},
],
},
});
});

test('Bucket with Server Access Logs', () => {
Expand Down
Loading