Skip to content

Commit 30ac0cc

Browse files
authored
fix(s3): enforce that fromBucketAttributes supplies a valid bucket name (#16915)
---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 5333c72 commit 30ac0cc

File tree

13 files changed

+108
-94
lines changed

13 files changed

+108
-94
lines changed

packages/@aws-cdk/aws-apigateway/test/domains.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ describe('domains', () => {
388388

389389
test('accepts a mutual TLS configuration', () => {
390390
const stack = new Stack();
391-
const bucket = Bucket.fromBucketName(stack, 'testBucket', 'exampleBucket');
391+
const bucket = Bucket.fromBucketName(stack, 'testBucket', 'example-bucket');
392392
new apigw.DomainName(stack, 'another-domain', {
393393
domainName: 'example.com',
394394
mtls: {
@@ -402,14 +402,14 @@ describe('domains', () => {
402402
'DomainName': 'example.com',
403403
'EndpointConfiguration': { 'Types': ['REGIONAL'] },
404404
'RegionalCertificateArn': 'arn:aws:acm:us-east-1:1111111:certificate/11-3336f1-44483d-adc7-9cd375c5169d',
405-
'MutualTlsAuthentication': { 'TruststoreUri': 's3://exampleBucket/someca.pem' },
405+
'MutualTlsAuthentication': { 'TruststoreUri': 's3://example-bucket/someca.pem' },
406406
});
407407

408408
});
409409

410410
test('mTLS should allow versions to be set on the s3 bucket', () => {
411411
const stack = new Stack();
412-
const bucket = Bucket.fromBucketName(stack, 'testBucket', 'exampleBucket');
412+
const bucket = Bucket.fromBucketName(stack, 'testBucket', 'example-bucket');
413413
new apigw.DomainName(stack, 'another-domain', {
414414
domainName: 'example.com',
415415
certificate: acm.Certificate.fromCertificateArn(stack, 'cert2', 'arn:aws:acm:us-east-1:1111111:certificate/11-3336f1-44483d-adc7-9cd375c5169d'),
@@ -423,7 +423,7 @@ describe('domains', () => {
423423
'DomainName': 'example.com',
424424
'EndpointConfiguration': { 'Types': ['REGIONAL'] },
425425
'RegionalCertificateArn': 'arn:aws:acm:us-east-1:1111111:certificate/11-3336f1-44483d-adc7-9cd375c5169d',
426-
'MutualTlsAuthentication': { 'TruststoreUri': 's3://exampleBucket/someca.pem', 'TruststoreVersion': 'version' },
426+
'MutualTlsAuthentication': { 'TruststoreUri': 's3://example-bucket/someca.pem', 'TruststoreVersion': 'version' },
427427
});
428428
});
429429

packages/@aws-cdk/aws-cloudtrail/test/cloudtrail.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ describe('cloudtrail', () => {
131131
test('with imported s3 bucket', () => {
132132
// GIVEN
133133
const stack = getTestStack();
134-
const bucket = s3.Bucket.fromBucketName(stack, 'S3', 'SomeBucket');
134+
const bucket = s3.Bucket.fromBucketName(stack, 'S3', 'somebucket');
135135

136136
// WHEN
137137
new Trail(stack, 'Trail', { bucket });
138138

139139
expect(stack).toHaveResource('AWS::CloudTrail::Trail', {
140-
S3BucketName: 'SomeBucket',
140+
S3BucketName: 'somebucket',
141141
});
142142
});
143143

packages/@aws-cdk/aws-codebuild/test/project.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ describe('Environment', () => {
673673
test('logs config - s3', () => {
674674
// GIVEN
675675
const stack = new cdk.Stack();
676-
const bucket = s3.Bucket.fromBucketName(stack, 'LogBucket', 'MyBucketName');
676+
const bucket = s3.Bucket.fromBucketName(stack, 'LogBucket', 'mybucketname');
677677

678678
// WHEN
679679
new codebuild.Project(stack, 'Project', {
@@ -693,7 +693,7 @@ describe('Environment', () => {
693693
expect(stack).toHaveResourceLike('AWS::CodeBuild::Project', {
694694
LogsConfig: objectLike({
695695
S3Logs: {
696-
Location: 'MyBucketName/my-logs',
696+
Location: 'mybucketname/my-logs',
697697
Status: 'ENABLED',
698698
},
699699
}),
@@ -703,7 +703,7 @@ describe('Environment', () => {
703703
test('logs config - cloudWatch and s3', () => {
704704
// GIVEN
705705
const stack = new cdk.Stack();
706-
const bucket = s3.Bucket.fromBucketName(stack, 'LogBucket2', 'MyBucketName');
706+
const bucket = s3.Bucket.fromBucketName(stack, 'LogBucket2', 'mybucketname');
707707
const logGroup = logs.LogGroup.fromLogGroupName(stack, 'LogGroup2', 'MyLogGroupName');
708708

709709
// WHEN
@@ -730,7 +730,7 @@ describe('Environment', () => {
730730
Status: 'ENABLED',
731731
},
732732
S3Logs: {
733-
Location: 'MyBucketName',
733+
Location: 'mybucketname',
734734
Status: 'ENABLED',
735735
},
736736
}),

packages/@aws-cdk/aws-ec2/test/cfn-init-element.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,15 +664,15 @@ describe('InitSource', () => {
664664

665665
test('fromS3Object uses object URL', () => {
666666
// GIVEN
667-
const bucket = s3.Bucket.fromBucketName(stack, 'bucket', 'MyBucket');
667+
const bucket = s3.Bucket.fromBucketName(stack, 'bucket', 'mybucket');
668668
const source = ec2.InitSource.fromS3Object('/tmp/foo', bucket, 'myKey');
669669

670670
// WHEN
671671
const rendered = getElementConfig(source, InitPlatform.LINUX);
672672

673673
// THEN
674674
expect(rendered).toEqual({
675-
'/tmp/foo': expect.stringContaining('/MyBucket/myKey'),
675+
'/tmp/foo': expect.stringContaining('/mybucket/myKey'),
676676
});
677677
});
678678

packages/@aws-cdk/aws-ec2/test/cfn-init.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ class SingletonLocationSythesizer extends DefaultStackSynthesizer {
667667
public addFileAsset(_asset: FileAssetSource): FileAssetLocation {
668668
const httpUrl = 'https://MyBucket.s3.amazonaws.com/MyAsset';
669669
return {
670-
bucketName: 'MyAssetBucket',
670+
bucketName: 'myassetbucket',
671671
objectKey: 'MyAssetFile',
672672
httpUrl,
673673
s3ObjectUrl: httpUrl,

packages/@aws-cdk/aws-glue/test/code.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('Code', () => {
1717
let bucket: s3.IBucket;
1818

1919
test('with valid bucket name and key and bound by job sets the right path and grants the job permissions to read from it', () => {
20-
bucket = s3.Bucket.fromBucketName(stack, 'Bucket', 'bucketName');
20+
bucket = s3.Bucket.fromBucketName(stack, 'Bucket', 'bucketname');
2121
script = glue.Code.fromBucket(bucket, key);
2222
new glue.Job(stack, 'Job1', {
2323
executable: glue.JobExecutable.pythonShell({
@@ -29,7 +29,7 @@ describe('Code', () => {
2929

3030
Template.fromStack(stack).hasResourceProperties('AWS::Glue::Job', {
3131
Command: {
32-
ScriptLocation: 's3://bucketName/script',
32+
ScriptLocation: 's3://bucketname/script',
3333
},
3434
});
3535

@@ -53,7 +53,7 @@ describe('Code', () => {
5353
{
5454
Ref: 'AWS::Partition',
5555
},
56-
':s3:::bucketName',
56+
':s3:::bucketname',
5757
],
5858
],
5959
},
@@ -65,7 +65,7 @@ describe('Code', () => {
6565
{
6666
Ref: 'AWS::Partition',
6767
},
68-
':s3:::bucketName/script',
68+
':s3:::bucketname/script',
6969
],
7070
],
7171
},

packages/@aws-cdk/aws-glue/test/job-executable.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('JobExecutable', () => {
3131

3232
beforeEach(() => {
3333
stack = new cdk.Stack();
34-
bucket = s3.Bucket.fromBucketName(stack, 'Bucket', 'bucketName');
34+
bucket = s3.Bucket.fromBucketName(stack, 'Bucket', 'bucketname');
3535
script = glue.Code.fromBucket(bucket, 'script.py');
3636
});
3737

packages/@aws-cdk/aws-glue/test/job.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('Job', () => {
5555

5656
describe('new', () => {
5757
const className = 'com.amazon.test.ClassName';
58-
const codeBucketName = 'bucketName';
58+
const codeBucketName = 'bucketname';
5959
const codeBucketAccessStatement = {
6060
Action: [
6161
's3:GetObject*',
@@ -166,7 +166,7 @@ describe('Job', () => {
166166
Template.fromStack(stack).hasResourceProperties('AWS::Glue::Job', {
167167
Command: {
168168
Name: 'glueetl',
169-
ScriptLocation: 's3://bucketName/script',
169+
ScriptLocation: 's3://bucketname/script',
170170
},
171171
Role: {
172172
'Fn::GetAtt': [
@@ -383,7 +383,7 @@ describe('Job', () => {
383383
});
384384

385385
describe('with bucket provided', () => {
386-
const sparkUIBucketName = 'sparkBucketName';
386+
const sparkUIBucketName = 'sparkbucketname';
387387
let sparkUIBucket: s3.IBucket;
388388

389389
beforeEach(() => {
@@ -420,7 +420,7 @@ describe('Job', () => {
420420
{
421421
Ref: 'AWS::Partition',
422422
},
423-
':s3:::sparkBucketName',
423+
':s3:::sparkbucketname',
424424
],
425425
],
426426
},
@@ -432,7 +432,7 @@ describe('Job', () => {
432432
{
433433
Ref: 'AWS::Partition',
434434
},
435-
':s3:::sparkBucketName/*',
435+
':s3:::sparkbucketname/*',
436436
],
437437
],
438438
},
@@ -460,7 +460,7 @@ describe('Job', () => {
460460
});
461461

462462
describe('with bucket and path provided', () => {
463-
const sparkUIBucketName = 'sparkBucketName';
463+
const sparkUIBucketName = 'sparkbucketname';
464464
const prefix = 'some/path/';
465465
let sparkUIBucket: s3.IBucket;
466466

@@ -516,7 +516,7 @@ describe('Job', () => {
516516
Template.fromStack(stack).hasResourceProperties('AWS::Glue::Job', {
517517
Command: {
518518
Name: 'glueetl',
519-
ScriptLocation: 's3://bucketName/script',
519+
ScriptLocation: 's3://bucketname/script',
520520
},
521521
Role: {
522522
'Fn::GetAtt': [
@@ -614,7 +614,7 @@ describe('Job', () => {
614614
GlueVersion: '2.0',
615615
Command: {
616616
Name: 'glueetl',
617-
ScriptLocation: 's3://bucketName/script',
617+
ScriptLocation: 's3://bucketname/script',
618618
PythonVersion: '3',
619619
},
620620
Role: {
@@ -625,9 +625,9 @@ describe('Job', () => {
625625
},
626626
DefaultArguments: {
627627
'--job-language': 'python',
628-
'--extra-jars': 's3://bucketName/file1.jar,s3://bucketName/file2.jar',
629-
'--extra-py-files': 's3://bucketName/file1.py,s3://bucketName/file2.py',
630-
'--extra-files': 's3://bucketName/file1.txt,s3://bucketName/file2.txt',
628+
'--extra-jars': 's3://bucketname/file1.jar,s3://bucketname/file2.jar',
629+
'--extra-py-files': 's3://bucketname/file1.py,s3://bucketname/file2.py',
630+
'--extra-files': 's3://bucketname/file1.txt,s3://bucketname/file2.txt',
631631
'--user-jars-first': 'true',
632632
},
633633
});
@@ -649,7 +649,7 @@ describe('Job', () => {
649649
GlueVersion: '2.0',
650650
Command: {
651651
Name: 'gluestreaming',
652-
ScriptLocation: 's3://bucketName/script',
652+
ScriptLocation: 's3://bucketname/script',
653653
},
654654
Role: {
655655
'Fn::GetAtt': [
@@ -660,8 +660,8 @@ describe('Job', () => {
660660
DefaultArguments: {
661661
'--job-language': 'scala',
662662
'--class': 'com.amazon.test.ClassName',
663-
'--extra-jars': 's3://bucketName/file1.jar,s3://bucketName/file2.jar',
664-
'--extra-files': 's3://bucketName/file1.txt,s3://bucketName/file2.txt',
663+
'--extra-jars': 's3://bucketname/file1.jar,s3://bucketname/file2.jar',
664+
'--extra-files': 's3://bucketname/file1.txt,s3://bucketname/file2.txt',
665665
'--user-jars-first': 'true',
666666
},
667667
});

packages/@aws-cdk/aws-s3-notifications/test/notifications.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ describe('CloudWatch Events', () => {
336336
test('onCloudTrailPutObject contains the Bucket ARN itself when path is undefined', () => {
337337
const stack = new cdk.Stack();
338338
const bucket = s3.Bucket.fromBucketAttributes(stack, 'Bucket', {
339-
bucketName: 'MyBucket',
339+
bucketName: 'mybucket',
340340
});
341341
bucket.onCloudTrailPutObject('PutRule', {
342342
target: {
@@ -363,7 +363,7 @@ describe('CloudWatch Events', () => {
363363
{
364364
'Ref': 'AWS::Partition',
365365
},
366-
':s3:::MyBucket',
366+
':s3:::mybucket',
367367
],
368368
],
369369
},
@@ -378,7 +378,7 @@ describe('CloudWatch Events', () => {
378378
test("onCloudTrailPutObject contains the path when it's provided", () => {
379379
const stack = new cdk.Stack();
380380
const bucket = s3.Bucket.fromBucketAttributes(stack, 'Bucket', {
381-
bucketName: 'MyBucket',
381+
bucketName: 'mybucket',
382382
});
383383
bucket.onCloudTrailPutObject('PutRule', {
384384
target: {
@@ -406,7 +406,7 @@ describe('CloudWatch Events', () => {
406406
{
407407
'Ref': 'AWS::Partition',
408408
},
409-
':s3:::MyBucket/my/path.zip',
409+
':s3:::mybucket/my/path.zip',
410410
],
411411
],
412412
},
@@ -421,7 +421,7 @@ describe('CloudWatch Events', () => {
421421
test('onCloudTrailWriteObject matches on events CompleteMultipartUpload, CopyObject, and PutObject', () => {
422422
const stack = new cdk.Stack();
423423
const bucket = s3.Bucket.fromBucketAttributes(stack, 'Bucket', {
424-
bucketName: 'MyBucket',
424+
bucketName: 'mybucket',
425425
});
426426
bucket.onCloudTrailWriteObject('OnCloudTrailWriteObjectRule', {
427427
target: {
@@ -449,7 +449,7 @@ describe('CloudWatch Events', () => {
449449
test('onCloudTrailWriteObject matches on the requestParameter bucketName when the path is not provided', () => {
450450
const stack = new cdk.Stack();
451451
const bucket = s3.Bucket.fromBucketAttributes(stack, 'Bucket', {
452-
bucketName: 'MyBucket',
452+
bucketName: 'mybucket',
453453
});
454454
bucket.onCloudTrailWriteObject('OnCloudTrailWriteObjectRule', {
455455
target: {
@@ -476,7 +476,7 @@ describe('CloudWatch Events', () => {
476476
test('onCloudTrailWriteObject matches on the requestParameters bucketName and key when the path is provided', () => {
477477
const stack = new cdk.Stack();
478478
const bucket = s3.Bucket.fromBucketAttributes(stack, 'Bucket', {
479-
bucketName: 'MyBucket',
479+
bucketName: 'mybucket',
480480
});
481481
bucket.onCloudTrailWriteObject('OnCloudTrailWriteObjectRule', {
482482
target: {

0 commit comments

Comments
 (0)