From c571ef181bca2e0cbec70bc6df53c706acd6c829 Mon Sep 17 00:00:00 2001 From: vasyas Date: Thu, 27 Jun 2019 00:10:53 +0300 Subject: [PATCH 1/2] tc for bank keys parsing error --- .eslintrc | 3 ++- package.json | 4 +++- test/responseParser.js | 43 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 test/responseParser.js diff --git a/.eslintrc b/.eslintrc index 6a9f7a9..c3147b5 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,7 +1,8 @@ { "extends": "airbnb-base", "env": { - "node": true + "node": true, + "mocha": true }, "parserOptions": { "ecmaVersion": 8, diff --git a/package.json b/package.json index 5fec538..16e256b 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,10 @@ "xpath": "0.0.27" }, "devDependencies": { + "chai": "^4.2.0", "eslint": "^4.19.1", "eslint-config-airbnb-base": "^12.1.0", - "eslint-plugin-import": "^2.12.0" + "eslint-plugin-import": "^2.12.0", + "mocha": "^6.1.4" } } diff --git a/test/responseParser.js b/test/responseParser.js new file mode 100644 index 0000000..05be3b3 --- /dev/null +++ b/test/responseParser.js @@ -0,0 +1,43 @@ +'use strict'; + +const { assert } = require('chai'); +const H004Response = require('../lib/orders/H004/response'); + +describe('H004 response parsing', () => { + it('parses bank keys', () => { + const response = H004Response('', {}); + + const x002mod = 'ntbX6WFjAJP5RyH4ogDG/26wZGzEJXsTudyvcgXmUdk1AExCNqArXDiSlGXpVNq4BKddUMFUmVOyvkdNckPRV2mk3uHNCE5T3tFKQI3FlwHSJHvPSpb9gtHnsK03jByMigWjhTKvsjIdfLVay5m5Bctxq9+5JMHwlNk7MlVXBQcqaFiHFFS1lPfA3Wk1bptPeeGyYcP0+U798oQWnCABKwS8hmYcp5xBtozGoRj9L/NDE68pdP8o/wTKNwT4Jo5nQKYfDsgO4R+z9vVv37Htp6bWhK8Jw3tpkcd3JnkYWx+Ylg0XBpg8LfjFhY2Jc7FqLlx0Bn0Y3PRLI1apxgC85w=='; + const e002mod = '4eOGrzcJHVzbEgZTmyPYUIq9kFoua8Ure1Mvyq6XlawFgCWskfu/xSKNLIMJ7H675wl/5y0Oy16P/b6pJEhWrzOw8omW46PBDTaXw9BDYBTuBblluz1yUnzpgfblP8gkRmxAo+QMIskmwdSzuZMiJcLNSzu/bkmLHK2RdrVYMAZLlB6QXTykdenPZtNmc2z4VU6TRmGljAwg2VUNF6iQoucbzDUuca+yUo3fiXZp69nfXv81X2ND+p1ir6zQpx7tbOdfauw0sEKI/Z/lC+E4fMrMlh/ZvOxSYUMA55J4liC3aUV3mTR3dPJHWu1aD1a7EfJnNw0eHLwlB+36qfgGuw=='; + + response.orderData = () => ` + + + + + ${x002mod} + AQAB + + 2015-02-25T08:01:13.061Z + + X002 + + + + + ${e002mod} + AQAB + + 2015-02-25T08:01:12.344Z + + E002 + + SBKPR01 + `; + + const bankKeys = response.bankKeys(); + + assert.equal(bankKeys.bankX002.mod.toString('base64'), x002mod); + assert.equal(bankKeys.bankE002.mod.toString('base64'), e002mod); + }); +}); From 5f0b6cd3747c4613920d2f71f3c04ce13225d397 Mon Sep 17 00:00:00 2001 From: vasyas Date: Thu, 27 Jun 2019 00:13:44 +0300 Subject: [PATCH 2/2] #2 corrected bank keys parsing --- lib/orders/H004/response.js | 4 ++-- test/responseParser.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/orders/H004/response.js b/lib/orders/H004/response.js index 7fb7a51..66239df 100644 --- a/lib/orders/H004/response.js +++ b/lib/orders/H004/response.js @@ -124,8 +124,8 @@ module.exports = (xml, keys) => ({ for (let i = 0; i < keyNodes.length; i++) { const type = lastChild(keyNodes[i].parentNode).textContent; - const modulus = xpath.select("//*[local-name(.)='Modulus']", keyNodes[i])[0].textContent; - const exponent = xpath.select("//*[local-name(.)='Exponent']", keyNodes[i])[0].textContent; + const modulus = xpath.select(".//*[local-name(.)='Modulus']", keyNodes[i])[0].textContent; + const exponent = xpath.select(".//*[local-name(.)='Exponent']", keyNodes[i])[0].textContent; const mod = new BN(Buffer.from(modulus, 'base64'), 2).toBuffer(); const exp = new BN(Buffer.from(exponent, 'base64')).toNumber(); diff --git a/test/responseParser.js b/test/responseParser.js index 05be3b3..a44eaa6 100644 --- a/test/responseParser.js +++ b/test/responseParser.js @@ -5,7 +5,7 @@ const H004Response = require('../lib/orders/H004/response'); describe('H004 response parsing', () => { it('parses bank keys', () => { - const response = H004Response('', {}); + const response = H004Response('', {}); const x002mod = 'ntbX6WFjAJP5RyH4ogDG/26wZGzEJXsTudyvcgXmUdk1AExCNqArXDiSlGXpVNq4BKddUMFUmVOyvkdNckPRV2mk3uHNCE5T3tFKQI3FlwHSJHvPSpb9gtHnsK03jByMigWjhTKvsjIdfLVay5m5Bctxq9+5JMHwlNk7MlVXBQcqaFiHFFS1lPfA3Wk1bptPeeGyYcP0+U798oQWnCABKwS8hmYcp5xBtozGoRj9L/NDE68pdP8o/wTKNwT4Jo5nQKYfDsgO4R+z9vVv37Htp6bWhK8Jw3tpkcd3JnkYWx+Ylg0XBpg8LfjFhY2Jc7FqLlx0Bn0Y3PRLI1apxgC85w=='; const e002mod = '4eOGrzcJHVzbEgZTmyPYUIq9kFoua8Ure1Mvyq6XlawFgCWskfu/xSKNLIMJ7H675wl/5y0Oy16P/b6pJEhWrzOw8omW46PBDTaXw9BDYBTuBblluz1yUnzpgfblP8gkRmxAo+QMIskmwdSzuZMiJcLNSzu/bkmLHK2RdrVYMAZLlB6QXTykdenPZtNmc2z4VU6TRmGljAwg2VUNF6iQoucbzDUuca+yUo3fiXZp69nfXv81X2ND+p1ir6zQpx7tbOdfauw0sEKI/Z/lC+E4fMrMlh/ZvOxSYUMA55J4liC3aUV3mTR3dPJHWu1aD1a7EfJnNw0eHLwlB+36qfgGuw==';