From 0e10483b4e999f1a661e8917a60248a24c27fca0 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 14 Jun 2018 17:31:40 +0200 Subject: [PATCH] test: adds test vulnerable to encoding translation --- js/src/object.js | 21 +++++++++++++++++++++ package.json | 1 + 2 files changed, 22 insertions(+) diff --git a/js/src/object.js b/js/src/object.js index 5bdb40f7..db3c2a1b 100644 --- a/js/src/object.js +++ b/js/src/object.js @@ -11,6 +11,9 @@ const dagPB = require('ipld-dag-pb') const DAGNode = dagPB.DAGNode const bs58 = require('bs58') const series = require('async/series') +const UnixFs = require('ipfs-unixfs') +const crypto = require('crypto') +const CID = require('cids') module.exports = (common) => { describe('.object', function () { @@ -451,6 +454,24 @@ module.exports = (common) => { }) }) }) + + it('supplies unadulterated data', () => { + // has to be big enough to span several DAGNodes + const data = crypto.randomBytes(1024 * 300) + + 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) + }) + }) }) describe('.links', () => { diff --git a/package.json b/package.json index 1aca264b..416c0b2a 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,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.0", "ipld-dag-pb": "~0.14.4", "is-ipfs": "~0.3.2",