@@ -252,6 +252,99 @@ describe('utils/encryption.js', () => {
252252 . done ( done ) ;
253253 } ) ;
254254
255+ it ( 'should encrypt data - listener function w/ eem as function' , ( done ) => {
256+ const rule1 = {
257+ id : 'e1' ,
258+ flavor : materialize ,
259+ eventType : 'thing-created' ,
260+ toUpdateRequest : async ( uow , rule ) => ( {
261+ Key : {
262+ pk : uow . event . thing . id ,
263+ sk : 'thing' ,
264+ } ,
265+ ...updateExpression ( await rule . encrypt ( {
266+ ...uow . event . thing ,
267+ discriminator : 'thing' ,
268+ timestamp : uow . event . timestamp ,
269+ } ) ) ,
270+ } ) ,
271+ eem : ( data ) => {
272+ if ( data . discriminator === 'thing' ) {
273+ return {
274+ fields : [
275+ 'name' ,
276+ 'description' ,
277+ ] ,
278+ } ;
279+ } else {
280+ return {
281+ fields : [ ] ,
282+ } ;
283+ }
284+ } ,
285+ masterKeyAlias : 'alias/aws-kms-ee' ,
286+ AES : false ,
287+ } ;
288+
289+ const events = toKinesisRecords ( [ {
290+ id : '0' ,
291+ type : 'thing-created' ,
292+ timestamp : 1572832690000 ,
293+ thing : {
294+ id : '1' ,
295+ name : 'n1' ,
296+ description : 'd1' ,
297+ status : 's1' ,
298+ } ,
299+ } ] ) ;
300+
301+ initialize ( {
302+ ...initializeFrom ( [ rule1 ] ) ,
303+ } )
304+ . assemble ( fromKinesis ( events ) , false )
305+ . collect ( )
306+ . tap ( ( collected ) => {
307+ // console.log(JSON.stringify(collected, null, 2));
308+ expect ( collected . length ) . to . equal ( 1 ) ;
309+ expect ( collected [ 0 ] . updateRequest ) . to . deep . equal ( {
310+ Key : {
311+ pk : '1' ,
312+ sk : 'thing' ,
313+ } ,
314+ ExpressionAttributeNames : {
315+ '#id' : 'id' ,
316+ '#name' : 'name' ,
317+ '#description' : 'description' ,
318+ '#status' : 'status' ,
319+ '#discriminator' : 'discriminator' ,
320+ '#timestamp' : 'timestamp' ,
321+ '#eem' : 'eem' ,
322+ } ,
323+ ExpressionAttributeValues : {
324+ ':id' : '1' ,
325+ ':name' : 'Im4xIg==' ,
326+ ':description' : 'ImQxIg==' ,
327+ ':status' : 's1' ,
328+ ':discriminator' : 'thing' ,
329+ ':timestamp' : 1572832690000 ,
330+ ':eem' : {
331+ dataKeys : {
332+ 'us-west-2' : MOCK_GEN_DK_RESPONSE . CiphertextBlob . toString ( 'base64' ) ,
333+ } ,
334+ masterKeyAlias : 'alias/aws-kms-ee' ,
335+ fields : [
336+ 'name' ,
337+ 'description' ,
338+ ] ,
339+ } ,
340+ } ,
341+ UpdateExpression : 'SET #id = :id, #name = :name, #description = :description, #status = :status, #discriminator = :discriminator, #timestamp = :timestamp, #eem = :eem' ,
342+ ReturnValues : 'ALL_NEW' ,
343+ } ) ;
344+ } )
345+ . done ( done ) ;
346+ } ) ;
347+
255348 it ( 'should decrypt data - query function' , async ( ) => {
256349 const encryptedQueryResults = [ {
257350 id : '1' ,
0 commit comments