From ce504cd826e68c5dda60b2d37fb5d31e67ffd219 Mon Sep 17 00:00:00 2001 From: Marius Darila Date: Mon, 3 Jul 2017 08:45:31 +0300 Subject: [PATCH] fix(bootstrap:add): prevent duplicate inserts (#893) * fix(bootstrap:add): prevent duplicate inserts --- src/core/components/bootstrap.js | 2 +- test/http-api/over-ipfs-api/bootstrap.js | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/core/components/bootstrap.js b/src/core/components/bootstrap.js index af2bd95818..21c4615132 100644 --- a/src/core/components/bootstrap.js +++ b/src/core/components/bootstrap.js @@ -27,7 +27,7 @@ module.exports = function bootstrap (self) { } if (args.default) { config.Bootstrap = defaultNodes - } else if (multiaddr) { + } else if (multiaddr && config.Bootstrap.indexOf(multiaddr) === -1) { config.Bootstrap.push(multiaddr) } self._repo.config.set(config, (err) => { diff --git a/test/http-api/over-ipfs-api/bootstrap.js b/test/http-api/over-ipfs-api/bootstrap.js index 1e31b40412..ebde07318e 100644 --- a/test/http-api/over-ipfs-api/bootstrap.js +++ b/test/http-api/over-ipfs-api/bootstrap.js @@ -28,6 +28,30 @@ module.exports = (ctl) => { }) }) + it('prevents duplicate inserts of bootstrap peers', () => { + return ctl + .bootstrap + .rm(null, { all: true }) + .then((res) => { + expect(res.Peers.length).to.equal(0) + return ctl.bootstrap.add(validIp4) + }) + .then(res => { + expect(res).to.be.eql({ Peers: [validIp4] }) + return ctl.bootstrap.add(validIp4) + }) + .then((res) => { + expect(res).to.be.eql({ Peers: [validIp4] }) + return ctl.bootstrap.list() + }) + .then((res) => { + expect(res).to.exist() + const insertPosition = res.Peers.indexOf(validIp4) + expect(insertPosition).to.not.equal(-1) + expect(res.Peers.length).to.equal(1) + }) + }) + it('returns a list of bootstrap peers when called with the default option', (done) => { ctl.bootstrap.add({ default: true }, (err, res) => { expect(err).to.not.exist()