From f1f09e90def5a366510f907a10a8724ff7d06a9b Mon Sep 17 00:00:00 2001
From: Dirk McCormick
Date: Thu, 6 Jun 2019 13:57:44 -0400
Subject: [PATCH 01/18] feat: config profile
---
package.json | 3 +-
src/cli/commands/config/profile.js | 15 ++++
src/cli/commands/config/profile/apply.js | 25 +++++++
src/cli/commands/config/profile/ls.js | 17 +++++
src/core/components/config.js | 91 +++++++++++++++++++++++-
src/http/api/resources/config.js | 38 ++++++++++
src/http/api/routes/config.js | 11 +++
test/cli/config.js | 67 +++++++++++++++++
8 files changed, 265 insertions(+), 2 deletions(-)
create mode 100644 src/cli/commands/config/profile.js
create mode 100644 src/cli/commands/config/profile/apply.js
create mode 100644 src/cli/commands/config/profile/ls.js
diff --git a/package.json b/package.json
index 0b87ec4e7b..899cf288e4 100644
--- a/package.json
+++ b/package.json
@@ -97,7 +97,7 @@
"ipfs-bitswap": "~0.25.1",
"ipfs-block": "~0.8.1",
"ipfs-block-service": "~0.15.2",
- "ipfs-http-client": "^34.0.0",
+ "ipfs-http-client": "^34.1.0",
"ipfs-http-response": "~0.3.1",
"ipfs-mfs": "~0.12.0",
"ipfs-multipart": "~0.1.1",
@@ -120,6 +120,7 @@
"is-pull-stream": "~0.0.0",
"is-stream": "^2.0.0",
"iso-url": "~0.4.6",
+ "jsondiffpatch": "~0.3.11",
"just-safe-set": "^2.1.0",
"kind-of": "^6.0.2",
"libp2p": "~0.26.1",
diff --git a/src/cli/commands/config/profile.js b/src/cli/commands/config/profile.js
new file mode 100644
index 0000000000..2b70510fde
--- /dev/null
+++ b/src/cli/commands/config/profile.js
@@ -0,0 +1,15 @@
+'use strict'
+
+module.exports = {
+ command: 'profile ',
+
+ description: 'Interact with config profiles.',
+
+ builder (yargs) {
+ return yargs
+ .commandDir('profile')
+ },
+
+ handler (argv) {
+ }
+}
diff --git a/src/cli/commands/config/profile/apply.js b/src/cli/commands/config/profile/apply.js
new file mode 100644
index 0000000000..d341b3049b
--- /dev/null
+++ b/src/cli/commands/config/profile/apply.js
@@ -0,0 +1,25 @@
+'use strict'
+
+const JSONDiff = require('jsondiffpatch')
+
+module.exports = {
+ command: 'apply ',
+
+ describe: 'Apply profile to config',
+
+ builder: {
+ 'dry-run': {
+ type: 'boolean',
+ describe: 'print difference between the current config and the config that would be generated.'
+ }
+ },
+
+ handler (argv) {
+ argv.resolve((async () => {
+ const ipfs = await argv.getIpfs()
+ const diff = await ipfs.config.profile(argv.profile, { dryRun: argv.dryRun })
+ const delta = JSONDiff.diff(diff.oldCfg, diff.newCfg)
+ return JSONDiff.formatters.console.format(delta, diff.oldCfg)
+ })())
+ }
+}
diff --git a/src/cli/commands/config/profile/ls.js b/src/cli/commands/config/profile/ls.js
new file mode 100644
index 0000000000..445a1655fe
--- /dev/null
+++ b/src/cli/commands/config/profile/ls.js
@@ -0,0 +1,17 @@
+'use strict'
+
+const { profiles } = require('../../../../core/components/config')
+
+module.exports = {
+ command: 'ls',
+
+ describe: 'List available config profiles',
+
+ builder: {},
+
+ handler (argv) {
+ argv.resolve((async () => {
+ return profiles.map(p => p.name + ':\n ' + p.description).join('\n')
+ })())
+ }
+}
diff --git a/src/core/components/config.js b/src/core/components/config.js
index 1f3afbfc8e..0e09cc0878 100644
--- a/src/core/components/config.js
+++ b/src/core/components/config.js
@@ -1,6 +1,7 @@
'use strict'
const promisify = require('promisify-es6')
+const defaultConfig = require('../runtime/config-nodejs.js')()
module.exports = function config (self) {
return {
@@ -17,6 +18,94 @@ module.exports = function config (self) {
}),
replace: promisify((config, callback) => {
self._repo.config.set(config, callback)
- })
+ }),
+ profile: promisify(applyProfile)
+ }
+
+ async function applyProfile (profileName, opts, callback) {
+ if (typeof opts === 'function') {
+ callback = opts
+ opts = {}
+ }
+ const { dryRun } = opts
+
+ const profile = profiles.find(p => p.name === profileName)
+ if (!profile) {
+ return callback(new Error(`No profile with name '${profileName}' exists`))
+ }
+
+ try {
+ const oldCfg = await self.config.get()
+ const newCfg = JSON.parse(JSON.stringify(oldCfg)) // clone
+ profile.transform(newCfg)
+ if (!dryRun) {
+ await self.config.replace(newCfg)
+ }
+
+ // Scrub private key from output
+ delete oldCfg.Identity.PrivKey
+ delete newCfg.Identity.PrivKey
+
+ callback(null, { oldCfg, newCfg })
+ } catch (err) {
+ callback(new Error(`Could not apply profile '${profileName}' to config: ${err.message}`))
+ }
}
}
+
+const profiles = [{
+ name: 'server',
+ description: 'Disables local host discovery - recommended when running IPFS on machines with public IPv4 addresses.',
+ transform: (config) => {
+ config.Discovery.MDNS.Enabled = false
+ config.Discovery.webRTCStar.Enabled = false
+ }
+}, {
+ name: 'local-discovery',
+ description: 'Enables local host discovery - inverse of "server" profile.',
+ transform: (config) => {
+ config.Discovery.MDNS.Enabled = true
+ config.Discovery.webRTCStar.Enabled = true
+ }
+}, {
+ name: 'test',
+ description: 'Reduces external interference of IPFS daemon - for running the daemon in test environments.',
+ transform: (config) => {
+ config.Addresses.API = defaultConfig.Addresses.API ? '/ip4/127.0.0.1/tcp/0' : ''
+ config.Addresses.Gateway = defaultConfig.Addresses.Gateway ? '/ip4/127.0.0.1/tcp/0' : ''
+ config.Addresses.Swarm = defaultConfig.Addresses.Swarm.length ? ['/ip4/127.0.0.1/tcp/0'] : []
+ config.Bootstrap = []
+ config.Discovery.MDNS.Enabled = false
+ config.Discovery.webRTCStar.Enabled = false
+ }
+}, {
+ name: 'default-networking',
+ description: 'Restores default network settings - inverse of "test" profile.',
+ transform: (config) => {
+ console.log('applying default-networking')
+ console.log('setting to', defaultConfig.Addresses)
+ config.Addresses.API = defaultConfig.Addresses.API
+ config.Addresses.Gateway = defaultConfig.Addresses.Gateway
+ config.Addresses.Swarm = defaultConfig.Addresses.Swarm
+ config.Bootstrap = defaultConfig.Bootstrap
+ config.Discovery.MDNS.Enabled = defaultConfig.Discovery.MDNS.Enabled
+ config.Discovery.webRTCStar.Enabled = defaultConfig.Discovery.webRTCStar.Enabled
+ }
+}, {
+ name: 'lowpower',
+ description: 'Reduces daemon overhead on the system - recommended for low power systems.',
+ transform: (config) => {
+ config.Swarm = config.Swarm || {}
+ config.Swarm.ConnMgr = config.Swarm.ConnMgr || {}
+ config.Swarm.ConnMgr.LowWater = 20
+ config.Swarm.ConnMgr.HighWater = 40
+ }
+}, {
+ name: 'default-power',
+ description: 'Inverse of "lowpower" profile.',
+ transform: (config) => {
+ config.Swarm = defaultConfig.Swarm
+ }
+}]
+
+module.exports.profiles = profiles
diff --git a/src/http/api/resources/config.js b/src/http/api/resources/config.js
index dd52a60f33..6c72103751 100644
--- a/src/http/api/resources/config.js
+++ b/src/http/api/resources/config.js
@@ -7,6 +7,8 @@ const log = debug('ipfs:http-api:config')
log.error = debug('ipfs:http-api:config:error')
const multipart = require('ipfs-multipart')
const Boom = require('@hapi/boom')
+const Joi = require('@hapi/joi')
+const { profiles } = require('../../../core/components/config')
exports.getOrSet = {
// pre request handler that parses the args and returns `key` & `value` which are assigned to `request.pre.args`
@@ -160,3 +162,39 @@ exports.replace = {
return h.response()
}
}
+
+exports.profile = {
+ validate: {
+ query: Joi.object().keys({
+ 'dry-run': Joi.boolean().default(false)
+ }).unknown()
+ },
+
+ // pre request handler that parses the args and returns `profile` which is assigned to `request.pre.args`
+ parseArgs: async function (request, h) {
+ if (!request.query.arg) {
+ throw Boom.badRequest("Argument 'profile' is required")
+ }
+
+ if (!profiles.find(p => p.name === request.query.arg)) {
+ throw Boom.badRequest("Argument 'profile' is not a valid profile name")
+ }
+
+ return { profile: request.query.arg }
+ },
+
+ handler: async function (request, h) {
+ const { ipfs } = request.server.app
+ const { profile } = request.pre.args
+ const dryRun = request.query['dry-run']
+
+ let diff
+ try {
+ diff = await ipfs.config.profile(profile, { dryRun })
+ } catch (err) {
+ throw Boom.boomify(err, { message: 'Failed to apply profile' })
+ }
+
+ return h.response({ OldCfg: diff.oldCfg, NewCfg: diff.newCfg })
+ }
+}
diff --git a/src/http/api/routes/config.js b/src/http/api/routes/config.js
index 5315a043dc..0bd127666a 100644
--- a/src/http/api/routes/config.js
+++ b/src/http/api/routes/config.js
@@ -31,5 +31,16 @@ module.exports = [
]
},
handler: resources.config.replace.handler
+ },
+ {
+ method: '*',
+ path: '/api/v0/config/profile/apply',
+ options: {
+ pre: [
+ { method: resources.config.profile.parseArgs, assign: 'args' }
+ ],
+ validate: resources.config.profile.validate
+ },
+ handler: resources.config.profile.handler
}
]
diff --git a/test/cli/config.js b/test/cli/config.js
index f9d1c0458a..9e4a8b0b71 100644
--- a/test/cli/config.js
+++ b/test/cli/config.js
@@ -8,6 +8,7 @@ chai.use(dirtyChai)
const fs = require('fs')
const path = require('path')
const runOnAndOff = require('../utils/on-and-off')
+const defaultConfig = require('../../src/core/runtime/config-nodejs')()
describe('config', () => runOnAndOff((thing) => {
let ipfs
@@ -97,4 +98,70 @@ describe('config', () => runOnAndOff((thing) => {
restoreConfig()
})
})
+
+ describe('profile', function () {
+ this.timeout(40 * 1000)
+
+ beforeEach(() => restoreConfig())
+ after(() => restoreConfig())
+
+ it('server / local-discovery', async () => {
+ await ipfs('config profile apply server')
+ const updated = updatedConfig()
+ expect(updated.Discovery.MDNS.Enabled).to.equal(false)
+ expect(updated.Discovery.webRTCStar.Enabled).to.equal(false)
+
+ await ipfs('config profile apply local-discovery')
+ const reversed = updatedConfig()
+ expect(reversed.Discovery.MDNS.Enabled).to.equal(true)
+ expect(reversed.Discovery.webRTCStar.Enabled).to.equal(true)
+ })
+
+ it('test / default-networking', async () => {
+ await ipfs('config profile apply test')
+ const updated = updatedConfig()
+ expect(updated.Addresses.API).to.equal('/ip4/127.0.0.1/tcp/0')
+ expect(updated.Addresses.Gateway).to.equal('/ip4/127.0.0.1/tcp/0')
+ expect(updated.Addresses.Swarm).to.eql(['/ip4/127.0.0.1/tcp/0'])
+ expect(updated.Bootstrap).to.eql([])
+ expect(updated.Discovery.MDNS.Enabled).to.equal(false)
+ expect(updated.Discovery.webRTCStar.Enabled).to.equal(false)
+
+ await ipfs('config profile apply default-networking')
+ const reversed = updatedConfig()
+ expect(reversed.Addresses.API).to.equal(defaultConfig.Addresses.API)
+ expect(reversed.Addresses.Gateway).to.equal(defaultConfig.Addresses.Gateway)
+ expect(reversed.Addresses.Swarm).to.eql(defaultConfig.Addresses.Swarm)
+ expect(reversed.Bootstrap).to.eql(defaultConfig.Bootstrap)
+ expect(reversed.Discovery.MDNS.Enabled).to.equal(true)
+ expect(reversed.Discovery.webRTCStar.Enabled).to.equal(true)
+ })
+
+ it('lowpower / default-power', async () => {
+ await ipfs('config profile apply lowpower')
+ const updated = updatedConfig()
+ expect(updated.Swarm.ConnMgr.LowWater).to.equal(20)
+ expect(updated.Swarm.ConnMgr.HighWater).to.equal(40)
+
+ await ipfs('config profile apply default-power')
+ const reversed = updatedConfig()
+ expect(reversed.Swarm.ConnMgr.LowWater).to.equal(defaultConfig.Swarm.ConnMgr.LowWater)
+ expect(reversed.Swarm.ConnMgr.HighWater).to.equal(defaultConfig.Swarm.ConnMgr.HighWater)
+ })
+
+ it('--dry-run causes no change', async () => {
+ await ipfs('config profile apply --dry-run=true server')
+ const after = updatedConfig()
+ expect(after.Discovery.MDNS.Enabled).to.equal(defaultConfig.Discovery.MDNS.Enabled)
+
+ await ipfs('config profile apply --dry-run=false server')
+ const updated = updatedConfig()
+ expect(updated.Discovery.MDNS.Enabled).to.equal(false)
+ })
+
+ it('Private key does not appear in output', async () => {
+ const out = await ipfs('config profile apply server')
+ expect(out).not.includes('PrivKey')
+ })
+ })
}))
From f4e6b9be170fddbfeafde4d6313576535fb6f200 Mon Sep 17 00:00:00 2001
From: Dirk McCormick
Date: Thu, 6 Jun 2019 14:29:19 -0400
Subject: [PATCH 02/18] fix: increase command count
---
test/cli/commands.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/cli/commands.js b/test/cli/commands.js
index 1e193257a6..1cf0ccf760 100644
--- a/test/cli/commands.js
+++ b/test/cli/commands.js
@@ -4,7 +4,7 @@
const expect = require('chai').expect
const runOnAndOff = require('../utils/on-and-off')
-const commandCount = 95
+const commandCount = 98
describe('commands', () => runOnAndOff((thing) => {
let ipfs
From 18f3a193115cc82d37ed19a6df3ed8171c906eaf Mon Sep 17 00:00:00 2001
From: Dirk McCormick
Date: Thu, 6 Jun 2019 15:03:44 -0400
Subject: [PATCH 03/18] feat: ipfs init --profile option
---
src/cli/commands/init.js | 13 +++++++++++--
src/core/components/init.js | 16 ++++++++++++++++
test/cli/init.js | 30 ++++++++++++++++++++++++++++++
3 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/src/cli/commands/init.js b/src/cli/commands/init.js
index 78095d25e4..fec3c1ac63 100644
--- a/src/cli/commands/init.js
+++ b/src/cli/commands/init.js
@@ -4,12 +4,15 @@ const { ipfsPathHelp } = require('../utils')
module.exports = {
command: 'init [config] [options]',
- describe: 'Initialize a local IPFS node',
+ describe: 'Initialize a local IPFS node\n\n' +
+ 'If you are going to run IPFS in a server environment, you may want to ' +
+ `initialize it using the 'server' profile.\n\n` +
+ 'For the list of available profiles run `jsipfs config profile ls`',
builder (yargs) {
return yargs
.epilog(ipfsPathHelp)
.positional('config', {
- describe: 'Node config, this should JSON and will be merged with the default config. Check https://github.com/ipfs/js-ipfs#optionsconfig',
+ describe: 'Node config, this should be JSON and will be merged with the default config. See https://github.com/ipfs/js-ipfs#optionsconfig',
type: 'string'
})
.option('bits', {
@@ -28,6 +31,11 @@ module.exports = {
type: 'string',
describe: 'Pre-generated private key to use for the repo'
})
+ .option('profile', {
+ alias: 'p',
+ type: 'string',
+ describe: `Apply profile settings to config. Multiple profiles can be separated by ','`
+ })
},
handler (argv) {
@@ -52,6 +60,7 @@ module.exports = {
bits: argv.bits,
privateKey: argv.privateKey,
emptyRepo: argv.emptyRepo,
+ profile: argv.profile,
pass: argv.pass,
log: argv.print
})
diff --git a/src/core/components/init.js b/src/core/components/init.js
index 5b1a1b7cbe..cce67d2e0d 100644
--- a/src/core/components/init.js
+++ b/src/core/components/init.js
@@ -17,6 +17,7 @@ const IPNS = require('../ipns')
const OfflineDatastore = require('../ipns/routing/offline-datastore')
const addDefaultAssets = require('./init-assets')
+const { profiles } = require('./config')
module.exports = function init (self) {
return promisify((opts, callback) => {
@@ -61,6 +62,21 @@ module.exports = function init (self) {
opts.log = opts.log || function () {}
const config = mergeOptions(defaultConfig(), self._options.config)
+
+ // Apply profiles (eg "server,lowpower") to config
+ if (opts.profile) {
+ const profileNames = opts.profile.split(',')
+ for (const profileName of profileNames) {
+ const profile = profiles.find(p => p.name === profileName)
+ if (!profile) {
+ return done(new Error(`Could not find profile with name '${profileName}'`))
+ }
+
+ self.log(`applying profile ${profileName}`)
+ profile.transform(config)
+ }
+ }
+
let privateKey
waterfall([
diff --git a/test/cli/init.js b/test/cli/init.js
index ab9082a731..af3ff72afb 100644
--- a/test/cli/init.js
+++ b/test/cli/init.js
@@ -25,6 +25,11 @@ describe('init', function () {
return !f.startsWith('.')
})
}
+
+ const repoConfSync = (p) => {
+ return JSON.parse(fs.readFileSync(path.join(repoPath, 'config')))
+ }
+
beforeEach(() => {
repoPath = os.tmpdir() + '/ipfs-' + hat()
ipfs = ipfsExec(repoPath)
@@ -67,6 +72,31 @@ describe('init', function () {
})
})
+ it('profile', async function () {
+ this.timeout(40 * 1000)
+
+ await ipfs('init --profile lowpower')
+ expect(repoConfSync().Swarm.ConnMgr.LowWater).to.equal(20)
+ })
+
+ it('profile multiple', async function () {
+ this.timeout(40 * 1000)
+
+ await ipfs('init --profile server,lowpower')
+ expect(repoConfSync().Discovery.MDNS.Enabled).to.equal(false)
+ expect(repoConfSync().Swarm.ConnMgr.LowWater).to.equal(20)
+ })
+
+ it('profile non-existent', async function () {
+ this.timeout(40 * 1000)
+
+ try {
+ await ipfs('init --profile doesnt-exist')
+ } catch (err) {
+ expect(err.stdout).includes('Could not find profile')
+ }
+ })
+
it('should present ipfs path help when option help is received', function (done) {
this.timeout(100 * 1000)
From 6b82ae14eb750b23aeb31fa24cc034bb7f13de13 Mon Sep 17 00:00:00 2001
From: Alan Shaw
Date: Wed, 4 Sep 2019 17:52:08 +0100
Subject: [PATCH 04/18] chore: update dependencies
License: MIT
Signed-off-by: Alan Shaw
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 899cf288e4..11685f350c 100644
--- a/package.json
+++ b/package.json
@@ -97,7 +97,7 @@
"ipfs-bitswap": "~0.25.1",
"ipfs-block": "~0.8.1",
"ipfs-block-service": "~0.15.2",
- "ipfs-http-client": "^34.1.0",
+ "ipfs-http-client": "^35.1.0",
"ipfs-http-response": "~0.3.1",
"ipfs-mfs": "~0.12.0",
"ipfs-multipart": "~0.1.1",
From 4e333c9c817905f9f6dee2d7db961f0d966d1a01 Mon Sep 17 00:00:00 2001
From: achingbrain
Date: Tue, 1 Oct 2019 18:33:35 +0100
Subject: [PATCH 05/18] fix: make sure default-config still works
---
src/cli/commands/init.js | 4 ++--
src/core/components/init.js | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/cli/commands/init.js b/src/cli/commands/init.js
index 71f0a21c19..b3b65cacb8 100644
--- a/src/cli/commands/init.js
+++ b/src/cli/commands/init.js
@@ -5,7 +5,7 @@ const debug = require('debug')('ipfs:cli:init')
const { ipfsPathHelp } = require('../utils')
module.exports = {
- command: 'init [config] [options]',
+ command: 'init [default-config] [options]',
describe: 'Initialize a local IPFS node\n\n' +
'If you are going to run IPFS in a server environment, you may want to ' +
'initialize it using the \'server\' profile.\n\n' +
@@ -13,7 +13,7 @@ module.exports = {
builder (yargs) {
return yargs
.epilog(ipfsPathHelp)
- .positional('config', {
+ .positional('default-config', {
describe: 'Node config, this should be a path to a file or JSON and will be merged with the default config. See https://github.com/ipfs/js-ipfs#optionsconfig',
type: 'string'
})
diff --git a/src/core/components/init.js b/src/core/components/init.js
index 29798b0872..683c7fe702 100644
--- a/src/core/components/init.js
+++ b/src/core/components/init.js
@@ -56,7 +56,7 @@ async function createRepo (self, opts) {
const config = mergeOptions(defaultConfig(), self._options.config)
- applyProfile(config, opts)
+ applyProfile(self, config, opts)
// Verify repo does not exist yet
const exists = await self._repo.exists()
@@ -132,7 +132,7 @@ async function addRepoAssets (self, privateKey, opts) {
}
// Apply profiles (eg "server,lowpower") to config
-function applyProfile (config, opts) {
+function applyProfile (self, config, opts) {
if (opts.profile) {
const profileNames = opts.profile.split(',')
From bfaf98126aa64f91db977faa924279593d5a57f3 Mon Sep 17 00:00:00 2001
From: achingbrain
Date: Wed, 2 Oct 2019 11:15:49 +0100
Subject: [PATCH 06/18] chore: add http api tests
---
test/http-api/inject/config.js | 45 ++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/test/http-api/inject/config.js b/test/http-api/inject/config.js
index f361037569..13cfbbd418 100644
--- a/test/http-api/inject/config.js
+++ b/test/http-api/inject/config.js
@@ -6,6 +6,7 @@ const fs = require('fs')
const FormData = require('form-data')
const streamToPromise = require('stream-to-promise')
const path = require('path')
+const { profiles } = require('../../../src/core/components/config')
module.exports = (http) => {
describe('/config', () => {
@@ -13,10 +14,12 @@ module.exports = (http) => {
const originalConfigPath = path.join(__dirname, '../../fixtures/go-ipfs-repo/config')
let updatedConfig
+ let originalConfig
let api
before(() => {
updatedConfig = () => JSON.parse(fs.readFileSync(configPath, 'utf8'))
+ originalConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'))
api = http.api._httpApi._apiServers[0]
})
@@ -189,5 +192,47 @@ module.exports = (http) => {
expect(updatedConfig()).to.deep.equal(expectedConfig)
})
})
+
+ describe('/config/profile/apply', () => {
+ it('returns 400 if no config profile is provided', async () => {
+ const res = await api.inject({
+ method: 'POST',
+ url: '/api/v0/config/profile/apply'
+ })
+
+ expect(res.statusCode).to.equal(400)
+ })
+
+ it('returns 500 if the config profile is invalid', async () => {
+ const res = await api.inject({
+ method: 'POST',
+ url: '/api/v0/config/profile/apply?arg=derp'
+ })
+
+ expect(res.statusCode).to.equal(500)
+ })
+
+ it('does not apply config profile with dry-run argument', async () => {
+ const res = await api.inject({
+ method: 'POST',
+ url: '/api/v0/config/profile/apply?arg=lowpower&dry-run=true'
+ })
+
+ expect(res.statusCode).to.equal(200)
+ expect(updatedConfig()).to.deep.equal(originalConfig)
+ })
+
+ it('applies config profile', async () => {
+ const profile = 'lowpower'
+
+ const res = await api.inject({
+ method: 'POST',
+ url: `/api/v0/config/profile/apply?arg=${profile}`
+ })
+
+ expect(res.statusCode).to.equal(200)
+ expect(updatedConfig()).to.deep.equal(profiles[profile].transform(originalConfig))
+ })
+ })
})
}
From b72af945ea0ac46c35db96701655cc537825ff69 Mon Sep 17 00:00:00 2001
From: achingbrain
Date: Wed, 2 Oct 2019 11:16:33 +0100
Subject: [PATCH 07/18] chore: address PR comments
---
src/core/components/config.js | 132 ++++++++++++++++++-------------
src/http/api/resources/config.js | 2 +-
2 files changed, 78 insertions(+), 56 deletions(-)
diff --git a/src/core/components/config.js b/src/core/components/config.js
index acd4e70ffd..f29f3c53a6 100644
--- a/src/core/components/config.js
+++ b/src/core/components/config.js
@@ -1,7 +1,8 @@
'use strict'
const callbackify = require('callbackify')
-const defaultConfig = require('../runtime/config-nodejs.js')()
+const getDefaultConfig = require('../runtime/config-nodejs.js')
+const log = require('debug')('ipfs:core:config')
module.exports = function config (self) {
return {
@@ -15,7 +16,7 @@ module.exports = function config (self) {
opts = opts || {}
const { dryRun } = opts
- const profile = profiles.find(p => p.name === profileName)
+ const profile = profiles[profileName]
if (!profile) {
throw new Error(`No profile with name '${profileName}' exists`)
@@ -23,8 +24,8 @@ module.exports = function config (self) {
try {
const oldCfg = await self.config.get()
- const newCfg = JSON.parse(JSON.stringify(oldCfg)) // clone
- profile.transform(newCfg)
+ let newCfg = JSON.parse(JSON.stringify(oldCfg)) // clone
+ newCfg = profile.transform(newCfg)
if (!dryRun) {
await self.config.replace(newCfg)
@@ -36,62 +37,83 @@ module.exports = function config (self) {
return { oldCfg, newCfg }
} catch (err) {
+ log(err)
+
throw new Error(`Could not apply profile '${profileName}' to config: ${err.message}`)
}
}
}
-const profiles = [{
- name: 'server',
- description: 'Disables local host discovery - recommended when running IPFS on machines with public IPv4 addresses.',
- transform: (config) => {
- config.Discovery.MDNS.Enabled = false
- config.Discovery.webRTCStar.Enabled = false
- }
-}, {
- name: 'local-discovery',
- description: 'Enables local host discovery - inverse of "server" profile.',
- transform: (config) => {
- config.Discovery.MDNS.Enabled = true
- config.Discovery.webRTCStar.Enabled = true
- }
-}, {
- name: 'test',
- description: 'Reduces external interference of IPFS daemon - for running the daemon in test environments.',
- transform: (config) => {
- config.Addresses.API = defaultConfig.Addresses.API ? '/ip4/127.0.0.1/tcp/0' : ''
- config.Addresses.Gateway = defaultConfig.Addresses.Gateway ? '/ip4/127.0.0.1/tcp/0' : ''
- config.Addresses.Swarm = defaultConfig.Addresses.Swarm.length ? ['/ip4/127.0.0.1/tcp/0'] : []
- config.Bootstrap = []
- config.Discovery.MDNS.Enabled = false
- config.Discovery.webRTCStar.Enabled = false
- }
-}, {
- name: 'default-networking',
- description: 'Restores default network settings - inverse of "test" profile.',
- transform: (config) => {
- config.Addresses.API = defaultConfig.Addresses.API
- config.Addresses.Gateway = defaultConfig.Addresses.Gateway
- config.Addresses.Swarm = defaultConfig.Addresses.Swarm
- config.Bootstrap = defaultConfig.Bootstrap
- config.Discovery.MDNS.Enabled = defaultConfig.Discovery.MDNS.Enabled
- config.Discovery.webRTCStar.Enabled = defaultConfig.Discovery.webRTCStar.Enabled
- }
-}, {
- name: 'lowpower',
- description: 'Reduces daemon overhead on the system - recommended for low power systems.',
- transform: (config) => {
- config.Swarm = config.Swarm || {}
- config.Swarm.ConnMgr = config.Swarm.ConnMgr || {}
- config.Swarm.ConnMgr.LowWater = 20
- config.Swarm.ConnMgr.HighWater = 40
- }
-}, {
- name: 'default-power',
- description: 'Inverse of "lowpower" profile.',
- transform: (config) => {
- config.Swarm = defaultConfig.Swarm
+const profiles = {
+ server: {
+ description: 'Disables local host discovery - recommended when running IPFS on machines with public IPv4 addresses.',
+ transform: (config) => {
+ config.Discovery.MDNS.Enabled = false
+ config.Discovery.webRTCStar.Enabled = false
+
+ return config
+ }
+ },
+ 'local-discovery': {
+ description: 'Enables local host discovery - inverse of "server" profile.',
+ transform: (config) => {
+ config.Discovery.MDNS.Enabled = true
+ config.Discovery.webRTCStar.Enabled = true
+
+ return config
+ }
+ },
+ test: {
+ description: 'Reduces external interference of IPFS daemon - for running the daemon in test environments.',
+ transform: (config) => {
+ const defaultConfig = getDefaultConfig()
+
+ config.Addresses.API = defaultConfig.Addresses.API ? '/ip4/127.0.0.1/tcp/0' : ''
+ config.Addresses.Gateway = defaultConfig.Addresses.Gateway ? '/ip4/127.0.0.1/tcp/0' : ''
+ config.Addresses.Swarm = defaultConfig.Addresses.Swarm.length ? ['/ip4/127.0.0.1/tcp/0'] : []
+ config.Bootstrap = []
+ config.Discovery.MDNS.Enabled = false
+ config.Discovery.webRTCStar.Enabled = false
+
+ return config
+ }
+ },
+ 'default-networking': {
+ description: 'Restores default network settings - inverse of "test" profile.',
+ transform: (config) => {
+ const defaultConfig = getDefaultConfig()
+
+ config.Addresses.API = defaultConfig.Addresses.API
+ config.Addresses.Gateway = defaultConfig.Addresses.Gateway
+ config.Addresses.Swarm = defaultConfig.Addresses.Swarm
+ config.Bootstrap = defaultConfig.Bootstrap
+ config.Discovery.MDNS.Enabled = defaultConfig.Discovery.MDNS.Enabled
+ config.Discovery.webRTCStar.Enabled = defaultConfig.Discovery.webRTCStar.Enabled
+
+ return config
+ }
+ },
+ lowpower: {
+ description: 'Reduces daemon overhead on the system - recommended for low power systems.',
+ transform: (config) => {
+ config.Swarm = config.Swarm || {}
+ config.Swarm.ConnMgr = config.Swarm.ConnMgr || {}
+ config.Swarm.ConnMgr.LowWater = 20
+ config.Swarm.ConnMgr.HighWater = 40
+
+ return config
+ }
+ },
+ 'default-power': {
+ description: 'Inverse of "lowpower" profile.',
+ transform: (config) => {
+ const defaultConfig = getDefaultConfig()
+
+ config.Swarm = defaultConfig.Swarm
+
+ return config
+ }
}
-}]
+}
module.exports.profiles = profiles
diff --git a/src/http/api/resources/config.js b/src/http/api/resources/config.js
index 54f11edd93..78a1184058 100644
--- a/src/http/api/resources/config.js
+++ b/src/http/api/resources/config.js
@@ -179,7 +179,7 @@ exports.profile = {
throw Boom.badRequest("Argument 'profile' is required")
}
- if (!profiles.find(p => p.name === request.query.arg)) {
+ if (!profiles[request.query.arg]) {
throw Boom.badRequest("Argument 'profile' is not a valid profile name")
}
From 2c1fac7e0ffdb8a32f8547bb9ae84f2cef284d3e Mon Sep 17 00:00:00 2001
From: achingbrain
Date: Wed, 2 Oct 2019 11:17:02 +0100
Subject: [PATCH 08/18] chore: fix linting
---
test/cli/init.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/cli/init.js b/test/cli/init.js
index 833affe8c4..1c11b189d5 100644
--- a/test/cli/init.js
+++ b/test/cli/init.js
@@ -90,7 +90,7 @@ describe('init', function () {
}
})
- it('should present ipfs path help when option help is received', async function () {
+ it('should present ipfs path help when option help is received', async function () {
const res = await ipfs('init --help')
expect(res).to.have.string('export IPFS_PATH=/path/to/ipfsrepo')
From efc6bd0d58c5188efb67611a21af7fcc84893ba1 Mon Sep 17 00:00:00 2001
From: achingbrain
Date: Wed, 2 Oct 2019 11:37:09 +0100
Subject: [PATCH 09/18] test: let internals of config profiles be internal
---
test/cli/config.js | 51 +++++++++++-----------------------------------
1 file changed, 12 insertions(+), 39 deletions(-)
diff --git a/test/cli/config.js b/test/cli/config.js
index f8dcf98eff..da28fe1c86 100644
--- a/test/cli/config.js
+++ b/test/cli/config.js
@@ -9,6 +9,7 @@ const fs = require('fs')
const path = require('path')
const runOnAndOff = require('../utils/on-and-off')
const defaultConfig = require('../../src/core/runtime/config-nodejs')()
+const { profiles } = require('../../src/core/components/config')
describe('config', () => runOnAndOff((thing) => {
let ipfs
@@ -94,51 +95,23 @@ describe('config', () => runOnAndOff((thing) => {
describe('profile', function () {
this.timeout(40 * 1000)
- beforeEach(() => restoreConfig())
- after(() => restoreConfig())
+ let originalConfig
- it('server / local-discovery', async () => {
- await ipfs('config profile apply server')
- const updated = updatedConfig()
- expect(updated.Discovery.MDNS.Enabled).to.equal(false)
- expect(updated.Discovery.webRTCStar.Enabled).to.equal(false)
-
- await ipfs('config profile apply local-discovery')
- const reversed = updatedConfig()
- expect(reversed.Discovery.MDNS.Enabled).to.equal(true)
- expect(reversed.Discovery.webRTCStar.Enabled).to.equal(true)
+ beforeEach(() => {
+ restoreConfig()
+ originalConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'))
})
- it('test / default-networking', async () => {
- await ipfs('config profile apply test')
- const updated = updatedConfig()
- expect(updated.Addresses.API).to.equal('/ip4/127.0.0.1/tcp/0')
- expect(updated.Addresses.Gateway).to.equal('/ip4/127.0.0.1/tcp/0')
- expect(updated.Addresses.Swarm).to.eql(['/ip4/127.0.0.1/tcp/0'])
- expect(updated.Bootstrap).to.eql([])
- expect(updated.Discovery.MDNS.Enabled).to.equal(false)
- expect(updated.Discovery.webRTCStar.Enabled).to.equal(false)
-
- await ipfs('config profile apply default-networking')
- const reversed = updatedConfig()
- expect(reversed.Addresses.API).to.equal(defaultConfig.Addresses.API)
- expect(reversed.Addresses.Gateway).to.equal(defaultConfig.Addresses.Gateway)
- expect(reversed.Addresses.Swarm).to.eql(defaultConfig.Addresses.Swarm)
- expect(reversed.Bootstrap).to.eql(defaultConfig.Bootstrap)
- expect(reversed.Discovery.MDNS.Enabled).to.equal(true)
- expect(reversed.Discovery.webRTCStar.Enabled).to.equal(true)
+ after(() => {
+ restoreConfig()
})
- it('lowpower / default-power', async () => {
- await ipfs('config profile apply lowpower')
- const updated = updatedConfig()
- expect(updated.Swarm.ConnMgr.LowWater).to.equal(20)
- expect(updated.Swarm.ConnMgr.HighWater).to.equal(40)
+ Object.keys(profiles).forEach(profile => {
+ it(`applies profile '${profile}'`, async () => {
+ await ipfs(`config profile apply ${profile}`)
- await ipfs('config profile apply default-power')
- const reversed = updatedConfig()
- expect(reversed.Swarm.ConnMgr.LowWater).to.equal(defaultConfig.Swarm.ConnMgr.LowWater)
- expect(reversed.Swarm.ConnMgr.HighWater).to.equal(defaultConfig.Swarm.ConnMgr.HighWater)
+ expect(updatedConfig()).to.deep.equal(profiles[profile].transform(originalConfig))
+ })
})
it('--dry-run causes no change', async () => {
From df86a2381a273304fe550a2e793d4191e2ae475a Mon Sep 17 00:00:00 2001
From: achingbrain
Date: Wed, 2 Oct 2019 11:59:41 +0100
Subject: [PATCH 10/18] chore: add test for listing profiles
---
src/cli/commands/config/profile/ls.js | 4 ++-
src/core/components/config.js | 42 +++++++++++++--------------
test/cli/config.js | 9 ++++++
3 files changed, 33 insertions(+), 22 deletions(-)
diff --git a/src/cli/commands/config/profile/ls.js b/src/cli/commands/config/profile/ls.js
index 4301fef2d5..39f070db6d 100644
--- a/src/cli/commands/config/profile/ls.js
+++ b/src/cli/commands/config/profile/ls.js
@@ -11,7 +11,9 @@ module.exports = {
handler (argv) {
argv.resolve(
- profiles.map(p => p.name + ':\n ' + p.description).join('\n')
+ Object.keys(profiles)
+ .map(profile => `${profile}:\n ${profiles[profile].description}`)
+ .join('\n')
)
}
}
diff --git a/src/core/components/config.js b/src/core/components/config.js
index f29f3c53a6..f78ea017cc 100644
--- a/src/core/components/config.js
+++ b/src/core/components/config.js
@@ -63,6 +63,27 @@ const profiles = {
return config
}
},
+ lowpower: {
+ description: 'Reduces daemon overhead on the system - recommended for low power systems.',
+ transform: (config) => {
+ config.Swarm = config.Swarm || {}
+ config.Swarm.ConnMgr = config.Swarm.ConnMgr || {}
+ config.Swarm.ConnMgr.LowWater = 20
+ config.Swarm.ConnMgr.HighWater = 40
+
+ return config
+ }
+ },
+ 'default-power': {
+ description: 'Inverse of "lowpower" profile.',
+ transform: (config) => {
+ const defaultConfig = getDefaultConfig()
+
+ config.Swarm = defaultConfig.Swarm
+
+ return config
+ }
+ },
test: {
description: 'Reduces external interference of IPFS daemon - for running the daemon in test environments.',
transform: (config) => {
@@ -90,27 +111,6 @@ const profiles = {
config.Discovery.MDNS.Enabled = defaultConfig.Discovery.MDNS.Enabled
config.Discovery.webRTCStar.Enabled = defaultConfig.Discovery.webRTCStar.Enabled
- return config
- }
- },
- lowpower: {
- description: 'Reduces daemon overhead on the system - recommended for low power systems.',
- transform: (config) => {
- config.Swarm = config.Swarm || {}
- config.Swarm.ConnMgr = config.Swarm.ConnMgr || {}
- config.Swarm.ConnMgr.LowWater = 20
- config.Swarm.ConnMgr.HighWater = 40
-
- return config
- }
- },
- 'default-power': {
- description: 'Inverse of "lowpower" profile.',
- transform: (config) => {
- const defaultConfig = getDefaultConfig()
-
- config.Swarm = defaultConfig.Swarm
-
return config
}
}
diff --git a/test/cli/config.js b/test/cli/config.js
index da28fe1c86..967fe04847 100644
--- a/test/cli/config.js
+++ b/test/cli/config.js
@@ -128,5 +128,14 @@ describe('config', () => runOnAndOff((thing) => {
const out = await ipfs('config profile apply server')
expect(out).not.includes('PrivKey')
})
+
+ it('lists available config profiles', async () => {
+ const out = await ipfs('config profile ls')
+
+ Object.keys(profiles => profile => {
+ expect(out).includes(profiles[profile].name)
+ expect(out).includes(profiles[profile].description)
+ })
+ })
})
}))
From cb750054c9d2ff8ffd008bf3a8be1a2b1431e5c4 Mon Sep 17 00:00:00 2001
From: achingbrain
Date: Wed, 2 Oct 2019 13:12:53 +0100
Subject: [PATCH 11/18] chore: turn profile list into list outside of core
---
README.md | 4 ++--
src/cli/commands/init.js | 7 +++++--
src/core/components/init.js | 12 +++++-------
3 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/README.md b/README.md
index 35223f525f..e8f6fcb56a 100644
--- a/README.md
+++ b/README.md
@@ -9,9 +9,9 @@
-
+
-
+
diff --git a/src/cli/commands/init.js b/src/cli/commands/init.js
index b3b65cacb8..02fd90c675 100644
--- a/src/cli/commands/init.js
+++ b/src/cli/commands/init.js
@@ -36,7 +36,10 @@ module.exports = {
.option('profile', {
alias: 'p',
type: 'string',
- describe: 'Apply profile settings to config. Multiple profiles can be separated by \',\''
+ describe: 'Apply profile settings to config. Multiple profiles can be separated by \',\'',
+ coerce: (value) => {
+ return (value || '').split(',')
+ }
})
},
@@ -74,7 +77,7 @@ module.exports = {
bits: argv.bits,
privateKey: argv.privateKey,
emptyRepo: argv.emptyRepo,
- profile: argv.profile,
+ profiles: argv.profile,
pass: argv.pass,
log: argv.print
})
diff --git a/src/core/components/init.js b/src/core/components/init.js
index 683c7fe702..768a8dd24e 100644
--- a/src/core/components/init.js
+++ b/src/core/components/init.js
@@ -133,17 +133,15 @@ async function addRepoAssets (self, privateKey, opts) {
// Apply profiles (eg "server,lowpower") to config
function applyProfile (self, config, opts) {
- if (opts.profile) {
- const profileNames = opts.profile.split(',')
-
- for (const profileName of profileNames) {
- const profile = profiles.find(p => p.name === profileName)
+ if (opts.profiles) {
+ for (const name of opts.profiles) {
+ const profile = profiles[name]
if (!profile) {
- throw new Error(`Could not find profile with name '${profileName}'`)
+ throw new Error(`Could not find profile with name '${name}'`)
}
- self.log(`applying profile ${profileName}`)
+ self.log(`applying profile ${name}`)
profile.transform(config)
}
}
From 078a3b732e457e1a9fa2d516a6a004d135236b97 Mon Sep 17 00:00:00 2001
From: achingbrain
Date: Thu, 3 Oct 2019 13:22:16 +0100
Subject: [PATCH 12/18] chore: expose profile list over http
---
package.json | 4 +-
src/cli/commands/config/profile/apply.js | 16 ++++--
src/cli/commands/config/profile/ls.js | 12 +++--
src/core/components/config.js | 14 ++++-
src/http/api/resources/config.js | 66 ++++++++++++++----------
src/http/api/routes/config.js | 11 ++--
test/http-api/inject/config.js | 40 +++++++++++---
7 files changed, 114 insertions(+), 49 deletions(-)
diff --git a/package.json b/package.json
index d4035fd5a6..0c16899de4 100644
--- a/package.json
+++ b/package.json
@@ -99,7 +99,7 @@
"ipfs-bitswap": "^0.26.0",
"ipfs-block": "~0.8.1",
"ipfs-block-service": "~0.16.0",
- "ipfs-http-client": "^38.0.0",
+ "ipfs-http-client": "ipfs/js-ipfs-http-client#ad8169a8b68fcd48f5eba1b3d820bc3bc54142a9",
"ipfs-http-response": "~0.3.1",
"ipfs-mfs": "^0.13.0",
"ipfs-multipart": "^0.2.0",
@@ -205,7 +205,7 @@
"execa": "^2.0.4",
"form-data": "^2.5.1",
"hat": "0.0.3",
- "interface-ipfs-core": "^0.115.1",
+ "interface-ipfs-core": "ipfs/interface-js-ipfs-core#30118c715d95582eaf65fdf8cb0ee240c504cb1e",
"ipfs-interop": "~0.1.0",
"ipfsd-ctl": "^0.47.2",
"libp2p-websocket-star": "~0.10.2",
diff --git a/src/cli/commands/config/profile/apply.js b/src/cli/commands/config/profile/apply.js
index d341b3049b..eb0d066f06 100644
--- a/src/cli/commands/config/profile/apply.js
+++ b/src/cli/commands/config/profile/apply.js
@@ -17,9 +17,19 @@ module.exports = {
handler (argv) {
argv.resolve((async () => {
const ipfs = await argv.getIpfs()
- const diff = await ipfs.config.profile(argv.profile, { dryRun: argv.dryRun })
- const delta = JSONDiff.diff(diff.oldCfg, diff.newCfg)
- return JSONDiff.formatters.console.format(delta, diff.oldCfg)
+ const diff = await ipfs.config.profiles.apply(argv.profile, { dryRun: argv.dryRun })
+ const delta = JSONDiff.diff(diff.old, diff.new)
+ const res = JSONDiff.formatters.console.format(delta, diff.old)
+
+ if (res) {
+ argv.print(res)
+
+ if (ipfs.send) {
+ argv.print('\nThe IPFS daemon is running in the background, you may need to restart it for changes to take effect.')
+ }
+ } else {
+ argv.print(`IPFS config already contains the settings from the '${argv.profile}' profile`)
+ }
})())
}
}
diff --git a/src/cli/commands/config/profile/ls.js b/src/cli/commands/config/profile/ls.js
index 39f070db6d..04bb74e37f 100644
--- a/src/cli/commands/config/profile/ls.js
+++ b/src/cli/commands/config/profile/ls.js
@@ -1,7 +1,5 @@
'use strict'
-const { profiles } = require('../../../../core/components/config')
-
module.exports = {
command: 'ls',
@@ -11,9 +9,13 @@ module.exports = {
handler (argv) {
argv.resolve(
- Object.keys(profiles)
- .map(profile => `${profile}:\n ${profiles[profile].description}`)
- .join('\n')
+ (async () => {
+ const ipfs = await argv.getIpfs()
+
+ for (const profile of await ipfs.config.profiles.list()) {
+ argv.print(`${profile.name}:\n ${profile.description}`)
+ }
+ })()
)
}
}
diff --git a/src/core/components/config.js b/src/core/components/config.js
index f78ea017cc..e364bb837d 100644
--- a/src/core/components/config.js
+++ b/src/core/components/config.js
@@ -9,7 +9,10 @@ module.exports = function config (self) {
get: callbackify.variadic(self._repo.config.get),
set: callbackify(self._repo.config.set),
replace: callbackify.variadic(self._repo.config.set),
- profile: callbackify.variadic(applyProfile)
+ profiles: {
+ apply: callbackify.variadic(applyProfile),
+ list: callbackify.variadic(listProfiles)
+ }
}
async function applyProfile (profileName, opts) {
@@ -35,7 +38,7 @@ module.exports = function config (self) {
delete oldCfg.Identity.PrivKey
delete newCfg.Identity.PrivKey
- return { oldCfg, newCfg }
+ return { old: oldCfg, new: newCfg }
} catch (err) {
log(err)
@@ -44,6 +47,13 @@ module.exports = function config (self) {
}
}
+async function listProfiles (options) { // eslint-disable-line require-await
+ return Object.keys(profiles).map(name => ({
+ name,
+ description: profiles[name].description
+ }))
+}
+
const profiles = {
server: {
description: 'Disables local host discovery - recommended when running IPFS on machines with public IPv4 addresses.',
diff --git a/src/http/api/resources/config.js b/src/http/api/resources/config.js
index 78a1184058..fd0b13048d 100644
--- a/src/http/api/resources/config.js
+++ b/src/http/api/resources/config.js
@@ -167,37 +167,51 @@ exports.replace = {
}
exports.profile = {
- validate: {
- query: Joi.object().keys({
- 'dry-run': Joi.boolean().default(false)
- }).unknown()
- },
+ apply: {
+ validate: {
+ query: Joi.object().keys({
+ 'dry-run': Joi.boolean().default(false)
+ }).unknown()
+ },
+
+ // pre request handler that parses the args and returns `profile` which is assigned to `request.pre.args`
+ parseArgs: function (request, h) {
+ if (!request.query.arg) {
+ throw Boom.badRequest("Argument 'profile' is required")
+ }
- // pre request handler that parses the args and returns `profile` which is assigned to `request.pre.args`
- parseArgs: function (request, h) {
- if (!request.query.arg) {
- throw Boom.badRequest("Argument 'profile' is required")
- }
+ if (!profiles[request.query.arg]) {
+ throw Boom.badRequest("Argument 'profile' is not a valid profile name")
+ }
- if (!profiles[request.query.arg]) {
- throw Boom.badRequest("Argument 'profile' is not a valid profile name")
- }
+ return { profile: request.query.arg }
+ },
- return { profile: request.query.arg }
- },
+ handler: async function (request, h) {
+ const { ipfs } = request.server.app
+ const { profile } = request.pre.args
+ const dryRun = request.query['dry-run']
- handler: async function (request, h) {
- const { ipfs } = request.server.app
- const { profile } = request.pre.args
- const dryRun = request.query['dry-run']
+ try {
+ const diff = await ipfs.config.profiles.apply(profile, { dryRun })
- let diff
- try {
- diff = await ipfs.config.profile(profile, { dryRun })
- } catch (err) {
- throw Boom.boomify(err, { message: 'Failed to apply profile' })
+ return h.response({ OldCfg: diff.old, NewCfg: diff.new })
+ } catch (err) {
+ throw Boom.boomify(err, { message: 'Failed to apply profile' })
+ }
+ }
+ },
+ list: {
+ handler: async function (request, h) {
+ const { ipfs } = request.server.app
+ const list = await ipfs.config.profiles.list()
+
+ return h.response(
+ list.map(profile => ({
+ Name: profile.name,
+ Description: profile.description
+ }))
+ )
}
-
- return h.response({ OldCfg: diff.oldCfg, NewCfg: diff.newCfg })
}
}
diff --git a/src/http/api/routes/config.js b/src/http/api/routes/config.js
index 0bd127666a..db94c0ba4b 100644
--- a/src/http/api/routes/config.js
+++ b/src/http/api/routes/config.js
@@ -37,10 +37,15 @@ module.exports = [
path: '/api/v0/config/profile/apply',
options: {
pre: [
- { method: resources.config.profile.parseArgs, assign: 'args' }
+ { method: resources.config.profile.apply.parseArgs, assign: 'args' }
],
- validate: resources.config.profile.validate
+ validate: resources.config.profile.apply.validate
},
- handler: resources.config.profile.handler
+ handler: resources.config.profile.apply.handler
+ },
+ {
+ method: '*',
+ path: '/api/v0/config/profile/list',
+ handler: resources.config.profile.list.handler
}
]
diff --git a/test/http-api/inject/config.js b/test/http-api/inject/config.js
index 13cfbbd418..513f46c922 100644
--- a/test/http-api/inject/config.js
+++ b/test/http-api/inject/config.js
@@ -14,12 +14,10 @@ module.exports = (http) => {
const originalConfigPath = path.join(__dirname, '../../fixtures/go-ipfs-repo/config')
let updatedConfig
- let originalConfig
let api
before(() => {
updatedConfig = () => JSON.parse(fs.readFileSync(configPath, 'utf8'))
- originalConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'))
api = http.api._httpApi._apiServers[0]
})
@@ -194,6 +192,12 @@ module.exports = (http) => {
})
describe('/config/profile/apply', () => {
+ let originalConfig
+
+ beforeEach(() => {
+ originalConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'))
+ })
+
it('returns 400 if no config profile is provided', async () => {
const res = await api.inject({
method: 'POST',
@@ -203,13 +207,13 @@ module.exports = (http) => {
expect(res.statusCode).to.equal(400)
})
- it('returns 500 if the config profile is invalid', async () => {
+ it('returns 400 if the config profile is invalid', async () => {
const res = await api.inject({
method: 'POST',
url: '/api/v0/config/profile/apply?arg=derp'
})
- expect(res.statusCode).to.equal(500)
+ expect(res.statusCode).to.equal(400)
})
it('does not apply config profile with dry-run argument', async () => {
@@ -222,16 +226,36 @@ module.exports = (http) => {
expect(updatedConfig()).to.deep.equal(originalConfig)
})
- it('applies config profile', async () => {
- const profile = 'lowpower'
+ Object.keys(profiles).forEach(profile => {
+ it(`applies config profile ${profile}`, async () => {
+ const res = await api.inject({
+ method: 'POST',
+ url: `/api/v0/config/profile/apply?arg=${profile}`
+ })
+ expect(res.statusCode).to.equal(200)
+ expect(updatedConfig()).to.deep.equal(profiles[profile].transform(originalConfig))
+ })
+ })
+ })
+
+ describe('/config/profile/list', () => {
+ it('lists available profiles', async () => {
const res = await api.inject({
method: 'POST',
- url: `/api/v0/config/profile/apply?arg=${profile}`
+ url: '/api/v0/config/profile/list'
})
expect(res.statusCode).to.equal(200)
- expect(updatedConfig()).to.deep.equal(profiles[profile].transform(originalConfig))
+
+ const listed = JSON.parse(res.payload)
+
+ Object.keys(profiles).forEach(name => {
+ const profile = listed.find(profile => profile.Name === name)
+
+ expect(profile).to.be.ok()
+ expect(profile.Description).to.equal(profiles[name].description)
+ })
})
})
})
From 92708e33d10272489d93f143989460a6eaa25d31 Mon Sep 17 00:00:00 2001
From: achingbrain
Date: Thu, 3 Oct 2019 13:45:07 +0100
Subject: [PATCH 13/18] fix: use chai exported from interface tests
Workaround for https://github.com/chaijs/chai/issues/1298
---
package.json | 2 --
test/cli/bitswap.js | 2 +-
test/cli/block.js | 2 +-
test/cli/bootstrap.js | 2 +-
test/cli/commands.js | 2 +-
test/cli/config.js | 5 +----
test/cli/daemon.js | 2 +-
test/cli/dag.js | 2 +-
test/cli/dht.js | 6 +-----
test/cli/dns.js | 2 +-
test/cli/file.js | 2 +-
test/cli/files.js | 2 +-
test/cli/general.js | 2 +-
test/cli/id.js | 5 +----
test/cli/init.js | 2 +-
test/cli/key.js | 2 +-
test/cli/ls.js | 2 +-
test/cli/name-pubsub.js | 5 +----
test/cli/object.js | 2 +-
test/cli/parser.js | 5 +----
test/cli/pin.js | 2 +-
test/cli/ping.js | 5 +----
test/cli/progress-bar.js | 2 +-
test/cli/pubsub.js | 5 +----
test/cli/refs-local.js | 2 +-
test/cli/refs.js | 2 +-
test/cli/repo.js | 2 +-
test/cli/swarm.js | 5 +----
test/cli/version.js | 2 +-
test/core/bitswap.spec.js | 5 +----
test/core/block.spec.js | 5 +----
test/core/bootstrap.spec.js | 6 +-----
test/core/circuit-relay.js | 6 +-----
test/core/config.spec.js | 6 +-----
test/core/create-node.spec.js | 5 +----
test/core/dag.spec.js | 6 +-----
test/core/dht.spec.js | 6 +-----
test/core/exports.spec.js | 5 +----
test/core/files-regular-utils.js | 5 +----
test/core/files-sharding.spec.js | 5 +----
test/core/files.spec.js | 5 +----
test/core/gc-lock.spec.js | 6 +-----
test/core/gc.spec.js | 6 +-----
test/core/init.spec.js | 5 +----
test/core/kad-dht.node.js | 5 +----
test/core/key-exchange.js | 5 +----
test/core/libp2p.spec.js | 6 +-----
test/core/mfs-preload.spec.js | 6 +-----
test/core/name-pubsub.js | 6 +-----
test/core/name.spec.js | 7 +------
test/core/object.spec.js | 5 +----
test/core/pin-set.js | 6 +-----
test/core/pin.js | 7 +------
test/core/pin.spec.js | 6 +-----
test/core/ping.spec.js | 5 +----
test/core/preload.spec.js | 5 +----
test/core/pubsub.spec.js | 6 +-----
test/core/stats.spec.js | 6 +-----
test/core/swarm.spec.js | 6 +-----
test/core/utils.js | 6 +-----
test/gateway/index.js | 5 +----
test/http-api/inject/bitswap.js | 2 +-
test/http-api/inject/block.js | 2 +-
test/http-api/inject/bootstrap.js | 2 +-
test/http-api/inject/config.js | 2 +-
test/http-api/inject/dag.js | 5 +----
test/http-api/inject/dht.js | 5 +----
test/http-api/inject/dns.js | 2 +-
test/http-api/inject/files.js | 2 +-
test/http-api/inject/id.js | 2 +-
test/http-api/inject/name.js | 7 +------
test/http-api/inject/object.js | 6 +-----
test/http-api/inject/pin.js | 2 +-
test/http-api/inject/ping.js | 6 +-----
test/http-api/inject/pubsub.js | 5 +----
test/http-api/inject/resolve.js | 2 +-
test/http-api/inject/version.js | 2 +-
test/http-api/routes.js | 4 +---
test/utils/ipfs-exec.js | 4 +---
79 files changed, 78 insertions(+), 247 deletions(-)
diff --git a/package.json b/package.json
index 0c16899de4..0fb7ba16a1 100644
--- a/package.json
+++ b/package.json
@@ -196,12 +196,10 @@
"devDependencies": {
"aegir": "^20.3.1",
"base64url": "^3.0.1",
- "chai": "^4.2.0",
"clear-module": "^4.0.0",
"delay": "^4.1.0",
"detect-node": "^2.0.4",
"dir-compare": "^1.7.3",
- "dirty-chai": "^2.0.1",
"execa": "^2.0.4",
"form-data": "^2.5.1",
"hat": "0.0.3",
diff --git a/test/cli/bitswap.js b/test/cli/bitswap.js
index cac76152b3..c22cefe81c 100644
--- a/test/cli/bitswap.js
+++ b/test/cli/bitswap.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const runOn = require('../utils/on-and-off').on
const PeerId = require('peer-id')
const CID = require('cids')
diff --git a/test/cli/block.js b/test/cli/block.js
index c00e06caf7..ee0d47b86f 100644
--- a/test/cli/block.js
+++ b/test/cli/block.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const runOnAndOff = require('../utils/on-and-off')
describe('block', () => runOnAndOff((thing) => {
diff --git a/test/cli/bootstrap.js b/test/cli/bootstrap.js
index 262f80e97e..3d5f0f6562 100644
--- a/test/cli/bootstrap.js
+++ b/test/cli/bootstrap.js
@@ -2,7 +2,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const runOnAndOff = require('../utils/on-and-off')
describe('bootstrap', () => runOnAndOff((thing) => {
diff --git a/test/cli/commands.js b/test/cli/commands.js
index 168fbc887d..23cc091bd2 100644
--- a/test/cli/commands.js
+++ b/test/cli/commands.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const runOnAndOff = require('../utils/on-and-off')
const commandCount = 98
diff --git a/test/cli/config.js b/test/cli/config.js
index 967fe04847..6b7741dcae 100644
--- a/test/cli/config.js
+++ b/test/cli/config.js
@@ -1,10 +1,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const fs = require('fs')
const path = require('path')
const runOnAndOff = require('../utils/on-and-off')
diff --git a/test/cli/daemon.js b/test/cli/daemon.js
index 1be77940d6..0bee3e507e 100644
--- a/test/cli/daemon.js
+++ b/test/cli/daemon.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const clean = require('../utils/clean')
const ipfsCmd = require('../utils/ipfs-exec')
const isWindows = require('../utils/platforms').isWindows
diff --git a/test/cli/dag.js b/test/cli/dag.js
index f4094777eb..8fbad2e458 100644
--- a/test/cli/dag.js
+++ b/test/cli/dag.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const runOnAndOff = require('../utils/on-and-off')
const path = require('path')
diff --git a/test/cli/dht.js b/test/cli/dht.js
index 3e066ac270..71b2012155 100644
--- a/test/cli/dht.js
+++ b/test/cli/dht.js
@@ -2,11 +2,7 @@
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const path = require('path')
const DaemonFactory = require('ipfsd-ctl')
const df = DaemonFactory.create({
diff --git a/test/cli/dns.js b/test/cli/dns.js
index 93e4610e3b..34722404ad 100644
--- a/test/cli/dns.js
+++ b/test/cli/dns.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const runOnAndOff = require('../utils/on-and-off')
const isIPFS = require('is-ipfs')
diff --git a/test/cli/file.js b/test/cli/file.js
index f7852c89ef..86a15d499d 100644
--- a/test/cli/file.js
+++ b/test/cli/file.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const runOnAndOff = require('../utils/on-and-off')
const file = 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV'
const dir = 'Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z'
diff --git a/test/cli/files.js b/test/cli/files.js
index 62c3139b0c..868fdd1f36 100644
--- a/test/cli/files.js
+++ b/test/cli/files.js
@@ -3,7 +3,7 @@
const fs = require('fs')
const os = require('os')
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const path = require('path')
const hat = require('hat')
const compareDir = require('dir-compare').compareSync
diff --git a/test/cli/general.js b/test/cli/general.js
index ee26a51e67..4bff0d095d 100644
--- a/test/cli/general.js
+++ b/test/cli/general.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const runOnAndOff = require('../utils/on-and-off')
describe('general cli options', () => runOnAndOff.off((thing) => {
diff --git a/test/cli/id.js b/test/cli/id.js
index b3f6102003..3498d0d240 100644
--- a/test/cli/id.js
+++ b/test/cli/id.js
@@ -2,12 +2,9 @@
'use strict'
const sinon = require('sinon')
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const YargsPromise = require('yargs-promise')
const clearModule = require('clear-module')
-chai.use(dirtyChai)
describe('id', () => {
let cli
diff --git a/test/cli/init.js b/test/cli/init.js
index 1c11b189d5..97bb486fbc 100644
--- a/test/cli/init.js
+++ b/test/cli/init.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const path = require('path')
const fs = require('fs')
const clean = require('../utils/clean')
diff --git a/test/cli/key.js b/test/cli/key.js
index d75f88bf0b..90b5992421 100644
--- a/test/cli/key.js
+++ b/test/cli/key.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const runOnAndOff = require('../utils/on-and-off')
const hat = require('hat')
diff --git a/test/cli/ls.js b/test/cli/ls.js
index d86c17490b..bd5870c6fa 100644
--- a/test/cli/ls.js
+++ b/test/cli/ls.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const runOnAndOff = require('../utils/on-and-off')
const delay = require('delay')
diff --git a/test/cli/name-pubsub.js b/test/cli/name-pubsub.js
index f3e1126039..af899501d2 100644
--- a/test/cli/name-pubsub.js
+++ b/test/cli/name-pubsub.js
@@ -2,10 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const path = require('path')
const ipfsExec = require('../utils/ipfs-exec')
diff --git a/test/cli/object.js b/test/cli/object.js
index d653e2fb82..7ccdb856f9 100644
--- a/test/cli/object.js
+++ b/test/cli/object.js
@@ -3,7 +3,7 @@
'use strict'
const hat = require('hat')
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const runOnAndOff = require('../utils/on-and-off')
const UnixFs = require('ipfs-unixfs')
const path = require('path')
diff --git a/test/cli/parser.js b/test/cli/parser.js
index 660def1f60..3352f16fcb 100644
--- a/test/cli/parser.js
+++ b/test/cli/parser.js
@@ -1,10 +1,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const parser = require('../../src/cli/parser')
const YargsPromise = require('yargs-promise')
diff --git a/test/cli/pin.js b/test/cli/pin.js
index d8aa5e23c6..20a777be92 100644
--- a/test/cli/pin.js
+++ b/test/cli/pin.js
@@ -2,7 +2,7 @@
/* eslint max-nested-callbacks: ["error", 8] */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const CID = require('cids')
const runOnAndOff = require('../utils/on-and-off')
const path = require('path')
diff --git a/test/cli/ping.js b/test/cli/ping.js
index 6d843bc113..66216fe0d2 100644
--- a/test/cli/ping.js
+++ b/test/cli/ping.js
@@ -2,8 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const DaemonFactory = require('ipfsd-ctl')
const ipfsExec = require('../utils/ipfs-exec')
const path = require('path')
@@ -11,8 +10,6 @@ const df = DaemonFactory.create({
type: 'js',
IpfsClient: require('ipfs-http-client')
})
-const expect = chai.expect
-chai.use(dirtyChai)
const config = {
Bootstrap: [],
diff --git a/test/cli/progress-bar.js b/test/cli/progress-bar.js
index 21708a59f8..353222a2a2 100644
--- a/test/cli/progress-bar.js
+++ b/test/cli/progress-bar.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const createProgressBar = require('../../src/cli/utils').createProgressBar
describe('progress bar', () => {
diff --git a/test/cli/pubsub.js b/test/cli/pubsub.js
index 017b665ce1..5255946ee1 100644
--- a/test/cli/pubsub.js
+++ b/test/cli/pubsub.js
@@ -2,10 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const delay = require('delay')
const series = require('async/series')
const ipfsExec = require('../utils/ipfs-exec')
diff --git a/test/cli/refs-local.js b/test/cli/refs-local.js
index 0232c3a9d3..6b1e5fc872 100644
--- a/test/cli/refs-local.js
+++ b/test/cli/refs-local.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const runOnAndOff = require('../utils/on-and-off')
describe('refs-local', () => runOnAndOff((thing) => {
diff --git a/test/cli/refs.js b/test/cli/refs.js
index bd7704d400..e102dfd067 100644
--- a/test/cli/refs.js
+++ b/test/cli/refs.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const runOnAndOff = require('../utils/on-and-off')
// Note: There are more comprehensive tests in interface-js-ipfs-core
diff --git a/test/cli/repo.js b/test/cli/repo.js
index f47437f67f..f5e47d7eb7 100644
--- a/test/cli/repo.js
+++ b/test/cli/repo.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const repoVersion = require('ipfs-repo').repoVersion
const runOnAndOff = require('../utils/on-and-off')
diff --git a/test/cli/swarm.js b/test/cli/swarm.js
index 2fca1d2899..0ec1b1b00b 100644
--- a/test/cli/swarm.js
+++ b/test/cli/swarm.js
@@ -2,10 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const sinon = require('sinon')
const ipfsExec = require('../utils/ipfs-exec')
const path = require('path')
diff --git a/test/cli/version.js b/test/cli/version.js
index 67fe53a295..4aa053ccad 100644
--- a/test/cli/version.js
+++ b/test/cli/version.js
@@ -3,7 +3,7 @@
'use strict'
const os = require('os')
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const repoVersion = require('ipfs-repo').repoVersion
const pkgversion = require('../../package.json').version
const runOnAndOff = require('../utils/on-and-off')
diff --git a/test/core/bitswap.spec.js b/test/core/bitswap.spec.js
index eaa368b7a2..deee69150e 100644
--- a/test/core/bitswap.spec.js
+++ b/test/core/bitswap.spec.js
@@ -3,10 +3,7 @@
'use strict'
const hat = require('hat')
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const _ = require('lodash')
const series = require('async/series')
const waterfall = require('async/waterfall')
diff --git a/test/core/block.spec.js b/test/core/block.spec.js
index c4c54bc3b3..68d11fc66d 100644
--- a/test/core/block.spec.js
+++ b/test/core/block.spec.js
@@ -2,10 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const hat = require('hat')
const IPFSFactory = require('ipfsd-ctl')
diff --git a/test/core/bootstrap.spec.js b/test/core/bootstrap.spec.js
index e8928b0e9b..566ffa3b7e 100644
--- a/test/core/bootstrap.spec.js
+++ b/test/core/bootstrap.spec.js
@@ -1,11 +1,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const isNode = require('detect-node')
const IPFS = require('../../src')
diff --git a/test/core/circuit-relay.js b/test/core/circuit-relay.js
index 628544e520..751f382bd3 100644
--- a/test/core/circuit-relay.js
+++ b/test/core/circuit-relay.js
@@ -2,11 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const waterfall = require('async/waterfall')
const multiaddr = require('multiaddr')
const crypto = require('crypto')
diff --git a/test/core/config.spec.js b/test/core/config.spec.js
index f884f74348..bd5fa43814 100644
--- a/test/core/config.spec.js
+++ b/test/core/config.spec.js
@@ -1,11 +1,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const config = require('../../src/core/config')
describe('config', () => {
diff --git a/test/core/create-node.spec.js b/test/core/create-node.spec.js
index 8c7d2a88a6..7d77fc7ded 100644
--- a/test/core/create-node.spec.js
+++ b/test/core/create-node.spec.js
@@ -2,10 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const series = require('async/series')
const sinon = require('sinon')
const waterfall = require('async/waterfall')
diff --git a/test/core/dag.spec.js b/test/core/dag.spec.js
index b5dc5b1fbf..a9c184a2cd 100644
--- a/test/core/dag.spec.js
+++ b/test/core/dag.spec.js
@@ -2,11 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const IPFSFactory = require('ipfsd-ctl')
const IPFS = require('../../src/core')
diff --git a/test/core/dht.spec.js b/test/core/dht.spec.js
index 5ce711473a..d8fde46d18 100644
--- a/test/core/dht.spec.js
+++ b/test/core/dht.spec.js
@@ -2,11 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const isNode = require('detect-node')
const IPFSFactory = require('ipfsd-ctl')
diff --git a/test/core/exports.spec.js b/test/core/exports.spec.js
index 4506dd8251..306dca99a7 100644
--- a/test/core/exports.spec.js
+++ b/test/core/exports.spec.js
@@ -11,10 +11,7 @@ const multihashing = require('multihashing-async')
const multicodec = require('multicodec')
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const Ipfs = require('../../')
diff --git a/test/core/files-regular-utils.js b/test/core/files-regular-utils.js
index 4cad233e4c..d8520cf583 100644
--- a/test/core/files-regular-utils.js
+++ b/test/core/files-regular-utils.js
@@ -2,10 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const utils = require('../../src/core/components/files-regular/utils')
describe('files-regular/utils', () => {
diff --git a/test/core/files-sharding.spec.js b/test/core/files-sharding.spec.js
index 6abcd86823..2d82834f7f 100644
--- a/test/core/files-sharding.spec.js
+++ b/test/core/files-sharding.spec.js
@@ -2,10 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const pull = require('pull-stream')
const IPFS = require('../../src/core')
diff --git a/test/core/files.spec.js b/test/core/files.spec.js
index 5c59e0d4db..b620306c17 100644
--- a/test/core/files.spec.js
+++ b/test/core/files.spec.js
@@ -2,10 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const hat = require('hat')
const pull = require('pull-stream')
const IPFSFactory = require('ipfsd-ctl')
diff --git a/test/core/gc-lock.spec.js b/test/core/gc-lock.spec.js
index 3effa1325e..30410204fb 100644
--- a/test/core/gc-lock.spec.js
+++ b/test/core/gc-lock.spec.js
@@ -1,11 +1,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const delay = require('delay')
const parallel = require('async/parallel')
const pull = require('pull-stream')
diff --git a/test/core/gc.spec.js b/test/core/gc.spec.js
index b6309b4fd2..2253e33425 100644
--- a/test/core/gc.spec.js
+++ b/test/core/gc.spec.js
@@ -2,11 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const IPFSFactory = require('ipfsd-ctl')
const pEvent = require('p-event')
const env = require('ipfs-utils/src/env')
diff --git a/test/core/init.spec.js b/test/core/init.spec.js
index 5a9c893839..182438cef7 100644
--- a/test/core/init.spec.js
+++ b/test/core/init.spec.js
@@ -2,10 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const isNode = require('detect-node')
const hat = require('hat')
const IPFS = require('../../src/core')
diff --git a/test/core/kad-dht.node.js b/test/core/kad-dht.node.js
index 032df5289a..4722ec66e2 100644
--- a/test/core/kad-dht.node.js
+++ b/test/core/kad-dht.node.js
@@ -2,10 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const path = require('path')
const parallel = require('async/parallel')
diff --git a/test/core/key-exchange.js b/test/core/key-exchange.js
index bb114dcd0d..47910edb71 100644
--- a/test/core/key-exchange.js
+++ b/test/core/key-exchange.js
@@ -2,10 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const hat = require('hat')
const IPFS = require('../../src/core')
diff --git a/test/core/libp2p.spec.js b/test/core/libp2p.spec.js
index ec52c0bd0e..f159db7a02 100644
--- a/test/core/libp2p.spec.js
+++ b/test/core/libp2p.spec.js
@@ -2,11 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const MemoryStore = require('interface-datastore').MemoryDatastore
const PeerInfo = require('peer-info')
const PeerBook = require('peer-book')
diff --git a/test/core/mfs-preload.spec.js b/test/core/mfs-preload.spec.js
index 3c066472cf..3fb84cfa00 100644
--- a/test/core/mfs-preload.spec.js
+++ b/test/core/mfs-preload.spec.js
@@ -2,11 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const delay = require('delay')
const waitFor = require('../utils/wait-for')
const mfsPreload = require('../../src/core/mfs-preload')
diff --git a/test/core/name-pubsub.js b/test/core/name-pubsub.js
index 09d940c4af..0e5fdd59ad 100644
--- a/test/core/name-pubsub.js
+++ b/test/core/name-pubsub.js
@@ -3,11 +3,7 @@
'use strict'
const hat = require('hat')
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const base64url = require('base64url')
const { fromB58String } = require('multihashes')
const peerId = require('peer-id')
diff --git a/test/core/name.spec.js b/test/core/name.spec.js
index abbce2379b..36bf8a5b6d 100644
--- a/test/core/name.spec.js
+++ b/test/core/name.spec.js
@@ -3,15 +3,10 @@
'use strict'
const hat = require('hat')
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const sinon = require('sinon')
-
const parallel = require('async/parallel')
const series = require('async/series')
-
const IPFS = require('../../src')
const ipnsPath = require('../../src/core/ipns/path')
const ipnsRouting = require('../../src/core/ipns/routing/config')
diff --git a/test/core/object.spec.js b/test/core/object.spec.js
index 789b32af8a..0cafe32f98 100644
--- a/test/core/object.spec.js
+++ b/test/core/object.spec.js
@@ -2,10 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const hat = require('hat')
const IPFSFactory = require('ipfsd-ctl')
const auto = require('async/auto')
diff --git a/test/core/pin-set.js b/test/core/pin-set.js
index cf1b0263bf..6a77025c26 100644
--- a/test/core/pin-set.js
+++ b/test/core/pin-set.js
@@ -2,11 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const parallelLimit = require('async/parallelLimit')
const series = require('async/series')
const {
diff --git a/test/core/pin.js b/test/core/pin.js
index fd67c25936..124a5a8acc 100644
--- a/test/core/pin.js
+++ b/test/core/pin.js
@@ -2,13 +2,8 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const fs = require('fs')
-
const {
DAGNode
} = require('ipld-dag-pb')
diff --git a/test/core/pin.spec.js b/test/core/pin.spec.js
index 467593dc03..9d55f24aa0 100644
--- a/test/core/pin.spec.js
+++ b/test/core/pin.spec.js
@@ -2,11 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const IPFSFactory = require('ipfsd-ctl')
const IPFS = require('../../src/core')
diff --git a/test/core/ping.spec.js b/test/core/ping.spec.js
index 05163a6b5e..23eb110807 100644
--- a/test/core/ping.spec.js
+++ b/test/core/ping.spec.js
@@ -1,16 +1,13 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const pull = require('pull-stream/pull')
const drain = require('pull-stream/sinks/drain')
const parallel = require('async/parallel')
const DaemonFactory = require('ipfsd-ctl')
const isNode = require('detect-node')
const path = require('path')
-const expect = chai.expect
-chai.use(dirtyChai)
const df = DaemonFactory.create({
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
IpfsClient: require('ipfs-http-client')
diff --git a/test/core/preload.spec.js b/test/core/preload.spec.js
index e40c0a740f..318c179e02 100644
--- a/test/core/preload.spec.js
+++ b/test/core/preload.spec.js
@@ -5,10 +5,7 @@
const hat = require('hat')
const parallel = require('async/parallel')
const waterfall = require('async/waterfall')
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const pull = require('pull-stream')
const CID = require('cids')
diff --git a/test/core/pubsub.spec.js b/test/core/pubsub.spec.js
index a341d787d7..1fc46623bc 100644
--- a/test/core/pubsub.spec.js
+++ b/test/core/pubsub.spec.js
@@ -3,11 +3,7 @@
'use strict'
const hat = require('hat')
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const IPFS = require('../../src')
const createTempRepo = require('../utils/create-repo-nodejs')
diff --git a/test/core/stats.spec.js b/test/core/stats.spec.js
index 3771a0b2ce..e522720aa7 100644
--- a/test/core/stats.spec.js
+++ b/test/core/stats.spec.js
@@ -2,11 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const pull = require('pull-stream')
const IPFSFactory = require('ipfsd-ctl')
const IPFS = require('../../src/core')
diff --git a/test/core/swarm.spec.js b/test/core/swarm.spec.js
index 7002ec3edd..40c2d23ee8 100644
--- a/test/core/swarm.spec.js
+++ b/test/core/swarm.spec.js
@@ -2,11 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const IPFSFactory = require('ipfsd-ctl')
const IPFS = require('../../src/core')
diff --git a/test/core/utils.js b/test/core/utils.js
index e0c620608a..a4d00e329f 100644
--- a/test/core/utils.js
+++ b/test/core/utils.js
@@ -2,11 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const fs = require('fs')
const fromB58String = require('multihashes').fromB58String
diff --git a/test/gateway/index.js b/test/gateway/index.js
index 48ecd7dcff..a9b640d89b 100644
--- a/test/gateway/index.js
+++ b/test/gateway/index.js
@@ -2,10 +2,7 @@
/* eslint dot-notation: 0, dot-notation: 0, quote-props: 0 */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const Daemon = require('../../src/cli/daemon')
const loadFixture = require('aegir/fixtures')
const os = require('os')
diff --git a/test/http-api/inject/bitswap.js b/test/http-api/inject/bitswap.js
index 44c265267e..e5c1fe09a3 100644
--- a/test/http-api/inject/bitswap.js
+++ b/test/http-api/inject/bitswap.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const CID = require('cids')
const waitFor = require('../../utils/wait-for')
diff --git a/test/http-api/inject/block.js b/test/http-api/inject/block.js
index e247dc9225..794893ea3a 100644
--- a/test/http-api/inject/block.js
+++ b/test/http-api/inject/block.js
@@ -2,7 +2,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const fs = require('fs')
const FormData = require('form-data')
const streamToPromise = require('stream-to-promise')
diff --git a/test/http-api/inject/bootstrap.js b/test/http-api/inject/bootstrap.js
index 713c6be08c..8e59ab89d0 100644
--- a/test/http-api/inject/bootstrap.js
+++ b/test/http-api/inject/bootstrap.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const qs = require('qs')
const defaultList = require('../../../src/core/runtime/config-nodejs.js')().Bootstrap
diff --git a/test/http-api/inject/config.js b/test/http-api/inject/config.js
index 513f46c922..53eb9f8785 100644
--- a/test/http-api/inject/config.js
+++ b/test/http-api/inject/config.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const fs = require('fs')
const FormData = require('form-data')
const streamToPromise = require('stream-to-promise')
diff --git a/test/http-api/inject/dag.js b/test/http-api/inject/dag.js
index d2507b6fc7..1e3996d582 100644
--- a/test/http-api/inject/dag.js
+++ b/test/http-api/inject/dag.js
@@ -3,10 +3,7 @@
'use strict'
const hat = require('hat')
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const DAGNode = require('ipld-dag-pb').DAGNode
const Readable = require('stream').Readable
const FormData = require('form-data')
diff --git a/test/http-api/inject/dht.js b/test/http-api/inject/dht.js
index f844658417..039df2bee2 100644
--- a/test/http-api/inject/dht.js
+++ b/test/http-api/inject/dht.js
@@ -2,10 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
module.exports = (http) => {
// TODO: unskip when DHT is enabled: https://github.com/ipfs/js-ipfs/pull/1994
diff --git a/test/http-api/inject/dns.js b/test/http-api/inject/dns.js
index c5b4c705ae..0e01879e54 100644
--- a/test/http-api/inject/dns.js
+++ b/test/http-api/inject/dns.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
module.exports = (http) => {
describe('/dns', () => {
diff --git a/test/http-api/inject/files.js b/test/http-api/inject/files.js
index 7c1c0b6a48..ee015a217c 100644
--- a/test/http-api/inject/files.js
+++ b/test/http-api/inject/files.js
@@ -3,7 +3,7 @@
'use strict'
const crypto = require('crypto')
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const FormData = require('form-data')
const streamToPromise = require('stream-to-promise')
const multibase = require('multibase')
diff --git a/test/http-api/inject/id.js b/test/http-api/inject/id.js
index dec6c66aa9..4022535e70 100644
--- a/test/http-api/inject/id.js
+++ b/test/http-api/inject/id.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
module.exports = (http) => {
describe('/id', () => {
diff --git a/test/http-api/inject/name.js b/test/http-api/inject/name.js
index b181f2935a..3fe7f2564c 100644
--- a/test/http-api/inject/name.js
+++ b/test/http-api/inject/name.js
@@ -2,12 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const checkAll = (bits) => string => bits.every(bit => string.includes(bit))
module.exports = (http) => {
diff --git a/test/http-api/inject/object.js b/test/http-api/inject/object.js
index 662474e0b0..77370b2620 100644
--- a/test/http-api/inject/object.js
+++ b/test/http-api/inject/object.js
@@ -2,11 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
-
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const fs = require('fs')
const FormData = require('form-data')
const streamToPromise = require('stream-to-promise')
diff --git a/test/http-api/inject/pin.js b/test/http-api/inject/pin.js
index 50fafe1da2..bf22ecb259 100644
--- a/test/http-api/inject/pin.js
+++ b/test/http-api/inject/pin.js
@@ -2,7 +2,7 @@
/* eslint max-nested-callbacks: ["error", 8] */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const FormData = require('form-data')
const streamToPromise = require('stream-to-promise')
const multibase = require('multibase')
diff --git a/test/http-api/inject/ping.js b/test/http-api/inject/ping.js
index 4467a05d11..ca1429afe8 100644
--- a/test/http-api/inject/ping.js
+++ b/test/http-api/inject/ping.js
@@ -2,11 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
module.exports = (http) => {
describe('/ping', function () {
diff --git a/test/http-api/inject/pubsub.js b/test/http-api/inject/pubsub.js
index ce1d803019..bb8198636b 100644
--- a/test/http-api/inject/pubsub.js
+++ b/test/http-api/inject/pubsub.js
@@ -2,10 +2,7 @@
/* eslint-env mocha */
'use strict'
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-const expect = chai.expect
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
module.exports = (http) => {
describe('/pubsub', () => {
diff --git a/test/http-api/inject/resolve.js b/test/http-api/inject/resolve.js
index c228a06607..e2f3f390e0 100644
--- a/test/http-api/inject/resolve.js
+++ b/test/http-api/inject/resolve.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const FormData = require('form-data')
const streamToPromise = require('stream-to-promise')
diff --git a/test/http-api/inject/version.js b/test/http-api/inject/version.js
index d1cb6a1577..fb6ec8f3ef 100644
--- a/test/http-api/inject/version.js
+++ b/test/http-api/inject/version.js
@@ -1,7 +1,7 @@
/* eslint-env mocha */
'use strict'
-const expect = require('chai').expect
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const pkgversion = require('./../../../package.json').version
module.exports = (http) => {
diff --git a/test/http-api/routes.js b/test/http-api/routes.js
index e0e3431b90..28ed06bb5a 100644
--- a/test/http-api/routes.js
+++ b/test/http-api/routes.js
@@ -2,9 +2,7 @@
'use strict'
const fs = require('fs')
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const hat = require('hat')
const Daemon = require('../../src/cli/daemon')
const promisify = require('promisify-es6')
diff --git a/test/utils/ipfs-exec.js b/test/utils/ipfs-exec.js
index ff657e034d..21533a0495 100644
--- a/test/utils/ipfs-exec.js
+++ b/test/utils/ipfs-exec.js
@@ -1,9 +1,7 @@
'use strict'
const execa = require('execa')
-const chai = require('chai')
-const dirtyChai = require('dirty-chai')
-chai.use(dirtyChai)
+const { expect } = require('interface-ipfs-core/src/utils/mocha')
const path = require('path')
const _ = require('lodash')
From 013ed41f5daf0ef98824b1f53356dedd7ce6e5a1 Mon Sep 17 00:00:00 2001
From: achingbrain
Date: Thu, 3 Oct 2019 13:53:50 +0100
Subject: [PATCH 14/18] chore: fix linting
---
test/http-api/routes.js | 1 -
test/utils/ipfs-exec.js | 1 -
2 files changed, 2 deletions(-)
diff --git a/test/http-api/routes.js b/test/http-api/routes.js
index 28ed06bb5a..258b411800 100644
--- a/test/http-api/routes.js
+++ b/test/http-api/routes.js
@@ -2,7 +2,6 @@
'use strict'
const fs = require('fs')
-const { expect } = require('interface-ipfs-core/src/utils/mocha')
const hat = require('hat')
const Daemon = require('../../src/cli/daemon')
const promisify = require('promisify-es6')
diff --git a/test/utils/ipfs-exec.js b/test/utils/ipfs-exec.js
index 21533a0495..3e002722b3 100644
--- a/test/utils/ipfs-exec.js
+++ b/test/utils/ipfs-exec.js
@@ -1,7 +1,6 @@
'use strict'
const execa = require('execa')
-const { expect } = require('interface-ipfs-core/src/utils/mocha')
const path = require('path')
const _ = require('lodash')
From bc5e8b7b9435f3e26bd93eb1e245ba7b22aad8f9 Mon Sep 17 00:00:00 2001
From: achingbrain
Date: Fri, 4 Oct 2019 16:33:42 +0100
Subject: [PATCH 15/18] chore: update deps and make keys agree with spec
---
src/cli/commands/config/profile/apply.js | 4 ++--
src/core/components/config.js | 2 +-
src/http/api/resources/config.js | 4 ++--
src/http/api/routes/config.js | 8 ++++----
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/cli/commands/config/profile/apply.js b/src/cli/commands/config/profile/apply.js
index eb0d066f06..8bd11a028f 100644
--- a/src/cli/commands/config/profile/apply.js
+++ b/src/cli/commands/config/profile/apply.js
@@ -18,8 +18,8 @@ module.exports = {
argv.resolve((async () => {
const ipfs = await argv.getIpfs()
const diff = await ipfs.config.profiles.apply(argv.profile, { dryRun: argv.dryRun })
- const delta = JSONDiff.diff(diff.old, diff.new)
- const res = JSONDiff.formatters.console.format(delta, diff.old)
+ const delta = JSONDiff.diff(diff.original, diff.updated)
+ const res = JSONDiff.formatters.console.format(delta, diff.original)
if (res) {
argv.print(res)
diff --git a/src/core/components/config.js b/src/core/components/config.js
index e364bb837d..f36e684521 100644
--- a/src/core/components/config.js
+++ b/src/core/components/config.js
@@ -38,7 +38,7 @@ module.exports = function config (self) {
delete oldCfg.Identity.PrivKey
delete newCfg.Identity.PrivKey
- return { old: oldCfg, new: newCfg }
+ return { original: oldCfg, updated: newCfg }
} catch (err) {
log(err)
diff --git a/src/http/api/resources/config.js b/src/http/api/resources/config.js
index fd0b13048d..bd45c00150 100644
--- a/src/http/api/resources/config.js
+++ b/src/http/api/resources/config.js
@@ -166,7 +166,7 @@ exports.replace = {
}
}
-exports.profile = {
+exports.profiles = {
apply: {
validate: {
query: Joi.object().keys({
@@ -195,7 +195,7 @@ exports.profile = {
try {
const diff = await ipfs.config.profiles.apply(profile, { dryRun })
- return h.response({ OldCfg: diff.old, NewCfg: diff.new })
+ return h.response({ OldCfg: diff.original, NewCfg: diff.updated })
} catch (err) {
throw Boom.boomify(err, { message: 'Failed to apply profile' })
}
diff --git a/src/http/api/routes/config.js b/src/http/api/routes/config.js
index db94c0ba4b..0f3ea9ddcb 100644
--- a/src/http/api/routes/config.js
+++ b/src/http/api/routes/config.js
@@ -37,15 +37,15 @@ module.exports = [
path: '/api/v0/config/profile/apply',
options: {
pre: [
- { method: resources.config.profile.apply.parseArgs, assign: 'args' }
+ { method: resources.config.profiles.apply.parseArgs, assign: 'args' }
],
- validate: resources.config.profile.apply.validate
+ validate: resources.config.profiles.apply.validate
},
- handler: resources.config.profile.apply.handler
+ handler: resources.config.profiles.apply.handler
},
{
method: '*',
path: '/api/v0/config/profile/list',
- handler: resources.config.profile.list.handler
+ handler: resources.config.profiles.list.handler
}
]
From 41893a6ad5a2daf8921f594debc6e28df959ed96 Mon Sep 17 00:00:00 2001
From: achingbrain
Date: Sat, 5 Oct 2019 07:59:51 +0100
Subject: [PATCH 16/18] chore: update interface tests
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 1df3f8b363..d6bff9fe39 100644
--- a/package.json
+++ b/package.json
@@ -203,7 +203,7 @@
"execa": "^2.0.4",
"form-data": "^2.5.1",
"hat": "0.0.3",
- "interface-ipfs-core": "^0.117.0",
+ "interface-ipfs-core": "^0.117.1",
"ipfs-interop": "~0.1.0",
"ipfsd-ctl": "^0.47.2",
"libp2p-websocket-star": "~0.10.2",
From ed4c74d6c1dc14c7caa5826eb567fdebcf0b8766 Mon Sep 17 00:00:00 2001
From: achingbrain
Date: Sat, 5 Oct 2019 10:34:50 +0100
Subject: [PATCH 17/18] chore: udpate test skips/includes
---
test/core/interface.spec.js | 24 +++++++-----------------
test/http-api/interface.js | 24 +++++++-----------------
2 files changed, 14 insertions(+), 34 deletions(-)
diff --git a/test/core/interface.spec.js b/test/core/interface.spec.js
index 84a386e353..5ac674782c 100644
--- a/test/core/interface.spec.js
+++ b/test/core/interface.spec.js
@@ -12,26 +12,16 @@ describe('interface-ipfs-core tests', function () {
tests.bitswap(defaultCommonFactory, { skip: !isNode })
- tests.block(defaultCommonFactory)
+ tests.block(defaultCommonFactory, {
+ skip: [{
+ name: 'rm',
+ reason: 'Not implemented'
+ }]
+ })
tests.bootstrap(defaultCommonFactory)
- tests.config(defaultCommonFactory, {
- skip: [
- {
- name: 'should set a number',
- reason: 'Failing - needs to be fixed'
- },
- {
- name: 'should output changes but not save them for dry run',
- reason: 'TODO unskip when https://github.com/ipfs/js-ipfs/pull/2165 is merged'
- },
- {
- name: 'should set a config profile',
- reason: 'TODO unskip when https://github.com/ipfs/js-ipfs/pull/2165 is merged'
- }
- ]
- })
+ tests.config(defaultCommonFactory)
tests.dag(defaultCommonFactory)
diff --git a/test/http-api/interface.js b/test/http-api/interface.js
index 3373f36069..7469be1564 100644
--- a/test/http-api/interface.js
+++ b/test/http-api/interface.js
@@ -12,26 +12,16 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => {
tests.bitswap(defaultCommonFactory)
- tests.block(defaultCommonFactory)
+ tests.block(defaultCommonFactory, {
+ skip: [{
+ name: 'rm',
+ reason: 'Not implemented'
+ }]
+ })
tests.bootstrap(defaultCommonFactory)
- tests.config(defaultCommonFactory, {
- skip: [
- {
- name: 'should set a number',
- reason: 'Failing - needs to be fixed'
- },
- {
- name: 'should output changes but not save them for dry run',
- reason: 'TODO unskip when https://github.com/ipfs/js-ipfs/pull/2165 is merged'
- },
- {
- name: 'should set a config profile',
- reason: 'TODO unskip when https://github.com/ipfs/js-ipfs/pull/2165 is merged'
- }
- ]
- })
+ tests.config(defaultCommonFactory)
tests.dag(defaultCommonFactory, {
skip: [{
From 936ad6984bab2b77b5e33c1247d254f5a76a07dc Mon Sep 17 00:00:00 2001
From: achingbrain
Date: Sat, 5 Oct 2019 12:54:27 +0100
Subject: [PATCH 18/18] chore: fix up interface tests
---
package.json | 2 +-
src/core/components/files-mfs.js | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/package.json b/package.json
index d6bff9fe39..a32cd13d41 100644
--- a/package.json
+++ b/package.json
@@ -203,7 +203,7 @@
"execa": "^2.0.4",
"form-data": "^2.5.1",
"hat": "0.0.3",
- "interface-ipfs-core": "^0.117.1",
+ "interface-ipfs-core": "^0.117.2",
"ipfs-interop": "~0.1.0",
"ipfsd-ctl": "^0.47.2",
"libp2p-websocket-star": "~0.10.2",
diff --git a/src/core/components/files-mfs.js b/src/core/components/files-mfs.js
index 77f2eed0ab..9d621ad60a 100644
--- a/src/core/components/files-mfs.js
+++ b/src/core/components/files-mfs.js
@@ -46,7 +46,7 @@ module.exports = (/** @type { import("../index") } */ ipfs) => {
if (paths.length) {
const options = args[args.length - 1]
- if (options.preload !== false) {
+ if (options && options.preload !== false) {
paths.forEach(path => ipfs._preload(path))
}
}