@@ -33,6 +33,7 @@ import {
33
33
} from './fixtures'
34
34
import {
35
35
BRANCH_KEY_ACTIVE_TYPE ,
36
+ KMS_CLIENT_USER_AGENT ,
36
37
PARTITION_KEY ,
37
38
SORT_KEY ,
38
39
} from '../src/constants'
@@ -233,7 +234,6 @@ describe('Test Branch keystore', () => {
233
234
expect (
234
235
validate ( keyStore . keyStoreId ) && version ( keyStore . keyStoreId ) === 4
235
236
) . equals ( true )
236
- // expect(keyStore.ddbTableName).equals(DDB_TABLE_NAME)
237
237
expect ( keyStore . kmsConfiguration . _config ) . equals ( kmsConfig )
238
238
} )
239
239
@@ -313,48 +313,97 @@ describe('Test Branch keystore', () => {
313
313
} )
314
314
315
315
expect ( storage instanceof DynamoDBKeyStorage ) . to . equals ( true )
316
+ //= aws-encryption-sdk-specification/framework/branch-key-store.md#initialization
317
+ //= type=test
318
+ //# This constructed [default key storage](./key-store/default-key-storage.md#initialization)
319
+ //# MUST be configured with either the [Table Name](#table-name) or the [DynamoDBTable](#dynamodbtable) table name
320
+ //# depending on which one is configured.
321
+ expect ( ( storage as DynamoDBKeyStorage ) . ddbTableName ) . to . equal (
322
+ DDB_TABLE_NAME
323
+ )
324
+
325
+ //= aws-encryption-sdk-specification/framework/branch-key-store.md#initialization
326
+ //= type=test
327
+ //# This constructed [default key storage](./key-store/default-key-storage.md#initialization)
328
+ //# MUST be configured with either the [DynamoDb Client](#dynamodb-client), the DDB client in the [DynamoDBTable](#dynamodbtable)
329
+ //# or a constructed DDB client depending on what is configured.
330
+ expect ( ( storage as DynamoDBKeyStorage ) . logicalKeyStoreName ) . to . equal (
331
+ LOGICAL_KEYSTORE_NAME
332
+ )
333
+
334
+ //= aws-encryption-sdk-specification/framework/branch-key-store.md#initialization
335
+ //= type=test
336
+ //# This constructed [default key storage](./key-store/default-key-storage.md#initialization)
337
+ //# MUST be configured with either the [DynamoDb Client](#dynamodb-client), the DDB client in the [DynamoDBTable](#dynamodbtable)
338
+ //# or a constructed DDB client depending on what is configured.
339
+ expect (
340
+ ( storage as DynamoDBKeyStorage ) . ddbClient instanceof DynamoDBClient
341
+ ) . to . equal ( true )
342
+
316
343
expect (
317
344
await ( storage as DynamoDBKeyStorage ) . ddbClient . config . region ( )
318
345
) . to . equal ( getRegionFromIdentifier ( KEY_ARN ) )
346
+
347
+ expect ( storage instanceof DynamoDBKeyStorage ) . to . equals ( true )
319
348
}
320
349
321
350
const mrkDiscovery = new BranchKeyStoreNode ( {
322
351
storage : {
323
- ddbTableName : DDB_TABLE_NAME
352
+ ddbTableName : DDB_TABLE_NAME ,
324
353
} ,
325
354
logicalKeyStoreName : LOGICAL_KEYSTORE_NAME ,
326
355
kmsConfiguration : { region : 'foo' } ,
327
356
} )
328
357
329
358
expect (
330
- await ( mrkDiscovery . storage as DynamoDBKeyStorage ) . ddbClient . config . region ( )
331
- ) . to . equal ( 'foo' )
359
+ await (
360
+ mrkDiscovery . storage as DynamoDBKeyStorage
361
+ ) . ddbClient . config . region ( )
362
+ ) . to . equal ( 'foo' )
332
363
333
364
const discovery = new BranchKeyStoreNode ( {
334
365
storage : {
335
- ddbTableName : DDB_TABLE_NAME
366
+ ddbTableName : DDB_TABLE_NAME ,
336
367
} ,
337
368
logicalKeyStoreName : LOGICAL_KEYSTORE_NAME ,
338
369
kmsConfiguration : 'discovery' ,
339
370
} )
340
371
341
372
expect (
342
- await ( discovery . storage as DynamoDBKeyStorage ) . ddbClient . config . region ( )
343
- ) . to . equal ( 'foo' )
373
+ await (
374
+ discovery . storage as DynamoDBKeyStorage
375
+ ) . ddbClient . config . region ( )
376
+ ) . to . not . equal ( '' )
344
377
} )
345
378
346
379
it ( 'Precondition: Only `discovery` is a valid string value' , async ( ) => {
347
- expect ( ( ) => new BranchKeyStoreNode ( {
348
- storage : {
349
- ddbTableName : DDB_TABLE_NAME
350
- } ,
351
- logicalKeyStoreName : LOGICAL_KEYSTORE_NAME ,
352
- kmsConfiguration : 'not discovery' as any ,
353
- } ) ) . to . throw ( 'Unexpected config shape' )
380
+ expect (
381
+ ( ) =>
382
+ new BranchKeyStoreNode ( {
383
+ storage : {
384
+ ddbTableName : DDB_TABLE_NAME ,
385
+ } ,
386
+ logicalKeyStoreName : LOGICAL_KEYSTORE_NAME ,
387
+ kmsConfiguration : 'not discovery' as any ,
388
+ } )
389
+ ) . to . throw ( 'Unexpected config shape' )
354
390
} )
355
391
392
+ //= aws-encryption-sdk-specification/framework/branch-key-store.md#initialization
393
+ //= type=test
394
+ //# If a DDB client needs to be constructed and the AWS KMS Configuration is KMS Key ARN or KMS MRKey ARN,
395
+ //# a new DynamoDb client MUST be created with the region of the supplied KMS ARN.
396
+ //#
397
+ //# If a DDB client needs to be constructed and the AWS KMS Configuration is Discovery,
398
+ //# a new DynamoDb client MUST be created with the default configuration.
399
+ //#
400
+ //# If a DDB client needs to be constructed and the AWS KMS Configuration is MRDiscovery,
401
+ //# a new DynamoDb client MUST be created with the region configured in the MRDiscovery.
356
402
it ( 'Postcondition: If unprovided, the KMS client is configured' , async ( ) => {
357
403
for ( const kmsClient of falseyValues ) {
404
+ //= aws-encryption-sdk-specification/framework/branch-key-store.md#initialization
405
+ //= type=test
406
+ //# If no AWS KMS client is provided one MUST be constructed.
358
407
const { kmsClient : client } = new BranchKeyStoreNode ( {
359
408
storage : { ddbTableName : DDB_TABLE_NAME } ,
360
409
logicalKeyStoreName : LOGICAL_KEYSTORE_NAME ,
@@ -365,7 +414,36 @@ describe('Test Branch keystore', () => {
365
414
expect ( await client . config . region ( ) ) . to . equal (
366
415
getRegionFromIdentifier ( KEY_ARN )
367
416
)
417
+
418
+ //= aws-encryption-sdk-specification/framework/branch-key-store.md#initialization
419
+ //= type=test
420
+ //# On initialization the KeyStore SHOULD
421
+ //# append a user agent string to the AWS KMS SDK Client with
422
+ //# the value `aws-kms-hierarchy`.
423
+ expect ( client . config . customUserAgent ) . to . deep . equal ( [
424
+ [ KMS_CLIENT_USER_AGENT ] ,
425
+ ] )
368
426
}
427
+
428
+ const mrkDiscovery = new BranchKeyStoreNode ( {
429
+ storage : {
430
+ ddbTableName : DDB_TABLE_NAME ,
431
+ } ,
432
+ logicalKeyStoreName : LOGICAL_KEYSTORE_NAME ,
433
+ kmsConfiguration : { region : 'foo' } ,
434
+ } )
435
+
436
+ expect ( await mrkDiscovery . kmsClient . config . region ( ) ) . to . equal ( 'foo' )
437
+
438
+ const discovery = new BranchKeyStoreNode ( {
439
+ storage : {
440
+ ddbTableName : DDB_TABLE_NAME ,
441
+ } ,
442
+ logicalKeyStoreName : LOGICAL_KEYSTORE_NAME ,
443
+ kmsConfiguration : 'discovery' ,
444
+ } )
445
+
446
+ expect ( await discovery . kmsClient . config . region ( ) ) . to . not . equal ( '' )
369
447
} )
370
448
371
449
//= aws-encryption-sdk-specification/framework/branch-key-store.md#table-name
@@ -414,6 +492,10 @@ describe('Test Branch keystore', () => {
414
492
expect ( Object . isFrozen ( BRANCH_KEYSTORE ) ) . equals ( true )
415
493
} )
416
494
495
+ it ( 'Storage is immutable' , ( ) => {
496
+ expect ( Object . isFrozen ( BRANCH_KEYSTORE . storage ) ) . equals ( true )
497
+ } )
498
+
417
499
it ( 'Attributes are correct' , ( ) => {
418
500
const kmsClient = new KMSClient ( {
419
501
region : getRegionFromIdentifier ( KEY_ARN ) ,
@@ -434,6 +516,19 @@ describe('Test Branch keystore', () => {
434
516
expect ( ( test . storage as DynamoDBKeyStorage ) . ddbTableName ) . to . equal (
435
517
DDB_TABLE_NAME
436
518
)
519
+
520
+ //= aws-encryption-sdk-specification/framework/branch-key-store.md#logical-keystore-name
521
+ //= type=test
522
+ //# This name is cryptographically bound to all data stored in this table,
523
+ //# and logically separates data between different tables.
524
+ //#
525
+ //# The logical keystore name MUST be bound to every created key.
526
+ //#
527
+ //# There needs to be a one to one mapping between DynamoDB Table Names and the Logical KeyStore Name.
528
+ //# This value can be set to the DynamoDB table name itself, but does not need to.
529
+ //#
530
+ //# Controlling this value independently enables restoring from DDB table backups
531
+ //# even when the table name after restoration is not exactly the same.
437
532
expect ( test . logicalKeyStoreName ) . to . equal ( LOGICAL_KEYSTORE_NAME )
438
533
expect ( test . kmsConfiguration . _config ) . to . equal ( KMS_CONFIGURATION )
439
534
expect ( test . kmsClient ) . to . equal ( kmsClient )
@@ -479,10 +574,20 @@ describe('Test Branch keystore', () => {
479
574
)
480
575
481
576
const branchKeyMaterials = await keyStore . getActiveBranchKey ( BRANCH_KEY_ID )
482
- // expect(branchKeyMaterials.branchKeyIdentifier).equals(BRANCH_KEY_ID)
577
+ //= aws-encryption-sdk-specification/framework/branch-key-store.md#getactivebranchkey
578
+ //= type=test
579
+ //# GetActiveBranchKey MUST verify that the returned EncryptedHierarchicalKey MUST have the requested `branch-key-id`.
580
+ expect ( branchKeyMaterials . branchKeyIdentifier ) . equals ( BRANCH_KEY_ID )
581
+ //= aws-encryption-sdk-specification/framework/branch-key-store.md#getactivebranchkey
582
+ //= type=test
583
+ //# GetActiveBranchKey MUST verify that the returned EncryptedHierarchicalKey is an ActiveHierarchicalSymmetricVersion.
483
584
expect ( branchKeyMaterials . branchKeyVersion ) . deep . equals (
484
585
BRANCH_KEY_ACTIVE_VERSION_UTF8_BYTES
485
586
)
587
+
588
+ //= aws-encryption-sdk-specification/framework/branch-key-store.md#getactivebranchkey
589
+ //= type=test
590
+ //# This operation MUST return the constructed [branch key materials](./structures.md#branch-key-materials).
486
591
expect ( branchKeyMaterials . branchKey ( ) . length ) . equals ( 32 )
487
592
} )
488
593
0 commit comments