Skip to content

Commit 684f1fd

Browse files
Joshua LamkeJoshua Lamke
authored andcommitted
allow eem to be a function for encryptEvent function. Also pass in entire uow as additional info
1 parent c6d5357 commit 684f1fd

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

src/utils/encryption.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ export const encryptEvent = ({
128128
return _(Promise.resolve(uow));
129129
}
130130

131+
const eemMetadata = typeof eem === 'function' ? eem(uow[sourceField], uow) : eem;
131132
const p = encryptObject(uow[sourceField], {
132133
masterKeyAlias,
133134
regions,
134-
...eem, // fields and overrides
135+
...eemMetadata, // fields and overrides
135136
AES,
136137
})
137138
// .tap(debug)

test/unit/utils/encryption.test.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,79 @@ describe('utils/encryption.js', () => {
9191
.done(done);
9292
});
9393

94+
it('should encrypt an event - trigger function w/ eem function', (done) => {
95+
const events = toDynamodbRecords([
96+
{
97+
timestamp: 1572832690,
98+
keys: {
99+
pk: '1',
100+
sk: 'thing',
101+
},
102+
newImage: {
103+
pk: '1',
104+
sk: 'thing',
105+
discriminator: 'thing',
106+
name: 'n1',
107+
description: 'd1',
108+
status: 's1',
109+
},
110+
},
111+
]);
112+
113+
fromDynamodb(events)
114+
.through(encryptEvent({
115+
eem: (event, _uow) => {
116+
if (event.raw.new.discriminator === 'thing') {
117+
return {
118+
fields: ['name', 'description'],
119+
};
120+
}
121+
return {
122+
fields: [],
123+
};
124+
},
125+
masterKeyAlias: 'alias/aws-kms-ee',
126+
AES: false,
127+
}))
128+
.collect()
129+
.tap((collected) => {
130+
// console.log(JSON.stringify(collected, null, 2));
131+
132+
expect(collected.length).to.equal(1);
133+
expect(collected[0].event).to.deep.equal({
134+
id: '0',
135+
type: 'thing-created',
136+
partitionKey: '1',
137+
timestamp: 1572832690000,
138+
tags: {
139+
region: 'us-west-2',
140+
},
141+
raw: {
142+
new: {
143+
pk: '1',
144+
sk: 'thing',
145+
discriminator: 'thing',
146+
name: 'Im4xIg==',
147+
description: 'ImQxIg==',
148+
status: 's1',
149+
},
150+
old: undefined,
151+
},
152+
eem: {
153+
masterKeyAlias: 'alias/aws-kms-ee',
154+
dataKeys: {
155+
'us-west-2': MOCK_GEN_DK_RESPONSE.CiphertextBlob.toString('base64'),
156+
},
157+
fields: [
158+
'name',
159+
'description',
160+
],
161+
},
162+
});
163+
})
164+
.done(done);
165+
});
166+
94167
it('should decrypt an event - listener function', (done) => {
95168
const events = toKinesisRecords([
96169
{

0 commit comments

Comments
 (0)