@@ -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