Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1456: Added extensions list object for unsupported version error #235

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions audit-resolve.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"decisions": {
"1523|@mojaloop/central-services-error-handling>lodash": {
"decision": "ignore",
"madeAt": 1593701985921,
"expiresAt": 1594306720364
},
"1523|@mojaloop/central-services-logger>winston>async>lodash": {
"decision": "ignore",
"madeAt": 1593701985921,
"expiresAt": 1594306720364
},
"1523|@mojaloop/event-sdk>@mojaloop/central-services-logger>winston>async>lodash": {
"decision": "ignore",
"madeAt": 1593701985921,
"expiresAt": 1594306720364
},
"1523|@mojaloop/event-sdk>winston>async>lodash": {
"decision": "ignore",
"madeAt": 1593701985921,
"expiresAt": 1594306720364
},
"1523|@mojaloop/event-sdk>lodash": {
"decision": "ignore",
"madeAt": 1593701985921,
"expiresAt": 1594306720364
},
"1523|lodash": {
"decision": "ignore",
"madeAt": 1593701985921,
"expiresAt": 1594306720364
},
"1523|openapi-backend>lodash": {
"decision": "ignore",
"madeAt": 1593701985921,
"expiresAt": 1594306720364
},
"1523|openapi-backend>mock-json-schema>lodash": {
"decision": "ignore",
"madeAt": 1593701985921,
"expiresAt": 1594306720364
}
},
"rules": {},
"version": 1
}
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/central-services-shared",
"version": "10.5.2",
"version": "10.5.3",
"description": "Shared code for central services",
"main": "src/index.js",
"scripts": {
Expand Down
7 changes: 5 additions & 2 deletions src/util/hapi/plugins/headerValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const defaultProtocolVersions = [
]

const errorMessages = {
REQUESTED_VERSION_NOT_SUPPORTED: 'Client requested to use a protocol version which is not supported by the server',
REQUESTED_VERSION_NOT_SUPPORTED: 'The Client requested an unsupported version, see extension list for supported version(s).',
INVALID_ACCEPT_HEADER: 'Invalid accept header',
INVALID_CONTENT_TYPE_HEADER: 'Invalid content-type header',
REQUIRE_ACCEPT_HEADER: 'Accept is required',
Expand Down Expand Up @@ -75,7 +75,10 @@ const plugin = {
if (!supportedProtocolVersions.some(supportedVer => accept.versions.has(supportedVer))) {
throw createFSPIOPError(
Enums.FSPIOPErrorCodes.UNACCEPTABLE_VERSION,
errorMessages.REQUESTED_VERSION_NOT_SUPPORTED
errorMessages.REQUESTED_VERSION_NOT_SUPPORTED,
null,
null,
protocolVersionsMap
)
}
}
Expand Down
7 changes: 5 additions & 2 deletions test/unit/util/hapi/plugins/headerValidation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const ErrorHandling = require('@mojaloop/central-services-error-handling')
const Test = require('tapes')(require('tape'))
const Sinon = require('sinon')
const { plugin, errorMessages } = require('../../../../../src/util/hapi/plugins/headerValidation')
const { protocolVersionsMap } = require('../../../../../src/util/headerValidation')
const {
generateAcceptHeader,
generateContentTypeHeader
Expand All @@ -46,8 +47,8 @@ const init = async () => {
// makes validation errors easier to inspect in server responses
server.ext('onPreResponse', (req, h) => {
if (req.response.name === 'FSPIOPError') {
const { message, apiErrorCode } = req.response
return h.response({ message, apiErrorCode }).code(apiErrorCode.httpStatusCode)
const { message, apiErrorCode, extensions } = req.response
return h.response({ message, apiErrorCode, extensions }).code(apiErrorCode.httpStatusCode)
}
return h.continue
})
Expand Down Expand Up @@ -173,6 +174,7 @@ Test('headerValidation plugin test', async (pluginTest) => {
const payload = JSON.parse(res.payload)
t.is(payload.apiErrorCode.code, fspiopCode.code)
t.is(payload.message, errorMessages.REQUESTED_VERSION_NOT_SUPPORTED)
t.deepEqual(payload.extensions, protocolVersionsMap)
t.end()
})

Expand Down Expand Up @@ -207,6 +209,7 @@ Test('headerValidation plugin test', async (pluginTest) => {
const payload = JSON.parse(res.payload)
t.is(payload.apiErrorCode.code, fspiopCode.code)
t.is(payload.message, errorMessages.SUPPLIED_VERSION_NOT_SUPPORTED)
t.deepEqual(payload.extensions, protocolVersionsMap)
t.end()
})

Expand Down