From be017be287f81514b8633339d3c107bef90d71fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=98=D0=BB=D1=8C?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Mon, 30 Jul 2018 20:10:01 +0300 Subject: [PATCH 1/3] fix(dag): check dag.put options for plain object fixes #1479 --- src/core/components/dag.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/core/components/dag.js b/src/core/components/dag.js index e8cecdb7a4..9d5b68f981 100644 --- a/src/core/components/dag.js +++ b/src/core/components/dag.js @@ -5,16 +5,22 @@ const CID = require('cids') const pull = require('pull-stream') const mapAsync = require('async/map') const flattenDeep = require('lodash/flattenDeep') +const isPlainObject = require('lodash/isPlainObject') module.exports = function dag (self) { return { put: promisify((dagNode, options, callback) => { if (typeof options === 'function') { callback = options - } else if (options.cid && (options.format || options.hashAlg)) { - return callback(new Error('Can\'t put dag node. Please provide either `cid` OR `format` and `hashAlg` options.')) - } else if ((options.format && !options.hashAlg) || (!options.format && options.hashAlg)) { - return callback(new Error('Can\'t put dag node. Please provide `format` AND `hashAlg` options.')) + options = {} + } else if (isPlainObject(options)) { + if (options.cid && (options.format || options.hashAlg)) { + return callback(new Error('Can\'t put dag node. Please provide either `cid` OR `format` and `hashAlg` options.')) + } else if ((options.format && !options.hashAlg) || (!options.format && options.hashAlg)) { + return callback(new Error('Can\'t put dag node. Please provide `format` AND `hashAlg` options.')) + } + } else { + options = {} } const optionDefaults = { From 748f4b41da5aa3a901eb69164927e8feff64b510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=98=D0=BB=D1=8C?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Mon, 30 Jul 2018 22:38:52 +0300 Subject: [PATCH 2/3] fix(dag): check for undefined options value --- src/core/components/dag.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/core/components/dag.js b/src/core/components/dag.js index 9d5b68f981..c33539d97c 100644 --- a/src/core/components/dag.js +++ b/src/core/components/dag.js @@ -5,7 +5,6 @@ const CID = require('cids') const pull = require('pull-stream') const mapAsync = require('async/map') const flattenDeep = require('lodash/flattenDeep') -const isPlainObject = require('lodash/isPlainObject') module.exports = function dag (self) { return { @@ -13,15 +12,12 @@ module.exports = function dag (self) { if (typeof options === 'function') { callback = options options = {} - } else if (isPlainObject(options)) { - if (options.cid && (options.format || options.hashAlg)) { - return callback(new Error('Can\'t put dag node. Please provide either `cid` OR `format` and `hashAlg` options.')) - } else if ((options.format && !options.hashAlg) || (!options.format && options.hashAlg)) { - return callback(new Error('Can\'t put dag node. Please provide `format` AND `hashAlg` options.')) - } - } else { - options = {} + } else if (options && options.cid && (options.format || options.hashAlg)) { + return callback(new Error('Can\'t put dag node. Please provide either `cid` OR `format` and `hashAlg` options.')) + } else if (options && ((options.format && !options.hashAlg) || (!options.format && options.hashAlg))) { + return callback(new Error('Can\'t put dag node. Please provide `format` AND `hashAlg` options.')) } + options = options || {} const optionDefaults = { format: 'dag-cbor', From 28db44be1125b60323f52781541aa4d2e38348ed Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 7 Aug 2018 14:54:33 +0100 Subject: [PATCH 3/3] fix: increase timeout for pin after hook License: MIT Signed-off-by: Alan Shaw --- test/core/pin.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/core/pin.js b/test/core/pin.js index 32618422a0..2c1b87e329 100644 --- a/test/core/pin.js +++ b/test/core/pin.js @@ -81,7 +81,10 @@ describe('pin', function () { }) }) - after(done => ipfs.stop(done)) + after(function (done) { + this.timeout(20 * 1000) + ipfs.stop(done) + }) describe('isPinnedWithType', function () { beforeEach(function () {