Skip to content

Commit ebd510d

Browse files
committed
Adding test information
1 parent 2c0dc18 commit ebd510d

File tree

3 files changed

+127
-19
lines changed

3 files changed

+127
-19
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@ import { DynamoDBKeyStorage } from './dynamodb_key_storage'
3131

3232
interface IBranchKeyStoreNode {
3333
//= aws-encryption-sdk-specification/framework/branch-key-store.md#operations
34+
//= type=implication
3435
//# - [GetActiveBranchKey](#getactivebranchkey)
3536
getActiveBranchKey(branchKeyId: string): Promise<NodeBranchKeyMaterial>
3637
//= aws-encryption-sdk-specification/framework/branch-key-store.md#operations
38+
//= type=implication
3739
//# - [GetBranchKeyVersion](#getbranchkeyversion)
3840
getBranchKeyVersion(
3941
branchKeyId: string,
4042
branchKeyVersion: string
4143
): Promise<NodeBranchKeyMaterial>
4244
//= aws-encryption-sdk-specification/framework/branch-key-store.md#operations
45+
//= type=implication
4346
//# - [GetKeyStoreInfo](#getkeystoreinfo)
4447
getKeyStoreInfo(): KeyStoreInfoOutput
4548
}
@@ -106,7 +109,7 @@ export class BranchKeyStoreNode implements IBranchKeyStoreNode {
106109
//= aws-encryption-sdk-specification/framework/branch-key-store.md#initialization
107110
//# If [Storage](#storage) is configured with [KeyStorage](#keystorage)
108111
//# then this MUST be the configured [KeyStorage interface](./key-store/key-storage.md#interface).
109-
this.storage
112+
this.storage = storage
110113
} else {
111114
//= aws-encryption-sdk-specification/framework/branch-key-store.md#initialization
112115
//# If [Storage](#storage) is not configured with [KeyStorage](#keystorage)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export interface RegionalKmsConfig {
5656
* this method tells the user the config's region
5757
* @returns the region
5858
*/
59-
getRegion(): string
59+
getRegion(): string | undefined
6060

6161
/**
6262
* this method tells the user if the config is compatible with an arn
@@ -125,7 +125,7 @@ export class KmsKeyConfig implements RegionalKmsConfig {
125125
Object.freeze(this)
126126
}
127127

128-
getRegion(): string {
128+
getRegion(): string | undefined {
129129
if (this._config === 'discovery') {
130130
//= aws-encryption-sdk-specification/framework/branch-key-store.md#initialization
131131
//# If a DDB client needs to be constructed and the AWS KMS Configuration is Discovery,
@@ -134,7 +134,7 @@ export class KmsKeyConfig implements RegionalKmsConfig {
134134
//= aws-encryption-sdk-specification/framework/branch-key-store.md#initialization
135135
//# If AWS KMS client needs to be constructed and the AWS KMS Configuration is Discovery,
136136
//# a new AWS KMS client MUST be created with the default configuration.
137-
return ''
137+
return undefined
138138
} else if (
139139
'identifier' in this._config ||
140140
'mrkIdentifier' in this._config

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

Lines changed: 120 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
} from './fixtures'
3434
import {
3535
BRANCH_KEY_ACTIVE_TYPE,
36+
KMS_CLIENT_USER_AGENT,
3637
PARTITION_KEY,
3738
SORT_KEY,
3839
} from '../src/constants'
@@ -233,7 +234,6 @@ describe('Test Branch keystore', () => {
233234
expect(
234235
validate(keyStore.keyStoreId) && version(keyStore.keyStoreId) === 4
235236
).equals(true)
236-
// expect(keyStore.ddbTableName).equals(DDB_TABLE_NAME)
237237
expect(keyStore.kmsConfiguration._config).equals(kmsConfig)
238238
})
239239

@@ -313,48 +313,97 @@ describe('Test Branch keystore', () => {
313313
})
314314

315315
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+
316343
expect(
317344
await (storage as DynamoDBKeyStorage).ddbClient.config.region()
318345
).to.equal(getRegionFromIdentifier(KEY_ARN))
346+
347+
expect(storage instanceof DynamoDBKeyStorage).to.equals(true)
319348
}
320349

321350
const mrkDiscovery = new BranchKeyStoreNode({
322351
storage: {
323-
ddbTableName: DDB_TABLE_NAME
352+
ddbTableName: DDB_TABLE_NAME,
324353
},
325354
logicalKeyStoreName: LOGICAL_KEYSTORE_NAME,
326355
kmsConfiguration: { region: 'foo' },
327356
})
328357

329358
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')
332363

333364
const discovery = new BranchKeyStoreNode({
334365
storage: {
335-
ddbTableName: DDB_TABLE_NAME
366+
ddbTableName: DDB_TABLE_NAME,
336367
},
337368
logicalKeyStoreName: LOGICAL_KEYSTORE_NAME,
338369
kmsConfiguration: 'discovery',
339370
})
340371

341372
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('')
344377
})
345378

346379
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')
354390
})
355391

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.
356402
it('Postcondition: If unprovided, the KMS client is configured', async () => {
357403
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.
358407
const { kmsClient: client } = new BranchKeyStoreNode({
359408
storage: { ddbTableName: DDB_TABLE_NAME },
360409
logicalKeyStoreName: LOGICAL_KEYSTORE_NAME,
@@ -365,7 +414,36 @@ describe('Test Branch keystore', () => {
365414
expect(await client.config.region()).to.equal(
366415
getRegionFromIdentifier(KEY_ARN)
367416
)
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+
])
368426
}
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('')
369447
})
370448

371449
//= aws-encryption-sdk-specification/framework/branch-key-store.md#table-name
@@ -414,6 +492,10 @@ describe('Test Branch keystore', () => {
414492
expect(Object.isFrozen(BRANCH_KEYSTORE)).equals(true)
415493
})
416494

495+
it('Storage is immutable', () => {
496+
expect(Object.isFrozen(BRANCH_KEYSTORE.storage)).equals(true)
497+
})
498+
417499
it('Attributes are correct', () => {
418500
const kmsClient = new KMSClient({
419501
region: getRegionFromIdentifier(KEY_ARN),
@@ -434,6 +516,19 @@ describe('Test Branch keystore', () => {
434516
expect((test.storage as DynamoDBKeyStorage).ddbTableName).to.equal(
435517
DDB_TABLE_NAME
436518
)
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.
437532
expect(test.logicalKeyStoreName).to.equal(LOGICAL_KEYSTORE_NAME)
438533
expect(test.kmsConfiguration._config).to.equal(KMS_CONFIGURATION)
439534
expect(test.kmsClient).to.equal(kmsClient)
@@ -479,10 +574,20 @@ describe('Test Branch keystore', () => {
479574
)
480575

481576
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.
483584
expect(branchKeyMaterials.branchKeyVersion).deep.equals(
484585
BRANCH_KEY_ACTIVE_VERSION_UTF8_BYTES
485586
)
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).
486591
expect(branchKeyMaterials.branchKey().length).equals(32)
487592
})
488593

0 commit comments

Comments
 (0)