Skip to content

Commit

Permalink
fixed resource api version to be changed only if message originates f…
Browse files Browse the repository at this point in the history
…rom the switch (#241)

Co-authored-by: Valentin <[email protected]>
  • Loading branch information
vgenev and Valentin authored Sep 21, 2020
1 parent 7021d02 commit 5c4a6db
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 70 deletions.
118 changes: 59 additions & 59 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "quoting-service",
"description": "Quoting Service hosted by a scheme",
"license": "Apache-2.0",
"version": "11.1.0",
"version": "11.1.1",
"author": "ModusBox",
"contributors": [
"James Bush <[email protected]>",
Expand Down Expand Up @@ -62,7 +62,7 @@
"@hapi/hapi": "20.0.0",
"@mojaloop/central-services-error-handling": "10.6.0",
"@mojaloop/central-services-logger": "10.6.0",
"@mojaloop/central-services-shared": "11.3.3",
"@mojaloop/central-services-shared": "11.3.5",
"@mojaloop/event-sdk": "10.6.0",
"@mojaloop/ml-number": "8.2.0",
"@mojaloop/sdk-standard-components": "10.3.2",
Expand All @@ -81,12 +81,12 @@
"rc": "1.2.8"
},
"devDependencies": {
"@types/jest": "26.0.13",
"eslint": "7.8.1",
"@types/jest": "26.0.14",
"eslint": "7.9.0",
"jest": "26.4.2",
"jest-junit": "11.1.0",
"npm-audit-resolver": "2.2.1",
"npm-check-updates": "8.1.1",
"npm-check-updates": "9.0.1",
"nyc": "15.1.0",
"pre-commit": "1.2.2",
"proxyquire": "2.1.3",
Expand Down
22 changes: 17 additions & 5 deletions src/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,27 @@ function removeEmptyKeys (originalObject) {
return obj
}

function applyResourceVersionHeaders (headers) {
let contentTypeHeader = headers['content-type'] || headers['Content-Type']
let acceptHeader = headers.accept || headers.Accept
if (Enum.Http.Headers.FSPIOP.SWITCH.regex.test(headers['fspiop-source'])) {
if (Enum.Http.Headers.GENERAL.CONTENT_TYPE.regex.test(contentTypeHeader) && !!resourceVersions.quotes.contentVersion) {
contentTypeHeader = `application/vnd.interoperability.quotes+json;version=${resourceVersions.quotes.contentVersion}`
}
if (Enum.Http.Headers.GENERAL.ACCEPT.regex.test(acceptHeader) && !!resourceVersions.quotes.acceptVersion) {
acceptHeader = `application/vnd.interoperability.quotes+json;version=${resourceVersions.quotes.acceptVersion}`
}
}
return { contentTypeHeader, acceptHeader }
}

/**
* Generates and returns an object containing API spec compliant HTTP request headers
*
* @returns {object}
*/
function generateRequestHeaders (headers, noAccept) {
let contentTypeHeader = headers['content-type'] || headers['Content-Type']
if (Enum.Http.Headers.GENERAL.CONTENT_TYPE.regex.test(contentTypeHeader) && !!resourceVersions.quotes.contentVersion) {
contentTypeHeader = `application/vnd.interoperability.quotes+json;version=${resourceVersions.quotes.contentVersion}`
}
const { contentTypeHeader } = applyResourceVersionHeaders(headers)
const ret = {
'Content-Type': contentTypeHeader,
Date: headers.date,
Expand All @@ -154,8 +165,9 @@ function generateRequestHeaders (headers, noAccept) {
* @returns {object}
*/
function generateRequestHeadersForJWS (headers, noAccept) {
const { contentTypeHeader } = applyResourceVersionHeaders(headers)
const ret = {
'Content-Type': headers['content-type'] || headers['Content-Type'],
'Content-Type': contentTypeHeader,
date: headers.date,
'fspiop-source': headers['fspiop-source'],
'fspiop-destination': headers['fspiop-destination'],
Expand Down
2 changes: 1 addition & 1 deletion src/model/bulkQuotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class BulkQuotesModel {
const fspiopDestination = headers[ENUM.Http.Headers.FSPIOP.DESTINATION]

// validate - this will throw if the request is invalid
await this.validateBulkQuoteRequest(fspiopSource, fspiopDestination, bulkQuoteRequest)
childSpan = span.getChild('qs_bulkquote_forwardBulkQuoteRequest')
await this.validateBulkQuoteRequest(fspiopSource, fspiopDestination, bulkQuoteRequest)
// if we got here rules passed, so we can forward the quote on to the recipient dfsp
await childSpan.audit({ headers, payload: bulkQuoteRequest }, EventSdk.AuditEventAction.start)
await this.forwardBulkQuoteRequest(headers, bulkQuoteRequest.bulkQuoteId, bulkQuoteRequest, childSpan)
Expand Down

0 comments on commit 5c4a6db

Please sign in to comment.