Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui Marinho committed Nov 18, 2017
1 parent 73c702f commit e27540c
Show file tree
Hide file tree
Showing 6 changed files with 3,338 additions and 49 deletions.
19 changes: 10 additions & 9 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
"env": {
"test": {
"plugins": [
"add-module-exports",
["transform-async-to-module-method", {
"module": "bluebird",
"method": "coroutine"
}],
"istanbul"
]
"@babel/transform-async-to-generator",
"istanbul"
]
}
},
"plugins": ["add-module-exports"],
"presets": ["es2015-node4"]
"presets": [
["@babel/preset-env", {
"targets": {
"node": "current"
}
}]
]
}
30 changes: 15 additions & 15 deletions 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 All @@ -44,21 +44,21 @@
"standard-error": "^1.1.0"
},
"devDependencies": {
"babel-cli": "^6.4.0",
"babel-eslint": "^8.0.1",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-istanbul": "^2.0.0",
"babel-plugin-transform-async-to-module-method": "^6.5.2",
"babel-preset-es2015-node4": "^2.0.2",
"babel-register": "^6.3.13",
"eslint": "^4.4.1",
"@babel/cli": "^7.0.0-beta.32",
"@babel/core": "^7.0.0-beta.32",
"@babel/plugin-transform-async-to-generator": "^7.0.0-beta.32",
"@babel/polyfill": "^7.0.0-beta.32",
"@babel/preset-env": "^7.0.0-beta.32",
"@babel/register": "^7.0.0-beta.32",
"babel-eslint": "^8.0.0",
"babel-plugin-istanbul": "^4.1.5",
"eslint": "4.11.0",
"eslint-config-uphold": "0.0.1",
"isparta": "^4.0.0",
"mocha": "^3.0.2",
"nock": "^8.0.0",
"nyc": "^8.1.0",
"mocha": "^4.0.1",
"nock": "^9.0.27",
"nyc": "^11.2.1",
"pre-commit": "^1.1.2",
"should": "^11.1.0"
"should": "^13.1.3"
},
"engines": {
"node": ">=4"
Expand All @@ -72,7 +72,7 @@
"sourceMap": false
},
"options": {
"mocha": "--compilers js:babel-register --timeout 20000 --recursive --require should"
"mocha": "--require @babel/register --timeout 20000 --recursive --require should"
},
"pre-commit": [
"lint"
Expand Down
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,13 @@ _.forOwn(methods, (range, method) => {
});

/**
* Export Client class.
* Export Client class (ESM).
*/

export default Client;

/**
* Export Client class (CJS) for compatibility with require('bitcoin-core').
*/

module.exports = Client;
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
Loading

0 comments on commit e27540c

Please sign in to comment.