Skip to content

Commit

Permalink
test: add tests for disallowed input (ipfs#376)
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
  • Loading branch information
alanshaw committed Nov 26, 2018
1 parent 4b2b7fe commit 204cce4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
20 changes: 20 additions & 0 deletions js/src/files-regular/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
8 changes: 4 additions & 4 deletions js/src/utils/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion js/test/fixtures/hidden-files-folder/ipfs-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down

0 comments on commit 204cce4

Please sign in to comment.