File tree 2 files changed +19
-4
lines changed
2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -26,13 +26,20 @@ function DAGService (blockService) {
26
26
27
27
// get retrieves a DAGNode, using the Block Service
28
28
this . get = function ( multihash , callback ) {
29
- if ( Buffer . isBuffer ( multihash ) ) {
29
+ const isBuf = Buffer . isBuffer ( multihash )
30
+ const isString = typeof multihash === 'string'
31
+
32
+ if ( ! isBuf && ! isString ) {
33
+ return callback ( new Error ( 'Invalid Key' ) )
34
+ }
35
+
36
+ if ( isBuf ) {
30
37
var mhString = base58 . encode ( multihash )
31
38
if ( ! isIPFS . multihash ( mhString ) ) { return callback ( new Error ( 'Invalid Key' ) ) }
32
39
this . getWith ( multihash , callback )
33
40
}
34
41
35
- if ( typeof multihash === 'string' ) {
42
+ if ( isString ) {
36
43
var isMhash = isIPFS . multihash ( multihash )
37
44
var isPath = isIPFS . path ( multihash )
38
45
if ( ! isMhash && ! isPath ) {
Original file line number Diff line number Diff line change @@ -176,8 +176,7 @@ module.exports = function (repo) {
176
176
} )
177
177
178
178
it ( 'get a mdag node from a /ipfs/ path' , ( done ) => {
179
- var encodedMh = 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG'
180
- var ipfsPath = '/ipfs/' + encodedMh
179
+ var ipfsPath = '/ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG'
181
180
dagService . get ( ipfsPath , ( err , fetchedNode ) => {
182
181
expect ( err ) . to . not . exist
183
182
expect ( fetchedNode . data ) . to . deep . equal ( new Buffer ( bs58 . decode ( 'cL' ) ) )
@@ -205,6 +204,15 @@ module.exports = function (repo) {
205
204
} )
206
205
} )
207
206
207
+ it ( 'supply something weird' , ( done ) => {
208
+ var mh = 3
209
+ dagService . get ( mh , ( err , fetchedNode ) => {
210
+ var error = 'Error: Invalid Key'
211
+ expect ( err . toString ( ) ) . to . equal ( error )
212
+ done ( )
213
+ } )
214
+ } )
215
+
208
216
it ( 'get a dag recursively' , ( done ) => {
209
217
// 1 -> 2 -> 3
210
218
const node1 = new DAGNode ( new Buffer ( '1' ) )
You can’t perform that action at this time.
0 commit comments