Skip to content

Commit c9eb658

Browse files
Rui Marinhojoaopaulofonseca
Rui Marinho
authored andcommitted
Update request-logger@^2.0.0
1 parent 9405dd8 commit c9eb658

File tree

4 files changed

+42
-33
lines changed

4 files changed

+42
-33
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"version": "npm run changelog --future-release=$npm_package_version && npm run transpile && git add -A CHANGELOG.md dist"
3535
},
3636
"dependencies": {
37-
"@uphold/request-logger": "^1.2.0",
37+
"@uphold/request-logger": "^2.0.0",
3838
"bluebird": "^3.4.1",
3939
"debugnyan": "^1.0.0",
4040
"json-bigint": "^0.2.0",

src/logging/request-obfuscator.js

+12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ function obfuscateResponseBody(body, method) {
3131
*/
3232

3333
function obfuscateResponse(request, instance) {
34+
if (request.type !== 'response') {
35+
return;
36+
}
37+
3438
if (!get(request, 'response.body')) {
3539
return;
3640
}
@@ -79,6 +83,10 @@ function obfuscateRequestBody(body) {
7983
*/
8084

8185
function obfuscateRequest(request) {
86+
if (request.type !== 'request') {
87+
return;
88+
}
89+
8290
if (!isString(request.body)) {
8391
return;
8492
}
@@ -99,6 +107,10 @@ function obfuscateRequest(request) {
99107
*/
100108

101109
function obfuscateHeaders(request) {
110+
if (request.type !== 'request') {
111+
return;
112+
}
113+
102114
if (!has(request, 'headers.authorization')) {
103115
return;
104116
}

test/logging/request-obfuscator_test.js

+26-24
Original file line numberDiff line numberDiff line change
@@ -12,91 +12,91 @@ import { obfuscate } from '../../src/logging/request-obfuscator';
1212
describe('RequestObfuscator', () => {
1313
describe('obfuscate', () => {
1414
it('should not obfuscate `request.body.params` when `method` is not listed for obfuscation', () => {
15-
const request = { body: '{"id":"1485369469422","method":"foo","params":["foobar"]}' };
15+
const request = { body: '{"id":"1485369469422","method":"foo","params":["foobar"]}', type: 'request' };
1616

1717
obfuscate(request);
1818

19-
request.should.eql({ body: '{"id":"1485369469422","method":"foo","params":["foobar"]}' });
19+
request.body.should.eql('{"id":"1485369469422","method":"foo","params":["foobar"]}');
2020
});
2121

2222
it('should obfuscate the authorization header', () => {
23-
const request = { headers: { authorization: 'Basic ==foobar' } };
23+
const request = { headers: { authorization: 'Basic ==foobar' }, type: 'request' };
2424

2525
obfuscate(request);
2626

27-
request.should.eql({ headers: { authorization: 'Basic ******' } });
27+
request.headers.should.eql({ authorization: 'Basic ******' });
2828
});
2929

3030
it('should obfuscate all private keys from `request.body` when `method` is `importmulti`', () => {
31-
const request = { body: '{"id":"1485369469422","method":"importmulti","params":[[{"address":"foobar","keys":["myprivate1","myprivate2"]},{"address":"foobar2","keys":["myprivate1","myprivate2"]}]]}' };
31+
const request = { body: '{"id":"1485369469422","method":"importmulti","params":[[{"address":"foobar","keys":["myprivate1","myprivate2"]},{"address":"foobar2","keys":["myprivate1","myprivate2"]}]]}', type: 'request' };
3232

3333
obfuscate(request);
3434

35-
request.should.eql({ body: '{"id":"1485369469422","method":"importmulti","params":[[{"address":"foobar","keys":["******","******"]},{"address":"foobar2","keys":["******","******"]}]]}' });
35+
request.body.should.eql('{"id":"1485369469422","method":"importmulti","params":[[{"address":"foobar","keys":["******","******"]},{"address":"foobar2","keys":["******","******"]}]]}');
3636
});
3737

3838
it('should obfuscate the private key from `request.body` when `method` is `importprivkey`', () => {
39-
const request = { body: '{"id":"1485369469422","method":"importprivkey","params":["foobar"]}' };
39+
const request = { body: '{"id":"1485369469422","method":"importprivkey","params":["foobar"]}', type: 'request' };
4040

4141
obfuscate(request);
4242

43-
request.should.eql({ body: '{"id":"1485369469422","method":"importprivkey","params":["******"]}' });
43+
request.body.should.eql('{"id":"1485369469422","method":"importprivkey","params":["******"]}');
4444
});
4545

4646
it('should obfuscate the private key from `request.body` when `method` is `signmessagewithprivkey`', () => {
47-
const request = { body: '{"id":"1485369469422","method":"signmessagewithprivkey","params":["foobar", "foobiz"]}' };
47+
const request = { body: '{"id":"1485369469422","method":"signmessagewithprivkey","params":["foobar", "foobiz"]}', type: 'request' };
4848

4949
obfuscate(request);
5050

51-
request.should.eql({ body: '{"id":"1485369469422","method":"signmessagewithprivkey","params":["******","foobiz"]}' });
51+
request.body.should.eql('{"id":"1485369469422","method":"signmessagewithprivkey","params":["******","foobiz"]}');
5252
});
5353

5454
it('should obfuscate all private keys from `request.body` when `method` is `signrawtransaction`', () => {
55-
const request = { body: '{"id":"1485369469422","method":"signrawtransaction","params":["foo","bar",["biz", "boz"]]}' };
55+
const request = { body: '{"id":"1485369469422","method":"signrawtransaction","params":["foo","bar",["biz", "boz"]]}', type: 'request' };
5656

5757
obfuscate(request);
5858

59-
request.should.eql({ body: '{"id":"1485369469422","method":"signrawtransaction","params":["foo","bar",["******","******"]]}' });
59+
request.body.should.eql('{"id":"1485369469422","method":"signrawtransaction","params":["foo","bar",["******","******"]]}');
6060
});
6161

6262
it('should obfuscate the passphrase from `request.body` when `method` is `encryptwallet`', () => {
63-
const request = { body: '{"id":"1485369469422","method":"encryptwallet","params":["foobar"]}' };
63+
const request = { body: '{"id":"1485369469422","method":"encryptwallet","params":["foobar"]}', type: 'request' };
6464

6565
obfuscate(request);
6666

67-
request.should.eql({ body: '{"id":"1485369469422","method":"encryptwallet","params":["******"]}' });
67+
request.body.should.eql('{"id":"1485369469422","method":"encryptwallet","params":["******"]}');
6868
});
6969

7070
it('should obfuscate the passphrase from `request.body` when `method` is `walletpassphrase`', () => {
71-
const request = { body: '{"id":"1485369469422","method":"walletpassphrase","params":["foobar"]}' };
71+
const request = { body: '{"id":"1485369469422","method":"walletpassphrase","params":["foobar"]}', type: 'request' };
7272

7373
obfuscate(request);
7474

75-
request.should.eql({ body: '{"id":"1485369469422","method":"walletpassphrase","params":["******"]}' });
75+
request.body.should.eql('{"id":"1485369469422","method":"walletpassphrase","params":["******"]}');
7676
});
7777

7878
it('should obfuscate the `request.body` of a batch request', () => {
79-
const request = { body: '[{"id":"1485369469422","method":"walletpassphrase","params":["foobar"]},{"id":"1485369469423","method":"walletpassphrase","params":["foobar"]}]' };
79+
const request = { body: '[{"id":"1485369469422","method":"walletpassphrase","params":["foobar"]},{"id":"1485369469423","method":"walletpassphrase","params":["foobar"]}]', type: 'request' };
8080

8181
obfuscate(request);
8282

83-
request.should.eql({ body: '[{"id":"1485369469422","method":"walletpassphrase","params":["******"]},{"id":"1485369469423","method":"walletpassphrase","params":["******"]}]' });
83+
request.body.should.eql('[{"id":"1485369469422","method":"walletpassphrase","params":["******"]},{"id":"1485369469423","method":"walletpassphrase","params":["******"]}]');
8484
});
8585

8686
it('should obfuscate the private key from `response.body` when `method` is `dumpprivkey`', () => {
87-
const request = { response: { body: { id: '1485369469422-0', result: 'foobiz' } } };
87+
const request = { response: { body: { id: '1485369469422-0', result: 'foobiz' } }, type: 'response' };
8888

8989
obfuscate(request, { body: '{"id":"1485369469422","method":"dumpprivkey","params":["foobar"]}' });
9090

91-
request.should.eql({ response: { body: { id: '1485369469422-0', result: '******' } } });
91+
request.response.body.should.eql({ id: '1485369469422-0', result: '******' });
9292
});
9393

9494
it('should obfuscate the `response.body` when `headers.content-type` is `application/octet-stream`', () => {
95-
const request = { response: { body: new Buffer('foobar'), headers: { 'content-type': 'application/octet-stream' } } };
95+
const request = { response: { body: new Buffer('foobar'), headers: { 'content-type': 'application/octet-stream' } }, type: 'response' };
9696

9797
obfuscate(request, { uri: 'foobar.bin' });
9898

99-
request.should.eql({ response: { body: '******', headers: { 'content-type': 'application/octet-stream' } } });
99+
request.response.should.eql({ body: '******', headers: { 'content-type': 'application/octet-stream' } });
100100
});
101101

102102
it('should obfuscate the `request.response.body` of a batch request', () => {
@@ -107,7 +107,8 @@ describe('RequestObfuscator', () => {
107107
{ id: '1485369469422-2', result: 'foobiz' },
108108
{ id: '1485369469422-1', result: 'foo' }
109109
]
110-
}
110+
},
111+
type: 'response'
111112
};
112113

113114
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', () => {
119120
{ id: '1485369469422-2', result: 'foobiz' },
120121
{ id: '1485369469422-1', result: '******' }
121122
]
122-
}
123+
},
124+
type: 'response'
123125
});
124126
});
125127
});

yarn.lock

+3-8
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,10 @@
457457
lodash "^4.2.0"
458458
to-fast-properties "^2.0.0"
459459

460-
"@uphold/request-logger@^1.2.0":
461-
version "1.2.0"
462-
resolved "https://registry.yarnpkg.com/@uphold/request-logger/-/request-logger-1.2.0.tgz#e406893711e3de0369553155075890bec064a073"
460+
"@uphold/request-logger@^2.0.0":
461+
version "2.0.0"
462+
resolved "https://registry.yarnpkg.com/@uphold/request-logger/-/request-logger-2.0.0.tgz#c585c0bdb94210198945c6597e4fe23d6e63e084"
463463
dependencies:
464-
lodash.clonedeep "^4.5.0"
465464
uuid "^3.0.1"
466465

467466
abbrev@1:
@@ -2011,10 +2010,6 @@ locate-path@^2.0.0:
20112010
p-locate "^2.0.0"
20122011
path-exists "^3.0.0"
20132012

2014-
lodash.clonedeep@^4.5.0:
2015-
version "4.5.0"
2016-
resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef"
2017-
20182013
lodash@^4.0.0, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0, lodash@~4.17.2:
20192014
version "4.17.4"
20202015
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"

0 commit comments

Comments
 (0)