Skip to content

Commit 204cce4

Browse files
author
Alan Shaw
authored
test: add tests for disallowed input (ipfs#376)
License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent 4b2b7fe commit 204cce4

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

js/src/files-regular/add.js

+20
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,26 @@ module.exports = (createCommon, options) => {
120120
})
121121
})
122122

123+
it('should not be able to add a string', (done) => {
124+
const data = `TEST${Date.now()}`
125+
126+
ipfs.add(data, (err) => {
127+
expect(err).to.exist()
128+
expect(err.message).to.contain('invalid input')
129+
done()
130+
})
131+
})
132+
133+
it('should not be able to add a non-Buffer TypedArray', (done) => {
134+
const data = Uint8Array.from([Date.now()])
135+
136+
ipfs.add(data, (err) => {
137+
expect(err).to.exist()
138+
expect(err.message).to.contain('invalid input')
139+
done()
140+
})
141+
})
142+
123143
it('should add readable stream', (done) => {
124144
const expectedCid = 'QmVv4Wz46JaZJeH5PMV4LGbRiiMKEmszPYY3g6fjGnVXBS'
125145

js/src/utils/mocha.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ function getDescribe (config) {
2525
}
2626

2727
_describe.skip = describe.skip
28-
_describe.only = describe.only
28+
_describe.only = describe.only // eslint-disable-line
2929

3030
return _describe
3131
}
3232

33-
if (config.only === true) return describe.only
33+
if (config.only === true) return describe.only // eslint-disable-line
3434
}
3535

3636
return describe
@@ -59,14 +59,14 @@ function getIt (config) {
5959
}
6060

6161
if (Array.isArray(config.only)) {
62-
if (config.only.includes(name)) return it.only(name, impl)
62+
if (config.only.includes(name)) return it.only(name, impl) // eslint-disable-line
6363
}
6464

6565
it(name, impl)
6666
}
6767

6868
_it.skip = it.skip
69-
_it.only = it.only
69+
_it.only = it.only // eslint-disable-line
7070

7171
return _it
7272
}

js/test/fixtures/hidden-files-folder/ipfs-add.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
const ipfs = require('../src')('localhost', 5001)
66
const files = process.argv.slice(2)
77

8-
ipfs.add(files, {recursive: true}, function (err, res) {
8+
ipfs.add(files, { recursive: true }, function (err, res) {
99
if (err || !res) return console.log(err)
1010

1111
for (let i = 0; i < res.length; i++) {

0 commit comments

Comments
 (0)