From 11b1a469c68e9df3a0dc93309f933dc4b9d8f56c Mon Sep 17 00:00:00 2001 From: Vassilis Barzokas Date: Tue, 17 Mar 2020 18:36:28 +0200 Subject: [PATCH 1/6] Modified `forwardQuoteUpdate` so it handles special cases where it doesn't need to modify/set the headers. --- src/model/quotes.js | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/model/quotes.js b/src/model/quotes.js index 898219ae..f6d02675 100644 --- a/src/model/quotes.js +++ b/src/model/quotes.js @@ -611,7 +611,7 @@ class QuotesModel { // we didnt get an endpoint for the payee dfsp! // make an error callback to the initiator const fspiopError = ErrorHandler.CreateFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.DESTINATION_FSP_ERROR, `No FSPIOP_CALLBACK_URL_QUOTES found for quote ${quoteId} PAYER party`, null, fspiopSource) - return this.sendErrorCallback(fspiopSource, fspiopError, quoteId, headers) + return this.sendErrorCallback(fspiopSource, fspiopError, quoteId, headers, false) } const fullCallbackUrl = `${endpoint}/quotes/${quoteId}` @@ -709,7 +709,7 @@ class QuotesModel { const fspiopError = ErrorHandler.CreateFSPIOPErrorFromErrorInformation(error) // Needed to add await here to prevent 'span already finished' bug - await this.sendErrorCallback(headers[ENUM.Http.Headers.FSPIOP.DESTINATION], fspiopError, quoteId, headers, span) + await this.sendErrorCallback(headers[ENUM.Http.Headers.FSPIOP.DESTINATION], fspiopError, quoteId, headers, span, true) return newError } catch (err) { @@ -826,7 +826,7 @@ class QuotesModel { const childSpan = span.getChild('qs_quote_sendErrorCallback') try { await childSpan.audit({ headers, params: { quoteId } }, EventSdk.AuditEventAction.start) - return await this.sendErrorCallback(fspiopSource, fspiopError, quoteId, headers, childSpan) + return await this.sendErrorCallback(fspiopSource, fspiopError, quoteId, headers, childSpan, true) } catch (err) { // any-error // not much we can do other than log the error @@ -845,7 +845,7 @@ class QuotesModel { * * @returns {promise} */ - async sendErrorCallback (fspiopSource, fspiopError, quoteId, headers, span) { + async sendErrorCallback (fspiopSource, fspiopError, quoteId, headers, span, modifyHeaders = true) { const envConfig = new Config() const fspiopDest = headers[ENUM.Http.Headers.FSPIOP.DESTINATION] try { @@ -867,12 +867,23 @@ class QuotesModel { this.writeLog(`Making error callback to participant '${fspiopSource}' for quoteId '${quoteId}' to ${fullCallbackUrl} for error: ${util.inspect(fspiopError.toFullErrorObject())}`) // make an error callback - const fromSwitchHeaders = Object.assign({}, headers, { - 'fspiop-destination': fspiopSource, - 'fspiop-source': ENUM.Http.Headers.FSPIOP.SWITCH.value, - 'fspiop-http-method': ENUM.Http.RestMethods.PUT, - 'fspiop-uri': fspiopUri - }) + let fromSwitchHeaders + + // modify/set the headers only in case it is explicitly requested to do so + // as this part needs to cover two different cases: + // 1. (do not modify them) when the Switch needs to relay an error, e.g. from a DFSP to another + // 2. (modify/set them) when the Switch needs send errors that are originating in the Switch, e.g. to send an error back to the caller + if (modifyHeaders === true) { + fromSwitchHeaders = Object.assign({}, headers, { + 'fspiop-destination': fspiopSource, + 'fspiop-source': ENUM.Http.Headers.FSPIOP.SWITCH.value, + 'fspiop-http-method': ENUM.Http.RestMethods.PUT, + 'fspiop-uri': fspiopUri + }) + } else { + fromSwitchHeaders = Object.assign({}, headers) + } + let opts = { method: ENUM.Http.RestMethods.PUT, url: fullCallbackUrl, From 67c102f53cfa11bef114f138f925943ca4aefdc0 Mon Sep 17 00:00:00 2001 From: Vassilis Barzokas Date: Tue, 17 Mar 2020 18:38:39 +0200 Subject: [PATCH 2/6] Bumped to 9.3.4-snapshot; Added myself to the hall of fame. --- package-lock.json | 41 +++++++++++++++++------------------------ package.json | 5 +++-- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1a5c8ce4..c534d6cb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "quoting-service", - "version": "9.3.3-snapshot", + "version": "9.3.4-snapshot", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2295,9 +2295,9 @@ "integrity": "sha512-tsFzPpcttalNjFBCFMqsKYQcWxxen1pgJR56by//QwvJc4/OUS3kPOOttx2tSIfjsylB0pYu7f5D3K1RCxUnUg==" }, "acorn": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz", - "integrity": "sha512-kL5CuoXA/dgxlBbVrflsflzQ3PAas7RYZB52NOm/6839iVYJgKMJ3cQJD+t2i5+qFa8h3MDpEOJiS64E8JLnSQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.1.tgz", + "integrity": "sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg==", "dev": true }, "acorn-globals": { @@ -2311,9 +2311,9 @@ }, "dependencies": { "acorn": { - "version": "6.4.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.0.tgz", - "integrity": "sha512-gac8OEcQ2Li1dxIEWGZzsp2BitJxwkwcOm0zHAJLcPJaVvm58FRnk6RkuLRpU1EujipU2ZFODv2P9DLMfnV8mw==", + "version": "6.4.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.1.tgz", + "integrity": "sha512-ZVA9k326Nwrj3Cj9jlh3wGFutC2ZornPNARZwsNYqQYgN0EsV2d53w5RN/co65Ohn4sUAUtb1rSUAOD6XN9idA==", "dev": true } } @@ -9830,9 +9830,9 @@ } }, "kind-of": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", - "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==" + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", + "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==" }, "kleur": { "version": "3.0.3", @@ -10262,9 +10262,9 @@ } }, "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" }, "minipass": { "version": "3.1.1", @@ -10364,18 +10364,11 @@ } }, "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.3.tgz", + "integrity": "sha512-P+2gwrFqx8lhew375MQHHeTlY8AuOJSrGf0R5ddkEndUkmwpgUob/vQuBD1V22/Cw1/lJr4x+EjllSezBThzBg==", "requires": { - "minimist": "0.0.8" - }, - "dependencies": { - "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" - } + "minimist": "^1.2.5" } }, "module-not-found-error": { diff --git a/package.json b/package.json index 389e6801..f1cb3ad4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "quoting-service", "description": "Quoting Service hosted by a scheme", "license": "Apache-2.0", - "version": "9.3.3-snapshot", + "version": "9.3.4-snapshot", "author": "Modusbox", "contributors": [ "James Bush ", @@ -10,7 +10,8 @@ "Henk Kodde ", "Miguel de Barros ", "Rajiv Mothilal ", - "Steven Oderayi " + "Steven Oderayi ", + "Vassilis Barzokas " ], "repository": { "type": "git", From a321459050a0699766cbe307cb287dd57d54aeb7 Mon Sep 17 00:00:00 2001 From: Vassilis Barzokas Date: Tue, 17 Mar 2020 18:49:52 +0200 Subject: [PATCH 3/6] Updated unit tests. --- test/unit/model/quotes.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/model/quotes.test.js b/test/unit/model/quotes.test.js index 023b9ab1..14468c9a 100644 --- a/test/unit/model/quotes.test.js +++ b/test/unit/model/quotes.test.js @@ -1836,7 +1836,7 @@ describe('QuotesModel', () => { const result = await quotesModel.handleException('payeefsp', mockData.quoteId, error, mockData.headers, mockSpan) // Assert - expect(quotesModel.sendErrorCallback).toHaveBeenCalledWith('payeefsp', expectedError, mockData.quoteId, mockData.headers, mockChildSpan) + expect(quotesModel.sendErrorCallback).toHaveBeenCalledWith('payeefsp', expectedError, mockData.quoteId, mockData.headers, mockChildSpan, true) expect(result).toBe(true) expect(mockChildSpan.finish).toHaveBeenCalledTimes(1) }) @@ -1852,7 +1852,7 @@ describe('QuotesModel', () => { await quotesModel.handleException('payeefsp', mockData.quoteId, error, mockData.headers, mockSpan) // Assert - expect(quotesModel.sendErrorCallback).toHaveBeenCalledWith('payeefsp', expectedError, mockData.quoteId, mockData.headers, mockChildSpan) + expect(quotesModel.sendErrorCallback).toHaveBeenCalledWith('payeefsp', expectedError, mockData.quoteId, mockData.headers, mockChildSpan, true) expect(quotesModel.writeLog).toHaveBeenCalledTimes(1) expect(mockChildSpan.finish).toHaveBeenCalledTimes(1) }) From c21ca3f9875fe133674eb17059923da0ae4716d2 Mon Sep 17 00:00:00 2001 From: Vassilis Barzokas Date: Tue, 17 Mar 2020 18:52:53 +0200 Subject: [PATCH 4/6] Changed bumped version to 9.4.0 to cope with the current versioning status. --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index c534d6cb..d9bec447 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "quoting-service", - "version": "9.3.4-snapshot", + "version": "9.4.0-snapshot", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index f1cb3ad4..91dcd94d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "quoting-service", "description": "Quoting Service hosted by a scheme", "license": "Apache-2.0", - "version": "9.3.4-snapshot", + "version": "9.4.0-snapshot", "author": "Modusbox", "contributors": [ "James Bush ", From ad1ab4f9a38cdb567574c00cfe351f7743de648c Mon Sep 17 00:00:00 2001 From: Vassilis Barzokas Date: Tue, 17 Mar 2020 19:18:34 +0200 Subject: [PATCH 5/6] Changed the places where the sendErrorCallback is called with `true` flag. --- src/model/quotes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/model/quotes.js b/src/model/quotes.js index f6d02675..a66f5171 100644 --- a/src/model/quotes.js +++ b/src/model/quotes.js @@ -611,7 +611,7 @@ class QuotesModel { // we didnt get an endpoint for the payee dfsp! // make an error callback to the initiator const fspiopError = ErrorHandler.CreateFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.DESTINATION_FSP_ERROR, `No FSPIOP_CALLBACK_URL_QUOTES found for quote ${quoteId} PAYER party`, null, fspiopSource) - return this.sendErrorCallback(fspiopSource, fspiopError, quoteId, headers, false) + return this.sendErrorCallback(fspiopSource, fspiopError, quoteId, headers, true) } const fullCallbackUrl = `${endpoint}/quotes/${quoteId}` @@ -709,7 +709,7 @@ class QuotesModel { const fspiopError = ErrorHandler.CreateFSPIOPErrorFromErrorInformation(error) // Needed to add await here to prevent 'span already finished' bug - await this.sendErrorCallback(headers[ENUM.Http.Headers.FSPIOP.DESTINATION], fspiopError, quoteId, headers, span, true) + await this.sendErrorCallback(headers[ENUM.Http.Headers.FSPIOP.DESTINATION], fspiopError, quoteId, headers, span, false) return newError } catch (err) { From 2a7126422eeca9e3ead4f13b96f87a6fc6e747f7 Mon Sep 17 00:00:00 2001 From: Vassilis Barzokas Date: Tue, 17 Mar 2020 19:23:30 +0200 Subject: [PATCH 6/6] run `npm run audit:resolve` and skipped for a week. --- audit-resolve.json | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/audit-resolve.json b/audit-resolve.json index 1b66561b..76ba2fbf 100644 --- a/audit-resolve.json +++ b/audit-resolve.json @@ -4,6 +4,36 @@ "decision": "ignore", "madeAt": 1582635042880, "expiresAt": 1583239828928 + }, + "1179|@mojaloop/central-services-shared>@mojaloop/event-sdk>grpc>node-pre-gyp>mkdirp>minimist": { + "decision": "ignore", + "madeAt": 1584465779331, + "expiresAt": 1585070560179 + }, + "1179|@mojaloop/event-sdk>grpc>node-pre-gyp>mkdirp>minimist": { + "decision": "ignore", + "madeAt": 1584465779331, + "expiresAt": 1585070560179 + }, + "1179|@mojaloop/central-services-shared>@mojaloop/event-sdk>grpc>node-pre-gyp>tar>mkdirp>minimist": { + "decision": "ignore", + "madeAt": 1584465779331, + "expiresAt": 1585070560179 + }, + "1179|@mojaloop/event-sdk>grpc>node-pre-gyp>tar>mkdirp>minimist": { + "decision": "ignore", + "madeAt": 1584465779331, + "expiresAt": 1585070560179 + }, + "1179|@mojaloop/central-services-shared>@mojaloop/event-sdk>grpc>node-pre-gyp>rc>minimist": { + "decision": "ignore", + "madeAt": 1584465779331, + "expiresAt": 1585070560179 + }, + "1179|@mojaloop/event-sdk>grpc>node-pre-gyp>rc>minimist": { + "decision": "ignore", + "madeAt": 1584465779331, + "expiresAt": 1585070560179 } }, "rules": {},