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 298
/
Copy pathkey.spec.js
88 lines (76 loc) · 2.07 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
85
86
87
88
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 8] */
'use strict'
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const ipfsClient = require('../src')
const f = require('./utils/factory')
describe('.key', function () {
this.timeout(50 * 1000)
let ipfsd
let ipfs
before((done) => {
f.spawn({ initOptions: { bits: 1024, profile: 'test' } }, (err, _ipfsd) => {
expect(err).to.not.exist()
ipfsd = _ipfsd
ipfs = ipfsClient(_ipfsd.apiAddr)
done()
})
})
after((done) => {
if (!ipfsd) return done()
ipfsd.stop(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.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.length).to.equal(5)
})
})
})
})
})