Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: remove http api support for key.export
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobheun committed Aug 5, 2020
1 parent 2f89e87 commit be7c4a4
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 168 deletions.
1 change: 1 addition & 0 deletions packages/interface-ipfs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"it-drain": "^1.0.1",
"it-last": "^1.0.1",
"it-pushable": "^1.3.1",
"libp2p-crypto": "^0.17.9",
"multiaddr": "^7.4.3",
"multibase": "^1.0.1",
"multihashing-async": "^1.0.0",
Expand Down
37 changes: 0 additions & 37 deletions packages/interface-ipfs-core/src/key/export.js

This file was deleted.

19 changes: 10 additions & 9 deletions packages/interface-ipfs-core/src/key/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict'

const { nanoid } = require('nanoid')
const keys = require('libp2p-crypto/src/keys')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const testTimeout = require('../utils/test-timeout')

Expand All @@ -26,24 +27,24 @@ module.exports = (common, options) => {
it('should respect timeout option when importing a key', async () => {
const password = nanoid()

const pem = await ipfs.key.export('self', password)
expect(pem).to.exist()
const key = await keys.generateKeyPair('ed25519')
const exported = key.export(password)

await testTimeout(() => ipfs.key.import('derp', pem, password, {
await testTimeout(() => ipfs.key.import('derp', exported, password, {
timeout: 1
}))
})

it('should import an exported key', async () => {
const password = nanoid()

const pem = await ipfs.key.export('self', password)
expect(pem).to.exist()
const key = await keys.generateKeyPair('ed25519')
const exported = await key.export(password)

const key = await ipfs.key.import('clone', pem, password)
expect(key).to.exist()
expect(key).to.have.property('name', 'clone')
expect(key).to.have.property('id')
const importedKey = await ipfs.key.import('clone', exported, password)
expect(importedKey).to.exist()
expect(importedKey).to.have.property('name', 'clone')
expect(importedKey).to.have.property('id')
})
})
}
1 change: 0 additions & 1 deletion packages/interface-ipfs-core/src/key/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const tests = {
list: require('./list'),
rename: require('./rename'),
rm: require('./rm'),
export: require('./export'),
import: require('./import')
}

Expand Down
26 changes: 0 additions & 26 deletions packages/ipfs-http-client/src/key/export.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/ipfs-http-client/src/key/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ module.exports = config => ({
list: require('./list')(config),
rename: require('./rename')(config),
rm: require('./rm')(config),
export: require('./export')(config),
import: require('./import')(config)
})
44 changes: 0 additions & 44 deletions packages/ipfs/src/http/api/resources/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,50 +181,6 @@ exports.gen = {
}
}

exports.export = {
options: {
validate: {
options: {
allowUnknown: true,
stripUnknown: true
},
query: Joi.object().keys({
name: Joi.string().required(),
password: Joi.string().required(),
timeout: Joi.timeout()
})
.rename('arg', 'name', {
override: true,
ignoreUndefined: true
})
}
},
handler: async (request, h) => {
const {
app: {
signal
},
server: {
app: {
ipfs
}
},
query: {
name,
password,
timeout
}
} = request

const pem = await ipfs.key.export(name, password, {
signal,
timeout
})

return h.response(pem).type('application/x-pem-file')
}
}

exports.import = {
options: {
validate: {
Expand Down
5 changes: 0 additions & 5 deletions packages/ipfs/src/http/api/routes/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ module.exports = [
path: '/api/v0/key/rename',
...resources.key.rename
},
{
method: 'POST',
path: '/api/v0/key/export',
...resources.key.export
},
{
method: 'POST',
path: '/api/v0/key/import',
Expand Down
45 changes: 0 additions & 45 deletions packages/ipfs/test/http-api/inject/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe('/key', function () {
rm: sinon.stub(),
rename: sinon.stub(),
gen: sinon.stub(),
export: sinon.stub(),
import: sinon.stub()
}
}
Expand Down Expand Up @@ -228,50 +227,6 @@ describe('/key', function () {
})
})

describe('/export', () => {
const defaultOptions = {
signal: sinon.match.instanceOf(AbortSignal),
timeout: undefined
}

it('only accepts POST', () => {
return testHttpMethod('/api/v0/key/export')
})

it('should export a key', async () => {
const name = 'name'
const password = 'password'

ipfs.key.export.withArgs(name, password, defaultOptions).returns('pem')

const res = await http({
method: 'POST',
url: `/api/v0/key/export?arg=${name}&password=${password}`
}, { ipfs })

expect(res).to.have.property('statusCode', 200)
expect(res).to.have.property('result', 'pem')
})

it('accepts a timeout', async () => {
const name = 'name'
const password = 'password'

ipfs.key.export.withArgs(name, password, {
...defaultOptions,
timeout: 1000
}).returns('pem')

const res = await http({
method: 'POST',
url: `/api/v0/key/export?arg=${name}&password=${password}&timeout=1s`
}, { ipfs })

expect(res).to.have.property('statusCode', 200)
expect(res).to.have.property('result', 'pem')
})
})

describe('/import', () => {
const defaultOptions = {
signal: sinon.match.instanceOf(AbortSignal),
Expand Down

0 comments on commit be7c4a4

Please sign in to comment.