Skip to content

Commit 57d4568

Browse files
committed
updates for tests
1 parent aabbfed commit 57d4568

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

modules/branch-keystore-node/src/branch_keystore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class BranchKeyStoreNode implements IBranchKeyStoreNode {
8282
'Logical keystore name must be a string'
8383
)
8484

85-
needs(kmsConfiguration, 'AWS KMS Configuration required')
85+
/* Precondition: KMS Configuration must be provided. */
8686
readOnlyProperty(
8787
this,
8888
'kmsConfiguration',

modules/branch-keystore-node/src/kms_config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ export class KmsKeyConfig implements RegionalKmsConfig {
8181
readOnlyProperty(this, '_config', config)
8282
/* Precondition: config must be a string or object */
8383
const configType = typeof config
84-
needs(!!config && (configType === 'object' || 'string'), 'Config must be a `discovery` or an object.')
85-
if (config === 'discovery') {
86-
// Nothing to set
84+
needs(!!config && (configType === 'object' || configType === 'string'), 'Config must be a `discovery` or an object.')
85+
if (configType === 'string') {
86+
/* Precondition: Only `discovery` is a valid string value */
87+
needs(config === 'discovery', 'Unexpected config shape')
8788
} else if ('identifier' in config || 'mrkIdentifier' in config) {
8889
const arn =
8990
'identifier' in config ? config.identifier : config.mrkIdentifier

modules/branch-keystore-node/test/branch_keystore.test.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,16 @@ describe('Test Branch keystore', () => {
9393
}
9494
})
9595

96-
it('Precondition: KMS Configuration must be SRK', () => {
97-
// all types of values
98-
const badVals = [...falseyValues, ...truthyValues]
99-
100-
for (const kmsConfiguration of badVals) {
96+
it('Precondition: KMS Configuration must be provided.', () => {
97+
for (const kmsConfiguration of [...falseyValues, ...truthyValues]) {
10198
expect(
10299
() =>
103100
new BranchKeyStoreNode({
104101
storage: { ddbTableName: DDB_TABLE_NAME },
105102
logicalKeyStoreName: LOGICAL_KEYSTORE_NAME,
106103
kmsConfiguration: kmsConfiguration as any,
107104
})
108-
).to.throw('KMS Configuration must be SRK')
105+
).to.throw(/Unexpected config shape|Config must be a `discovery` or an object./)
109106
}
110107
})
111108

@@ -193,11 +190,10 @@ describe('Test Branch keystore', () => {
193190
const kmsClient = new KMSClient({})
194191
const ddbClient = new DynamoDBClient({})
195192
expect(() => {
196-
const kmsConfig = { identifier: KEY_ID }
197193
return new BranchKeyStoreNode({
198194
storage: { ddbTableName: DDB_TABLE_NAME, ddbClient },
199195
logicalKeyStoreName: LOGICAL_KEYSTORE_NAME,
200-
kmsConfiguration: kmsConfig,
196+
kmsConfiguration: { identifier: KEY_ID},
201197
keyManagement: { kmsClient },
202198
})
203199
}).to.throw(
@@ -224,7 +220,7 @@ describe('Test Branch keystore', () => {
224220
it('Valid config', () => {
225221
const kmsClient = new KMSClient({})
226222
const ddbClient = new DynamoDBClient({})
227-
const kmsConfig = { identifier: KEY_ID }
223+
const kmsConfig = { identifier: KEY_ARN }
228224
const keyStore = new BranchKeyStoreNode({
229225
storage: { ddbTableName: DDB_TABLE_NAME, ddbClient },
230226
logicalKeyStoreName: LOGICAL_KEYSTORE_NAME,
@@ -236,13 +232,13 @@ describe('Test Branch keystore', () => {
236232
validate(keyStore.keyStoreId) && version(keyStore.keyStoreId) === 4
237233
).equals(true)
238234
// expect(keyStore.ddbTableName).equals(DDB_TABLE_NAME)
239-
expect(keyStore.kmsConfiguration).equals(kmsConfig)
235+
expect(keyStore.kmsConfiguration._config).equals(kmsConfig)
240236
})
241237

242238
it('Test valid config with no clients', () => {
243239
const kmsClient = new KMSClient({})
244240
const ddbClient = new DynamoDBClient({})
245-
const kmsConfig = { identifier: KEY_ID }
241+
const kmsConfig = { identifier: KEY_ARN }
246242

247243
// test with no kms client supplied
248244
expect(
@@ -390,7 +386,7 @@ describe('Test Branch keystore', () => {
390386
DDB_TABLE_NAME
391387
)
392388
expect(test.logicalKeyStoreName).to.equal(LOGICAL_KEYSTORE_NAME)
393-
expect(test.kmsConfiguration).to.equal(KMS_CONFIGURATION)
389+
expect(test.kmsConfiguration._config).to.equal(KMS_CONFIGURATION)
394390
expect(test.kmsClient).to.equal(kmsClient)
395391
expect((test.storage as DynamoDBKeyStorage).ddbClient).to.equal(
396392
ddbClient
@@ -407,7 +403,7 @@ describe('Test Branch keystore', () => {
407403
it('Test get active key', async () => {
408404
const kmsClient = new KMSClient({})
409405
const ddbClient = new DynamoDBClient({})
410-
const kmsConfig = { identifier: KEY_ID }
406+
const kmsConfig = { identifier: KEY_ARN }
411407
const keyStore = new BranchKeyStoreNode({
412408
kmsConfiguration: kmsConfig,
413409
storage: { ddbTableName: DDB_TABLE_NAME, ddbClient: ddbClient },
@@ -443,7 +439,7 @@ describe('Test Branch keystore', () => {
443439
it('Test get branch key version', async () => {
444440
const kmsClient = new KMSClient({})
445441
const ddbClient = new DynamoDBClient({})
446-
const kmsConfig = { identifier: KEY_ID }
442+
const kmsConfig = { identifier: KEY_ARN }
447443

448444
const keyStore = new BranchKeyStoreNode({
449445
kmsConfiguration: kmsConfig,
@@ -493,7 +489,7 @@ describe('Test Branch keystore', () => {
493489
it('Test get active key with incorrect kms key arn', async () => {
494490
const kmsClient = new KMSClient({})
495491
const ddbClient = new DynamoDBClient({})
496-
const kmsConfig = { identifier: KEY_ID }
492+
const kmsConfig = { identifier: KEY_ARN }
497493

498494
const keyStore = new BranchKeyStoreNode({
499495
kmsConfiguration: kmsConfig,
@@ -513,7 +509,7 @@ describe('Test Branch keystore', () => {
513509
it('Test get active key with wrong logical keystore name', async () => {
514510
const kmsClient = new KMSClient({})
515511
const ddbClient = new DynamoDBClient({})
516-
const kmsConfig = { identifier: KEY_ID }
512+
const kmsConfig = { identifier: KEY_ARN }
517513

518514
const keyStore = new BranchKeyStoreNode({
519515
kmsConfiguration: kmsConfig,
@@ -531,7 +527,7 @@ describe('Test Branch keystore', () => {
531527
it('Test get active key does not exist fails', async () => {
532528
const kmsClient = new KMSClient({})
533529
const ddbClient = new DynamoDBClient({})
534-
const kmsConfig = { identifier: KEY_ID }
530+
const kmsConfig = { identifier: KEY_ARN }
535531

536532
const keyStore = new BranchKeyStoreNode({
537533
kmsConfiguration: kmsConfig,
@@ -549,7 +545,7 @@ describe('Test Branch keystore', () => {
549545
})
550546

551547
it('Test get active key with no clients', async () => {
552-
const kmsConfig = { identifier: KEY_ID }
548+
const kmsConfig = { identifier: KEY_ARN }
553549
const keyStore = new BranchKeyStoreNode({
554550
kmsConfiguration: kmsConfig,
555551
logicalKeyStoreName: LOGICAL_KEYSTORE_NAME,

0 commit comments

Comments
 (0)