Skip to content

Commit

Permalink
Update request-logger@^2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui Marinho authored and joaopaulofonseca committed Nov 24, 2017
1 parent 9405dd8 commit c9eb658
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions src/logging/request-obfuscator.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ function obfuscateResponseBody(body, method) {
*/

function obfuscateResponse(request, instance) {
if (request.type !== 'response') {
return;
}

if (!get(request, 'response.body')) {
return;
}
Expand Down Expand Up @@ -79,6 +83,10 @@ function obfuscateRequestBody(body) {
*/

function obfuscateRequest(request) {
if (request.type !== 'request') {
return;
}

if (!isString(request.body)) {
return;
}
Expand All @@ -99,6 +107,10 @@ function obfuscateRequest(request) {
*/

function obfuscateHeaders(request) {
if (request.type !== 'request') {
return;
}

if (!has(request, 'headers.authorization')) {
return;
}
Expand Down
50 changes: 26 additions & 24 deletions test/logging/request-obfuscator_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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"]}]' });
Expand All @@ -119,7 +120,8 @@ describe('RequestObfuscator', () => {
{ id: '1485369469422-2', result: 'foobiz' },
{ id: '1485369469422-1', result: '******' }
]
}
},
type: 'response'
});
});
});
Expand Down
11 changes: 3 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit c9eb658

Please sign in to comment.