File tree Expand file tree Collapse file tree 3 files changed +44
-2
lines changed
Expand file tree Collapse file tree 3 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ const { getCodiQrUrl } = require("./utils/getCodiQrUrl");
99const { getSellerApiKey } = require ( "./utils/getSellerApiKey" ) ;
1010const { verifySignature } = require ( "./utils/verifySignature" ) ;
1111const { getKeyCredentials } = require ( "./utils/getKeyCredentials" ) ;
12+ const { compareCrtBanxico } = require ( "./utils/compareCrtBanxico" ) ;
1213const { generateSignature } = require ( "./utils/generateDigitalSignature" ) ;
1314const { getBanxicoCredentials } = require ( "./utils/getBanxicoCredentials" ) ;
1415const { getDeveloperCredentials } = require ( "./utils/getDeveloperCredentials" ) ;
@@ -81,15 +82,19 @@ module.exports = {
8182 } ) ;
8283 }
8384
84- // Send the data
85+ // Send the data to Banxico
8586 const response = await axios . post ( codiApiQrEndpoint , requestBody , {
8687 headers : {
8788 "Content-Type" : "application/json; charset=utf-8" ,
8889 } ,
8990 } ) ;
9091 // console.log("\n🔵 Respuesta de Banxico: ", response.data);
9192
92- // Verify the signed data
93+ // Verify th crtBdeM value sent in response
94+ const crtBanxicoVerified = compareCrtBanxico ( crtBanxico , response . data ) ;
95+ // console.log("\n🔵 crtBdeM verificado: ", crtBanxicoVerified);
96+
97+ // Verify the signature: Banxico
9398 const responseIsVerified = verifySignature (
9499 response . data ,
95100 publicKeyBanxico
Original file line number Diff line number Diff line change 1+ function compareCrtBanxico ( crtBanxico , data ) {
2+ if ( crtBanxico === data . crtBdeM ) {
3+ return true ;
4+ } else {
5+ console . error (
6+ "Mismatch: data.crtBdeM does not match with crtBanxico public key"
7+ ) ;
8+ return false ;
9+ }
10+ }
11+
12+ module . exports = {
13+ compareCrtBanxico,
14+ } ;
Original file line number Diff line number Diff line change 1+ const { compareCrtBanxico } = require ( "../controllers/utils/compareCrtBanxico" ) ;
2+
3+ describe ( "compareCrtBanxico" , ( ) => {
4+ test ( "should return true when crtBanxico matches data.crtBdeM" , ( ) => {
5+ const crtBanxico = "00000100000100015974" ;
6+ const data = {
7+ crtBdeM : "00000100000100015974" ,
8+ } ;
9+ expect ( compareCrtBanxico ( crtBanxico , data ) ) . toBe ( true ) ;
10+ } ) ;
11+
12+ test ( "should return false and log error when crtBanxico does not match data.crtBdeM" , ( ) => {
13+ const crtBanxico = "00000100000100015974" ;
14+ const data = {
15+ crtBdeM : "00000100000100015975" ,
16+ } ;
17+ console . error = jest . fn ( ) ; // Mock console.error
18+ expect ( compareCrtBanxico ( crtBanxico , data ) ) . toBe ( false ) ;
19+ expect ( console . error ) . toHaveBeenCalledWith (
20+ "Mismatch: data.crtBdeM does not match with crtBanxico public key"
21+ ) ;
22+ } ) ;
23+ } ) ;
You can’t perform that action at this time.
0 commit comments