File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -5,11 +5,15 @@ const lambdaUtils = require("../lambda-utils");
5
5
6
6
const console = lambdaUtils . console ;
7
7
8
+ function encrypt ( clear ) {
9
+ const cipher = crypto . createCipher ( "aes192" , config . HL_SECRET1 ) ;
10
+ return cipher . update ( clear , "utf8" , "base64" ) + cipher . final ( "base64" ) ;
11
+ }
12
+
8
13
function postEncrypt ( call , res , next ) {
9
14
console . log ( "Encrypting payload" ) ;
10
- const cipher = crypto . createCipher ( "aes192" , process . env . HL_SECRET1 ) ;
11
- cipher . update ( JSON . stringify ( call . event . body ) ) ;
12
- call . body = { encrypted : cipher . final ( "base64" ) } ;
15
+ const encrypted = encrypt ( JSON . stringify ( call . event . body ) ) ;
16
+ call . body = { encrypted} ;
13
17
next ( ) ;
14
18
}
15
19
Original file line number Diff line number Diff line change 1
1
"use strict" ;
2
2
const { handler} = require ( "./lambda" ) ;
3
+ const config = require ( "../config" ) ;
4
+ const crypto = require ( "crypto" ) ;
3
5
const eventSchema = require ( "./event-schema" ) ;
4
6
const set = require ( "lodash.set" ) ;
5
7
const tap = require ( "tap" ) ;
@@ -12,6 +14,11 @@ function mockEvent(path, value) {
12
14
return event ;
13
15
}
14
16
17
+ function decrypt ( encrypted ) {
18
+ const decipher = crypto . createDecipher ( "aes192" , config . HL_SECRET1 ) ;
19
+ return decipher . update ( encrypted , "base64" , "utf8" ) + decipher . final ( "utf8" ) ;
20
+ }
21
+
15
22
const invalids = [
16
23
[ "body" , 0 ] , // not string
17
24
[ "body" , false ] , // not string
@@ -38,6 +45,9 @@ tap.test("handler should work in base case", test => {
38
45
const body = JSON . parse ( res . body ) ;
39
46
test . ok ( body . encrypted ) ;
40
47
test . same ( typeof body . encrypted , "string" ) ;
48
+ const payloadJson = decrypt ( body . encrypted ) ;
49
+ const payload = JSON . parse ( payloadJson ) ;
50
+ test . match ( { foo : "FOO" , bar : "BAR" } , payload ) ;
41
51
test . end ( ) ;
42
52
} ) ;
43
53
} ) ;
You can’t perform that action at this time.
0 commit comments