From f7a668dc4f10cd2a86363eaff4ec739ece934a78 Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 24 Aug 2016 09:45:00 +0100 Subject: [PATCH] feat(config-http): return error if value is invalid --- src/http-api/resources/config.js | 7 +++++++ .../test-config.js | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/http-api/resources/config.js b/src/http-api/resources/config.js index 869c2bfc80..214fdeb459 100644 --- a/src/http-api/resources/config.js +++ b/src/http-api/resources/config.js @@ -58,6 +58,13 @@ exports.getOrSet = { const key = request.pre.args.key const value = request.pre.args.value + if (typeof value === 'object' && value.type === 'Buffer') { + return reply({ + Message: 'Invalid value type', + Code: 0 + }).code(500) + } + if (value === undefined) { // Get the value of a given key return request.server.app.ipfs.config.get((err, config) => { diff --git a/test/http-api/interface-ipfs-core-over-ipfs-api/test-config.js b/test/http-api/interface-ipfs-core-over-ipfs-api/test-config.js index e69de29bb2..fe8cbbb667 100644 --- a/test/http-api/interface-ipfs-core-over-ipfs-api/test-config.js +++ b/test/http-api/interface-ipfs-core-over-ipfs-api/test-config.js @@ -0,0 +1,20 @@ +/* eslint-env mocha */ + +'use strict' + +const test = require('interface-ipfs-core') +const FactoryClient = require('./../../utils/factory-http') + +let fc + +const common = { + setup: function (callback) { + fc = new FactoryClient() + callback(null, fc) + }, + teardown: function (callback) { + fc.dismantle(callback) + } +} + +test.config(common)