Skip to content

Commit 90d1fc3

Browse files
committed
prefix is not required
1 parent c7d3968 commit 90d1fc3

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,18 @@ export function validateBranchKeyRecord(item: BranchKeyItem): BranchKeyRecord {
165165
`Branch keystore record does not contain ${HIERARCHY_VERSION_FIELD} field of type number`
166166
)
167167

168+
169+
// This requirement is around the construction of the encryption context.
170+
// It is possible that customers will have constructed their own branch keys
171+
// with a custom creation method.
172+
// In this case encryption context may not be prefixed.
173+
// The Dafny version of this code does not enforce
174+
// that additional encryption context keys MUST be prefixed,
175+
// therefore the JS release does not as well.
176+
168177
//= aws-encryption-sdk-specification/framework/key-store/dynamodb-key-storage.md#record-format
169178
//# A branch key record MAY include [custom encryption context](../branch-key-store.md#custom-encryption-context) key-value pairs.
170179
//# These attributes should be prefixed with `aws-crypto-ec:` the same way they are for [AWS KMS encryption context](../branch-key-store.md#encryption-context).
171-
for (const field in item) {
172-
if (!POTENTIAL_BRANCH_KEY_RECORD_FIELDS.includes(field)) {
173-
needs(
174-
field.startsWith(CUSTOM_ENCRYPTION_CONTEXT_FIELD_PREFIX),
175-
`Custom encryption context key ${field} should be prefixed with ${CUSTOM_ENCRYPTION_CONTEXT_FIELD_PREFIX}`
176-
)
177-
}
178-
}
179180

180181
// serialize the DDB response item as a more well-defined and validated branch
181182
// key record object

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

+3-11
Original file line numberDiff line numberDiff line change
@@ -333,26 +333,18 @@ describe('Test keystore helpers', () => {
333333
})
334334
})
335335

336-
it('Active & versioned items have additional fields prefixed improperly', () => {
336+
it('Active & versioned items may have additional fields that are not prefixed', () => {
337337
const activeItem = {
338338
...ACTIVE_BRANCH_KEY,
339339
...INVALID_CUSTOM_ENCRYPTION_CONTEXT_KV_PAIRS,
340340
}
341-
expect(() => validateBranchKeyRecord(activeItem)).to.throw(
342-
`Custom encryption context key ${
343-
Object.keys(INVALID_CUSTOM_ENCRYPTION_CONTEXT_KV_PAIRS)[0]
344-
} should be prefixed with ${CUSTOM_ENCRYPTION_CONTEXT_FIELD_PREFIX}`
345-
)
341+
expect(() => validateBranchKeyRecord(activeItem)).to.not.throw()
346342

347343
const versionedItem = {
348344
...VERSION_BRANCH_KEY,
349345
...INVALID_CUSTOM_ENCRYPTION_CONTEXT_KV_PAIRS,
350346
}
351-
expect(() => validateBranchKeyRecord(versionedItem)).to.throw(
352-
`Custom encryption context key ${
353-
Object.keys(INVALID_CUSTOM_ENCRYPTION_CONTEXT_KV_PAIRS)[0]
354-
} should be prefixed with ${CUSTOM_ENCRYPTION_CONTEXT_FIELD_PREFIX}`
355-
)
347+
expect(() => validateBranchKeyRecord(versionedItem)).to.not.throw()
356348
})
357349
})
358350

0 commit comments

Comments
 (0)