From 1ee508f315cce42c242e5958caed08f8c3aab7bf Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 23 Oct 2018 10:11:28 +0100 Subject: [PATCH 1/3] test: add tests for disallowed input License: MIT Signed-off-by: Alan Shaw --- js/src/files-regular/add.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/js/src/files-regular/add.js b/js/src/files-regular/add.js index a2ab90393..c155a6a3d 100644 --- a/js/src/files-regular/add.js +++ b/js/src/files-regular/add.js @@ -120,6 +120,26 @@ module.exports = (createCommon, options) => { }) }) + it('should not be able to add a string', (done) => { + const data = `TEST${Date.now()}` + + ipfs.files.add(data, (err) => { + expect(err).to.exist() + expect(err.message).to.contain('invalid input') + done() + }) + }) + + it('should not be able to add a non-Buffer TypedArray', (done) => { + const data = Uint8Array.from([Date.now()]) + + ipfs.files.add(data, (err) => { + expect(err).to.exist() + expect(err.message).to.contain('invalid input') + done() + }) + }) + it('should add readable stream', (done) => { const expectedCid = 'QmVv4Wz46JaZJeH5PMV4LGbRiiMKEmszPYY3g6fjGnVXBS' From 772159ac71724d044ed7bad7a3d60f5bda198aa3 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 26 Nov 2018 10:57:10 +0000 Subject: [PATCH 2/3] fix: ipfs.files.add moved to ipfs.add License: MIT Signed-off-by: Alan Shaw --- js/src/files-regular/add.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/src/files-regular/add.js b/js/src/files-regular/add.js index c155a6a3d..0663ad25c 100644 --- a/js/src/files-regular/add.js +++ b/js/src/files-regular/add.js @@ -123,7 +123,7 @@ module.exports = (createCommon, options) => { it('should not be able to add a string', (done) => { const data = `TEST${Date.now()}` - ipfs.files.add(data, (err) => { + ipfs.add(data, (err) => { expect(err).to.exist() expect(err.message).to.contain('invalid input') done() @@ -133,7 +133,7 @@ module.exports = (createCommon, options) => { it('should not be able to add a non-Buffer TypedArray', (done) => { const data = Uint8Array.from([Date.now()]) - ipfs.files.add(data, (err) => { + ipfs.add(data, (err) => { expect(err).to.exist() expect(err.message).to.contain('invalid input') done() From 039f3de0df056334e7f0e70105c746ceca8325a8 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 26 Nov 2018 11:13:12 +0000 Subject: [PATCH 3/3] chore: appease linter License: MIT Signed-off-by: Alan Shaw --- js/src/utils/mocha.js | 8 ++++---- js/test/fixtures/hidden-files-folder/ipfs-add.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/js/src/utils/mocha.js b/js/src/utils/mocha.js index 9ea71a0fa..c21ae8739 100644 --- a/js/src/utils/mocha.js +++ b/js/src/utils/mocha.js @@ -25,12 +25,12 @@ function getDescribe (config) { } _describe.skip = describe.skip - _describe.only = describe.only + _describe.only = describe.only // eslint-disable-line return _describe } - if (config.only === true) return describe.only + if (config.only === true) return describe.only // eslint-disable-line } return describe @@ -59,14 +59,14 @@ function getIt (config) { } if (Array.isArray(config.only)) { - if (config.only.includes(name)) return it.only(name, impl) + if (config.only.includes(name)) return it.only(name, impl) // eslint-disable-line } it(name, impl) } _it.skip = it.skip - _it.only = it.only + _it.only = it.only // eslint-disable-line return _it } diff --git a/js/test/fixtures/hidden-files-folder/ipfs-add.js b/js/test/fixtures/hidden-files-folder/ipfs-add.js index 962aa11fe..0d99df8d2 100755 --- a/js/test/fixtures/hidden-files-folder/ipfs-add.js +++ b/js/test/fixtures/hidden-files-folder/ipfs-add.js @@ -5,7 +5,7 @@ const ipfs = require('../src')('localhost', 5001) const files = process.argv.slice(2) -ipfs.add(files, {recursive: true}, function (err, res) { +ipfs.add(files, { recursive: true }, function (err, res) { if (err || !res) return console.log(err) for (let i = 0; i < res.length; i++) {