@@ -2,6 +2,7 @@ import HmacValidator from "../utils/hmacValidator";
2
2
import { NotificationItem , NotificationRequestItem } from "../typings/notification/models" ;
3
3
import { ApiConstants } from "../constants/apiConstants" ;
4
4
import NotificationRequestService from "../notification/notificationRequest" ;
5
+ const fs = require ( 'fs' ) ;
5
6
6
7
const key = "DFB1EB5485895CFA84146406857104ABB4CBCABDC8AAF103A624C8F6A3EAAB00" ;
7
8
const expectedSign = "ZNBPtI+oDyyRrLyD1XirkKnQgIAlFc07Vj27TeHsDRE=" ;
@@ -127,4 +128,21 @@ describe("HMAC Validator", function (): void {
127
128
notification . notificationItems ! [ 0 ] . additionalData ! [ ApiConstants . HMAC_SIGNATURE ] = "notValidSign" ;
128
129
expect ( hmacValidator . validateHMAC ( notification . notificationItems ! [ 0 ] , key ) ) . toBeFalsy ( ) ;
129
130
} ) ;
131
+
132
+ it ( "should calculate Banking webhook correctly" , function ( ) : void {
133
+ const data = fs . readFileSync ( './src/__mocks__/notification/accountHolderCreated.json' , 'utf8' ) ;
134
+ const encrypted = hmacValidator . calculateHmac ( data , "11223344D785FBAE710E7F943F307971BB61B21281C98C9129B3D4018A57B2EB" ) ;
135
+
136
+ expect ( encrypted ) . toEqual ( "UVBzHbDayhfT1XgaRGAkuKvxwoxrLoVCBdfi3WZU8lI=" ) ;
137
+ } ) ;
138
+
139
+ it ( "should validate Banking webhook correctly" , function ( ) : void {
140
+ const hmacKey = "11223344D785FBAE710E7F943F307971BB61B21281C98C9129B3D4018A57B2EB"
141
+ const hmacSignature = "UVBzHbDayhfT1XgaRGAkuKvxwoxrLoVCBdfi3WZU8lI="
142
+ const data = fs . readFileSync ( './src/__mocks__/notification/accountHolderCreated.json' , 'utf8' ) ;
143
+ const isValid = hmacValidator . validateHMACSignature ( hmacKey , hmacSignature , data ) ;
144
+
145
+ expect ( isValid ) . toBeTruthy
146
+ } ) ;
147
+
130
148
} ) ;
0 commit comments