@@ -2,6 +2,7 @@ import HmacValidator from "../utils/hmacValidator";
22import { NotificationItem , NotificationRequestItem } from "../typings/notification/models" ;
33import { ApiConstants } from "../constants/apiConstants" ;
44import NotificationRequestService from "../notification/notificationRequest" ;
5+ const fs = require ( 'fs' ) ;
56
67const key = "DFB1EB5485895CFA84146406857104ABB4CBCABDC8AAF103A624C8F6A3EAAB00" ;
78const expectedSign = "ZNBPtI+oDyyRrLyD1XirkKnQgIAlFc07Vj27TeHsDRE=" ;
@@ -127,4 +128,21 @@ describe("HMAC Validator", function (): void {
127128 notification . notificationItems ! [ 0 ] . additionalData ! [ ApiConstants . HMAC_SIGNATURE ] = "notValidSign" ;
128129 expect ( hmacValidator . validateHMAC ( notification . notificationItems ! [ 0 ] , key ) ) . toBeFalsy ( ) ;
129130 } ) ;
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+
130148} ) ;
0 commit comments