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

Do not modify the request object is jwsSigner class #220

Merged
merged 2 commits into from
May 13, 2020
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
152 changes: 47 additions & 105 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/central-services-shared",
"version": "10.1.1",
"version": "10.1.2",
"description": "Shared code for central services",
"main": "src/index.js",
"scripts": {
Expand Down Expand Up @@ -43,7 +43,7 @@
"dependencies": {
"@hapi/catbox": "11.1.0",
"@hapi/catbox-memory": "5.0.0",
"@mojaloop/central-services-error-handling": "10.1.0",
"@mojaloop/central-services-error-handling": "10.2.0",
"@mojaloop/central-services-logger": "9.5.1",
"@mojaloop/central-services-metrics": "9.5.0",
"@mojaloop/event-sdk": "9.5.2",
Expand All @@ -60,7 +60,7 @@
"@hapi/hapi": "19.1.1",
"@hapi/joi": "17.1.1",
"@mojaloop/sdk-standard-components": "10.1.0",
"chance": "1.1.4",
"chance": "1.1.5",
"faucet": "0.0.1",
"npm-audit-resolver": "2.2.0",
"npm-check-updates": "5.0.0",
Expand All @@ -70,7 +70,7 @@
"rc": "1.2.8",
"rewire": "5.0.0",
"sinon": "9.0.2",
"standard": "14.3.3",
"standard": "14.3.4",
"tap-xunit": "2.4.1",
"tape": "5.0.0",
"tapes": "4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/util/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const sendRequest = async (url, headers, source, destination, method = enums.Htt
}
// if jwsSigner is passed then sign the request
if (jwsSigner != null && typeof (jwsSigner) === 'object') {
jwsSigner.sign(requestOptions)
requestOptions.headers['fspiop-signature'] = jwsSigner.getSignature(requestOptions)
}

if (span) {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/util/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ Test('ParticipantEndpoint Model Test', modelTest => {
})
request = sandbox.stub().returns({ status: 200 })
Model = proxyquire('../../../src/util/request', { axios: request })
const signSpy = Sinon.spy(jwsSigner, 'sign')
const signSpy = Sinon.spy(jwsSigner, 'getSignature')
await Model.sendRequest(requestOptions.url, requestOptions.headers, Enum.Http.HeaderResources.SWITCH, fsp, requestOptions.method, payload, Enum.Http.ResponseTypes.JSON, undefined, jwsSigner)
test.ok(signSpy.calledOnce, 'JwsSigner.sign is called once')
test.ok('fspiop-signature' in signSpy.getCall(0).firstArg.headers, 'The header has fspiop-signature')
Expand All @@ -221,7 +221,7 @@ Test('ParticipantEndpoint Model Test', modelTest => {
})
request = sandbox.stub().returns({ status: 200 })
Model = proxyquire('../../../src/util/request', { axios: request })
const signSpy = Sinon.spy(jwsSigner, 'sign')
const signSpy = Sinon.spy(jwsSigner, 'getSignature')
await Model.sendRequest(requestOptions.url, requestOptions.headers, Enum.Http.HeaderResources.SWITCH, fsp, requestOptions.method, payload, Enum.Http.ResponseTypes.JSON, undefined, undefined)
test.equal(signSpy.callCount, 0, 'JwsSigner.sign is NOT called')
test.end()
Expand Down