From 204cce436970f16f8cf07ed98387d4702fab9855 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 26 Nov 2018 11:31:24 +0000 Subject: [PATCH] test: add tests for disallowed input (#376) License: MIT Signed-off-by: Alan Shaw --- js/src/files-regular/add.js | 20 +++++++++++++++++++ js/src/utils/mocha.js | 8 ++++---- .../fixtures/hidden-files-folder/ipfs-add.js | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/js/src/files-regular/add.js b/js/src/files-regular/add.js index a2ab90393d..0663ad25c1 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.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.add(data, (err) => { + expect(err).to.exist() + expect(err.message).to.contain('invalid input') + done() + }) + }) + it('should add readable stream', (done) => { const expectedCid = 'QmVv4Wz46JaZJeH5PMV4LGbRiiMKEmszPYY3g6fjGnVXBS' diff --git a/js/src/utils/mocha.js b/js/src/utils/mocha.js index 9ea71a0fae..c21ae8739d 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 962aa11fe6..0d99df8d2f 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++) {