This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 299
/
Copy pathkey.spec.js
84 lines (74 loc) · 1.98 KB
/
key.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 8] */
'use strict'
const FactoryClient = require('./ipfs-factory/client')
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
describe('.key', () => {
let ipfs
let fc
before(function (done) {
this.timeout(20 * 1000) // slow CI
fc = new FactoryClient()
fc.spawnNode((err, node) => {
expect(err).to.not.exist()
ipfs = node
done()
})
})
after((done) => {
fc.dismantle(done)
})
describe('Callback API', () => {
describe('.gen', () => {
it('create a new rsa key', (done) => {
ipfs.key.gen('foobarsa', { type: 'rsa', size: 2048 }, (err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
done()
})
})
it('create a new ed25519 key', (done) => {
ipfs.key.gen('bazed', { type: 'ed25519' }, (err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
done()
})
})
})
describe('.list', () => {
it('both keys show up + self', (done) => {
ipfs.key.list((err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
expect(res.Keys.length).to.equal(3)
done()
})
})
})
})
describe('Promise API', () => {
describe('.gen', () => {
it('create a new rsa key', () => {
return ipfs.key.gen('foobarsa2', {type: 'rsa', size: 2048}).then((res) => {
expect(res).to.exist()
})
})
it('create a new ed25519 key', () => {
return ipfs.key.gen('bazed2', {type: 'ed25519'}).then((res) => {
expect(res).to.exist()
})
})
})
describe('.list', () => {
it('4 keys to show up + self', () => {
return ipfs.key.list().then((res) => {
expect(res).to.exist()
expect(res.Keys.length).to.equal(5)
})
})
})
})
})