Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

test: adds test vulnerable to encoding translation #302

Merged
merged 1 commit into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions js/src/object/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const bs58 = require('bs58')
const series = require('async/series')
const hat = require('hat')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const UnixFs = require('ipfs-unixfs')
const crypto = require('crypto')

module.exports = (createCommon, options) => {
const describe = getDescribe(options)
Expand Down Expand Up @@ -285,5 +287,39 @@ module.exports = (createCommon, options) => {
}
], done)
})

it('supplies unadulterated data', () => {
// has to be big enough to span several DAGNodes
let required = 1024 * 3000

// can't just request `required` random bytes in the browser yet
// as it's more than 65536:
// https://github.com/crypto-browserify/randombytes/pull/15
let data = Buffer.alloc(0)
const maxBytes = 65536
let next = maxBytes

while (data.length !== required) {
data = Buffer.concat([data, crypto.randomBytes(next)])
next = maxBytes

if (data.length + maxBytes > required) {
next = required - data.length
}
}

return ipfs.files.add({
path: '',
content: data
})
.then((result) => {
return ipfs.object.get(result[0].hash)
})
.then((node) => {
const meta = UnixFs.unmarshal(node.data)

expect(meta.fileSize()).to.equal(data.length)
})
})
})
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"dirty-chai": "^2.0.1",
"hat": "0.0.3",
"ipfs-block": "~0.7.1",
"ipfs-unixfs": "~0.1.15",
"ipld-dag-cbor": "~0.12.1",
"ipld-dag-pb": "~0.14.5",
"is-ipfs": "~0.3.2",
Expand Down