@@ -338,26 +338,101 @@ describe('bucket', () => {
338
338
339
339
} ) ;
340
340
341
- test ( 'throws error if using KMS-Managed key and server access logging to self' , ( ) => {
341
+ test ( 'logs to self, no encryption does not throw error' , ( ) => {
342
+ const stack = new cdk . Stack ( ) ;
343
+ expect ( ( ) => {
344
+ new s3 . Bucket ( stack , 'MyBucket' , { encryption : s3 . BucketEncryption . UNENCRYPTED , serverAccessLogsPrefix : 'test' } ) ;
345
+ } ) . not . toThrowError ( ) ;
346
+ } ) ;
347
+
348
+ test ( 'logs to self, S3 encryption does not throw error' , ( ) => {
349
+ const stack = new cdk . Stack ( ) ;
350
+ expect ( ( ) => {
351
+ new s3 . Bucket ( stack , 'MyBucket' , { encryption : s3 . BucketEncryption . S3_MANAGED , serverAccessLogsPrefix : 'test' } ) ;
352
+ } ) . not . toThrowError ( ) ;
353
+ } ) ;
354
+
355
+ test ( 'logs to self, KMS_MANAGED encryption throws error' , ( ) => {
342
356
const stack = new cdk . Stack ( ) ;
343
357
expect ( ( ) => {
344
358
new s3 . Bucket ( stack , 'MyBucket' , { encryption : s3 . BucketEncryption . KMS_MANAGED , serverAccessLogsPrefix : 'test' } ) ;
345
- } ) . toThrow ( 'SSE-S3 is the only supported default bucket encryption for Server Access Logging target buckets' ) ;
359
+ } ) . toThrow ( / S S E - S 3 i s t h e o n l y s u p p o r t e d d e f a u l t b u c k e t e n c r y p t i o n f o r S e r v e r A c c e s s L o g g i n g t a r g e t b u c k e t s / ) ;
360
+ } ) ;
361
+
362
+ test ( 'logs to self, KMS encryption without key throws error' , ( ) => {
363
+ const stack = new cdk . Stack ( ) ;
364
+ expect ( ( ) => {
365
+ new s3 . Bucket ( stack , 'MyBucket' , { encryption : s3 . BucketEncryption . KMS , serverAccessLogsPrefix : 'test' } ) ;
366
+ } ) . toThrow ( / S S E - S 3 i s t h e o n l y s u p p o r t e d d e f a u l t b u c k e t e n c r y p t i o n f o r S e r v e r A c c e s s L o g g i n g t a r g e t b u c k e t s / ) ;
367
+ } ) ;
368
+
369
+ test ( 'logs to self, KMS encryption with key throws error' , ( ) => {
370
+ const stack = new cdk . Stack ( ) ;
371
+ const key = new kms . Key ( stack , 'TestKey' ) ;
372
+ expect ( ( ) => {
373
+ new s3 . Bucket ( stack , 'MyBucket' , { encryptionKey : key , encryption : s3 . BucketEncryption . KMS , serverAccessLogsPrefix : 'test' } ) ;
374
+ } ) . toThrow ( / S S E - S 3 i s t h e o n l y s u p p o r t e d d e f a u l t b u c k e t e n c r y p t i o n f o r S e r v e r A c c e s s L o g g i n g t a r g e t b u c k e t s / ) ;
346
375
} ) ;
347
- test ( 'throws error if using KMS CMK and server access logging to self' , ( ) => {
376
+
377
+ test ( 'logs to self, KMS key with no specific encryption specified throws error' , ( ) => {
348
378
const stack = new cdk . Stack ( ) ;
349
379
const key = new kms . Key ( stack , 'TestKey' ) ;
350
380
expect ( ( ) => {
351
381
new s3 . Bucket ( stack , 'MyBucket' , { encryptionKey : key , serverAccessLogsPrefix : 'test' } ) ;
352
- } ) . toThrow ( 'SSE-S3 is the only supported default bucket encryption for Server Access Logging target buckets' ) ;
382
+ } ) . toThrow ( / S S E - S 3 i s t h e o n l y s u p p o r t e d d e f a u l t b u c k e t e n c r y p t i o n f o r S e r v e r A c c e s s L o g g i n g t a r g e t b u c k e t s / ) ;
383
+ } ) ;
384
+
385
+ test ( 'logs to separate bucket, no encryption does not throw error' , ( ) => {
386
+ const stack = new cdk . Stack ( ) ;
387
+ const logBucket = new s3 . Bucket ( stack , 'testLogBucket' , { encryption : s3 . BucketEncryption . UNENCRYPTED } ) ;
388
+ expect ( ( ) => {
389
+ new s3 . Bucket ( stack , 'MyBucket' , { serverAccessLogsBucket : logBucket } ) ;
390
+ } ) . not . toThrowError ( ) ;
391
+ } ) ;
392
+
393
+ test ( 'logs to separate bucket, S3 encryption does not throw error' , ( ) => {
394
+ const stack = new cdk . Stack ( ) ;
395
+ const logBucket = new s3 . Bucket ( stack , 'testLogBucket' , { encryption : s3 . BucketEncryption . S3_MANAGED } ) ;
396
+ expect ( ( ) => {
397
+ new s3 . Bucket ( stack , 'MyBucket' , { serverAccessLogsBucket : logBucket } ) ;
398
+ } ) . not . toThrowError ( ) ;
399
+ } ) ;
400
+
401
+ // When provided an external bucket (as an IBucket), we cannot detect KMS_MANAGED encryption. Since this
402
+ // check is impossible, we skip thist test.
403
+ // eslint-disable-next-line jest/no-disabled-tests
404
+ test . skip ( 'logs to separate bucket, KMS_MANAGED encryption throws error' , ( ) => {
405
+ const stack = new cdk . Stack ( ) ;
406
+ const logBucket = new s3 . Bucket ( stack , 'testLogBucket' , { encryption : s3 . BucketEncryption . KMS_MANAGED } ) ;
407
+ expect ( ( ) => {
408
+ new s3 . Bucket ( stack , 'MyBucket' , { serverAccessLogsBucket : logBucket } ) ;
409
+ } ) . toThrow ( / S S E - S 3 i s t h e o n l y s u p p o r t e d d e f a u l t b u c k e t e n c r y p t i o n f o r S e r v e r A c c e s s L o g g i n g t a r g e t b u c k e t s / ) ;
353
410
} ) ;
354
- test ( 'throws error if enabling server access logging to bucket with SSE-KMS' , ( ) => {
411
+
412
+ test ( 'logs to separate bucket, KMS encryption without key throws error' , ( ) => {
413
+ const stack = new cdk . Stack ( ) ;
414
+ const logBucket = new s3 . Bucket ( stack , 'testLogBucket' , { encryption : s3 . BucketEncryption . KMS } ) ;
415
+ expect ( ( ) => {
416
+ new s3 . Bucket ( stack , 'MyBucket' , { serverAccessLogsBucket : logBucket } ) ;
417
+ } ) . toThrow ( / S S E - S 3 i s t h e o n l y s u p p o r t e d d e f a u l t b u c k e t e n c r y p t i o n f o r S e r v e r A c c e s s L o g g i n g t a r g e t b u c k e t s / ) ;
418
+ } ) ;
419
+
420
+ test ( 'logs to separate bucket, KMS encryption with key throws error' , ( ) => {
421
+ const stack = new cdk . Stack ( ) ;
422
+ const key = new kms . Key ( stack , 'TestKey' ) ;
423
+ const logBucket = new s3 . Bucket ( stack , 'testLogBucket' , { encryptionKey : key , encryption : s3 . BucketEncryption . KMS } ) ;
424
+ expect ( ( ) => {
425
+ new s3 . Bucket ( stack , 'MyBucket' , { serverAccessLogsBucket : logBucket } ) ;
426
+ } ) . toThrow ( / S S E - S 3 i s t h e o n l y s u p p o r t e d d e f a u l t b u c k e t e n c r y p t i o n f o r S e r v e r A c c e s s L o g g i n g t a r g e t b u c k e t s / ) ;
427
+ } ) ;
428
+
429
+ test ( 'logs to separate bucket, KMS key with no specific encryption specified throws error' , ( ) => {
355
430
const stack = new cdk . Stack ( ) ;
356
431
const key = new kms . Key ( stack , 'TestKey' ) ;
357
- const targetBucket = new s3 . Bucket ( stack , 'TargetBucket ' , { encryptionKey : key } ) ;
432
+ const logBucket = new s3 . Bucket ( stack , 'testLogBucket ' , { encryptionKey : key } ) ;
358
433
expect ( ( ) => {
359
- new s3 . Bucket ( stack , 'MyBucket' , { serverAccessLogsBucket : targetBucket } ) ;
360
- } ) . toThrow ( ' SSE-S3 is the only supported default bucket encryption for Server Access Logging target buckets' ) ;
434
+ new s3 . Bucket ( stack , 'MyBucket' , { serverAccessLogsBucket : logBucket } ) ;
435
+ } ) . toThrow ( / S S E - S 3 i s t h e o n l y s u p p o r t e d d e f a u l t b u c k e t e n c r y p t i o n f o r S e r v e r A c c e s s L o g g i n g t a r g e t b u c k e t s / ) ;
361
436
} ) ;
362
437
363
438
test ( 'bucket with versioning turned on' , ( ) => {
0 commit comments