From c9eb6584a85c66cb1cb71453498ddc80ad3b2759 Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Fri, 24 Nov 2017 11:29:58 +0000 Subject: [PATCH] Update request-logger@^2.0.0 --- package.json | 2 +- src/logging/request-obfuscator.js | 12 ++++++ test/logging/request-obfuscator_test.js | 50 +++++++++++++------------ yarn.lock | 11 ++---- 4 files changed, 42 insertions(+), 33 deletions(-) diff --git a/package.json b/package.json index ccb3f7b..e60ae14 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "version": "npm run changelog --future-release=$npm_package_version && npm run transpile && git add -A CHANGELOG.md dist" }, "dependencies": { - "@uphold/request-logger": "^1.2.0", + "@uphold/request-logger": "^2.0.0", "bluebird": "^3.4.1", "debugnyan": "^1.0.0", "json-bigint": "^0.2.0", diff --git a/src/logging/request-obfuscator.js b/src/logging/request-obfuscator.js index 88587b5..1259c86 100644 --- a/src/logging/request-obfuscator.js +++ b/src/logging/request-obfuscator.js @@ -31,6 +31,10 @@ function obfuscateResponseBody(body, method) { */ function obfuscateResponse(request, instance) { + if (request.type !== 'response') { + return; + } + if (!get(request, 'response.body')) { return; } @@ -79,6 +83,10 @@ function obfuscateRequestBody(body) { */ function obfuscateRequest(request) { + if (request.type !== 'request') { + return; + } + if (!isString(request.body)) { return; } @@ -99,6 +107,10 @@ function obfuscateRequest(request) { */ function obfuscateHeaders(request) { + if (request.type !== 'request') { + return; + } + if (!has(request, 'headers.authorization')) { return; } diff --git a/test/logging/request-obfuscator_test.js b/test/logging/request-obfuscator_test.js index 8ef2c47..9960b53 100644 --- a/test/logging/request-obfuscator_test.js +++ b/test/logging/request-obfuscator_test.js @@ -12,91 +12,91 @@ import { obfuscate } from '../../src/logging/request-obfuscator'; describe('RequestObfuscator', () => { describe('obfuscate', () => { it('should not obfuscate `request.body.params` when `method` is not listed for obfuscation', () => { - const request = { body: '{"id":"1485369469422","method":"foo","params":["foobar"]}' }; + const request = { body: '{"id":"1485369469422","method":"foo","params":["foobar"]}', type: 'request' }; obfuscate(request); - request.should.eql({ body: '{"id":"1485369469422","method":"foo","params":["foobar"]}' }); + request.body.should.eql('{"id":"1485369469422","method":"foo","params":["foobar"]}'); }); it('should obfuscate the authorization header', () => { - const request = { headers: { authorization: 'Basic ==foobar' } }; + const request = { headers: { authorization: 'Basic ==foobar' }, type: 'request' }; obfuscate(request); - request.should.eql({ headers: { authorization: 'Basic ******' } }); + request.headers.should.eql({ authorization: 'Basic ******' }); }); it('should obfuscate all private keys from `request.body` when `method` is `importmulti`', () => { - const request = { body: '{"id":"1485369469422","method":"importmulti","params":[[{"address":"foobar","keys":["myprivate1","myprivate2"]},{"address":"foobar2","keys":["myprivate1","myprivate2"]}]]}' }; + const request = { body: '{"id":"1485369469422","method":"importmulti","params":[[{"address":"foobar","keys":["myprivate1","myprivate2"]},{"address":"foobar2","keys":["myprivate1","myprivate2"]}]]}', type: 'request' }; obfuscate(request); - request.should.eql({ body: '{"id":"1485369469422","method":"importmulti","params":[[{"address":"foobar","keys":["******","******"]},{"address":"foobar2","keys":["******","******"]}]]}' }); + request.body.should.eql('{"id":"1485369469422","method":"importmulti","params":[[{"address":"foobar","keys":["******","******"]},{"address":"foobar2","keys":["******","******"]}]]}'); }); it('should obfuscate the private key from `request.body` when `method` is `importprivkey`', () => { - const request = { body: '{"id":"1485369469422","method":"importprivkey","params":["foobar"]}' }; + const request = { body: '{"id":"1485369469422","method":"importprivkey","params":["foobar"]}', type: 'request' }; obfuscate(request); - request.should.eql({ body: '{"id":"1485369469422","method":"importprivkey","params":["******"]}' }); + request.body.should.eql('{"id":"1485369469422","method":"importprivkey","params":["******"]}'); }); it('should obfuscate the private key from `request.body` when `method` is `signmessagewithprivkey`', () => { - const request = { body: '{"id":"1485369469422","method":"signmessagewithprivkey","params":["foobar", "foobiz"]}' }; + const request = { body: '{"id":"1485369469422","method":"signmessagewithprivkey","params":["foobar", "foobiz"]}', type: 'request' }; obfuscate(request); - request.should.eql({ body: '{"id":"1485369469422","method":"signmessagewithprivkey","params":["******","foobiz"]}' }); + request.body.should.eql('{"id":"1485369469422","method":"signmessagewithprivkey","params":["******","foobiz"]}'); }); it('should obfuscate all private keys from `request.body` when `method` is `signrawtransaction`', () => { - const request = { body: '{"id":"1485369469422","method":"signrawtransaction","params":["foo","bar",["biz", "boz"]]}' }; + const request = { body: '{"id":"1485369469422","method":"signrawtransaction","params":["foo","bar",["biz", "boz"]]}', type: 'request' }; obfuscate(request); - request.should.eql({ body: '{"id":"1485369469422","method":"signrawtransaction","params":["foo","bar",["******","******"]]}' }); + request.body.should.eql('{"id":"1485369469422","method":"signrawtransaction","params":["foo","bar",["******","******"]]}'); }); it('should obfuscate the passphrase from `request.body` when `method` is `encryptwallet`', () => { - const request = { body: '{"id":"1485369469422","method":"encryptwallet","params":["foobar"]}' }; + const request = { body: '{"id":"1485369469422","method":"encryptwallet","params":["foobar"]}', type: 'request' }; obfuscate(request); - request.should.eql({ body: '{"id":"1485369469422","method":"encryptwallet","params":["******"]}' }); + request.body.should.eql('{"id":"1485369469422","method":"encryptwallet","params":["******"]}'); }); it('should obfuscate the passphrase from `request.body` when `method` is `walletpassphrase`', () => { - const request = { body: '{"id":"1485369469422","method":"walletpassphrase","params":["foobar"]}' }; + const request = { body: '{"id":"1485369469422","method":"walletpassphrase","params":["foobar"]}', type: 'request' }; obfuscate(request); - request.should.eql({ body: '{"id":"1485369469422","method":"walletpassphrase","params":["******"]}' }); + request.body.should.eql('{"id":"1485369469422","method":"walletpassphrase","params":["******"]}'); }); it('should obfuscate the `request.body` of a batch request', () => { - const request = { body: '[{"id":"1485369469422","method":"walletpassphrase","params":["foobar"]},{"id":"1485369469423","method":"walletpassphrase","params":["foobar"]}]' }; + const request = { body: '[{"id":"1485369469422","method":"walletpassphrase","params":["foobar"]},{"id":"1485369469423","method":"walletpassphrase","params":["foobar"]}]', type: 'request' }; obfuscate(request); - request.should.eql({ body: '[{"id":"1485369469422","method":"walletpassphrase","params":["******"]},{"id":"1485369469423","method":"walletpassphrase","params":["******"]}]' }); + request.body.should.eql('[{"id":"1485369469422","method":"walletpassphrase","params":["******"]},{"id":"1485369469423","method":"walletpassphrase","params":["******"]}]'); }); it('should obfuscate the private key from `response.body` when `method` is `dumpprivkey`', () => { - const request = { response: { body: { id: '1485369469422-0', result: 'foobiz' } } }; + const request = { response: { body: { id: '1485369469422-0', result: 'foobiz' } }, type: 'response' }; obfuscate(request, { body: '{"id":"1485369469422","method":"dumpprivkey","params":["foobar"]}' }); - request.should.eql({ response: { body: { id: '1485369469422-0', result: '******' } } }); + request.response.body.should.eql({ id: '1485369469422-0', result: '******' }); }); it('should obfuscate the `response.body` when `headers.content-type` is `application/octet-stream`', () => { - const request = { response: { body: new Buffer('foobar'), headers: { 'content-type': 'application/octet-stream' } } }; + const request = { response: { body: new Buffer('foobar'), headers: { 'content-type': 'application/octet-stream' } }, type: 'response' }; obfuscate(request, { uri: 'foobar.bin' }); - request.should.eql({ response: { body: '******', headers: { 'content-type': 'application/octet-stream' } } }); + request.response.should.eql({ body: '******', headers: { 'content-type': 'application/octet-stream' } }); }); it('should obfuscate the `request.response.body` of a batch request', () => { @@ -107,7 +107,8 @@ describe('RequestObfuscator', () => { { id: '1485369469422-2', result: 'foobiz' }, { id: '1485369469422-1', result: 'foo' } ] - } + }, + type: 'response' }; obfuscate(request, { body: '[{"id":"1485369469422-0","method":"dumpprivkey","params":["foobar"]},{"id":"1485369469422-2","method":"getnewaddress","params":["foobiz"]},{"id":"1485369469422-1","method":"dumpprivkey","params":["foobiz"]}]' }); @@ -119,7 +120,8 @@ describe('RequestObfuscator', () => { { id: '1485369469422-2', result: 'foobiz' }, { id: '1485369469422-1', result: '******' } ] - } + }, + type: 'response' }); }); }); diff --git a/yarn.lock b/yarn.lock index 6ae199f..e3d3971 100644 --- a/yarn.lock +++ b/yarn.lock @@ -457,11 +457,10 @@ lodash "^4.2.0" to-fast-properties "^2.0.0" -"@uphold/request-logger@^1.2.0": - version "1.2.0" - resolved "https://registry.yarnpkg.com/@uphold/request-logger/-/request-logger-1.2.0.tgz#e406893711e3de0369553155075890bec064a073" +"@uphold/request-logger@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@uphold/request-logger/-/request-logger-2.0.0.tgz#c585c0bdb94210198945c6597e4fe23d6e63e084" dependencies: - lodash.clonedeep "^4.5.0" uuid "^3.0.1" abbrev@1: @@ -2011,10 +2010,6 @@ locate-path@^2.0.0: p-locate "^2.0.0" path-exists "^3.0.0" -lodash.clonedeep@^4.5.0: - version "4.5.0" - resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef" - lodash@^4.0.0, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0, lodash@~4.17.2: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"