Skip to content
This repository has been archived by the owner on Feb 24, 2022. It is now read-only.

Commit

Permalink
chore(kinesis): some minor cleanup, adding a test (aws#7135)
Browse files Browse the repository at this point in the history
Since we infer the intent was to use `KMS` if an encryption key was provided, we no longer need the validation block. Also some minor cleanup so we don't return undefined
  • Loading branch information
shivlaks authored and horsmand committed Apr 8, 2020
1 parent d3b7471 commit af2670a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
7 changes: 2 additions & 5 deletions packages/@aws-cdk/aws-kinesis/lib/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,12 @@ export class Stream extends StreamBase {
}

if (encryptionType === StreamEncryption.UNENCRYPTED) {
return { streamEncryption: undefined, encryptionKey: undefined };
return { };
}

if (encryptionType === StreamEncryption.MANAGED) {
const encryption = { encryptionType: 'KMS', keyId: 'alias/aws/kinesis'};
return {
streamEncryption: encryption,
encryptionKey: undefined
};
return { streamEncryption: encryption };
}

if (encryptionType === StreamEncryption.KMS) {
Expand Down
18 changes: 18 additions & 0 deletions packages/@aws-cdk/aws-kinesis/test/test.stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export = {

test.done();
},

'retention period must be between 24 and 168 hours'(test: Test) {
test.throws(() => {
new Stream(new Stack(), 'MyStream', {
Expand Down Expand Up @@ -303,6 +304,21 @@ export = {
test.done();
},

'encryption key cannot be supplied with UNENCRYPTED as the encryption type'(test: Test) {

const stack = new Stack();
const key = new kms.Key(stack, 'myKey');

test.throws(() => {
new Stream(stack, 'MyStream', {
encryptionKey: key,
encryption: StreamEncryption.UNENCRYPTED
});
}, /encryptionKey is specified, so 'encryption' must be set to KMS/);

test.done();
},

'if a KMS key is supplied, use KMS as the encryption type'(test: Test) {
// GIVEN
const stack = new Stack();
Expand Down Expand Up @@ -409,6 +425,7 @@ export = {

test.done();
},

'uses explicit KMS key if encryption type is KMS and a key is provided'(test: Test) {
const stack = new Stack();

Expand Down Expand Up @@ -493,6 +510,7 @@ export = {

test.done();
},

permissions: {
'with encryption': {
'grantRead creates and attaches a policy with read only access to Stream and EncryptionKey'(test: Test) {
Expand Down

0 comments on commit af2670a

Please sign in to comment.