@@ -24,11 +24,11 @@ describe('init', function () {
24
24
let cleanup
25
25
26
26
/**
27
- * @param {import('../src/types').InitOptions } options
27
+ * @param {import('../src/types').Options } [ options]
28
28
*/
29
29
const init = async ( options ) => {
30
30
const res = await createNode ( {
31
- init : options ,
31
+ ... options ,
32
32
start : false
33
33
} )
34
34
@@ -41,41 +41,71 @@ describe('init', function () {
41
41
afterEach ( ( ) => cleanup ( ) )
42
42
43
43
it ( 'should init successfully' , async ( ) => {
44
- await init ( { bits : 512 } )
44
+ await init ( )
45
45
46
46
const res = await repo . exists ( )
47
47
expect ( res ) . to . equal ( true )
48
48
49
49
const config = await repo . config . getAll ( )
50
50
51
- expect ( config . Identity ) . to . exist ( )
52
- expect ( config . Keychain ) . to . exist ( )
51
+ expect ( config ) . to . have . property ( 'Identity' )
52
+ expect ( config ) . to . have . nested . property ( 'Keychain.DEK' )
53
53
} )
54
54
55
55
it ( 'should init successfully with a keychain pass' , async ( ) => {
56
- await init ( { bits : 512 } )
56
+ await init ( {
57
+ pass : 'super-super-secure-1234' ,
58
+ init : {
59
+ algorithm : 'RSA' ,
60
+ bits : 512
61
+ }
62
+ } )
57
63
58
64
const res = await repo . exists ( )
59
65
expect ( res ) . to . equal ( true )
60
66
61
67
const config = await repo . config . getAll ( )
62
-
63
68
expect ( config . Keychain ) . to . exist ( )
64
69
70
+ const { ipfs : ipfs2 , repo : repo2 } = await createNode ( {
71
+ repo : repo ,
72
+ pass : 'something-else-that-is-long-enough' ,
73
+ start : false ,
74
+ init : {
75
+ algorithm : 'RSA' ,
76
+ bits : 512
77
+ }
78
+ } )
79
+
80
+ // same repo, same peer id
81
+ expect ( repo . path ) . to . equal ( repo2 . path )
82
+ expect ( await ipfs2 . id ( ) ) . to . deep . equal ( await ipfs . id ( ) )
83
+
84
+ // opened with correct password
85
+ await expect ( ipfs . key . export ( 'self' , 'some-other-password' ) ) . to . eventually . be . ok ( )
86
+
87
+ // opened with incorrect password
88
+ await expect ( ipfs2 . key . export ( 'self' , 'some-other-password' ) ) . to . eventually . be . rejected ( )
89
+ } )
90
+
91
+ it ( 'should init with a key algorithm (RSA)' , async ( ) => {
92
+ await init ( { init : { algorithm : 'RSA' } } )
93
+
94
+ const config = await repo . config . getAll ( )
65
95
const peerId = await PeerId . createFromPrivKey ( `${ config . Identity ?. PrivKey } ` )
66
96
expect ( peerId . privKey ) . is . instanceOf ( supportedKeys . rsa . RsaPrivateKey )
67
97
} )
68
98
69
99
it ( 'should init with a key algorithm (Ed25519)' , async ( ) => {
70
- await init ( { algorithm : 'Ed25519' } )
100
+ await init ( { init : { algorithm : 'Ed25519' } } )
71
101
72
102
const config = await repo . config . getAll ( )
73
103
const peerId = await PeerId . createFromPrivKey ( `${ config . Identity ?. PrivKey } ` )
74
104
expect ( peerId . privKey ) . is . instanceOf ( supportedKeys . ed25519 . Ed25519PrivateKey )
75
105
} )
76
106
77
107
it ( 'should init with a key algorithm (secp256k1)' , async ( ) => {
78
- await init ( { algorithm : 'secp256k1' } )
108
+ await init ( { init : { algorithm : 'secp256k1' } } )
79
109
80
110
const config = await repo . config . getAll ( )
81
111
const peerId = await PeerId . createFromPrivKey ( `${ config . Identity ?. PrivKey } ` )
@@ -85,58 +115,63 @@ describe('init', function () {
85
115
it ( 'should set # of bits in key' , async function ( ) {
86
116
this . timeout ( 120 * 1000 )
87
117
88
- await init ( { bits : 1024 } )
118
+ await init ( {
119
+ init : {
120
+ algorithm : 'RSA' ,
121
+ bits : 1024
122
+ }
123
+ } )
89
124
90
125
const config = await repo . config . getAll ( )
91
126
expect ( config . Identity ?. PrivKey . length ) . is . above ( 256 )
92
127
} )
93
128
94
129
it ( 'should allow a pregenerated key to be used' , async ( ) => {
95
- await init ( { privateKey } )
130
+ await init ( { init : { privateKey } } )
96
131
97
132
const config = await repo . config . getAll ( )
98
133
expect ( config . Identity ?. PeerID ) . is . equal ( 'QmRsooYQasV5f5r834NSpdUtmejdQcpxXkK6qsozZWEihC' )
99
134
} )
100
135
101
136
it ( 'should allow a pregenerated ed25519 key to be used' , async ( ) => {
102
- await init ( { privateKey : edPrivateKey } )
137
+ await init ( { init : { privateKey : edPrivateKey } } )
103
138
104
139
const config = await repo . config . getAll ( )
105
140
expect ( config . Identity ?. PeerID ) . is . equal ( '12D3KooWRm8J3iL796zPFi2EtGGtUJn58AG67gcqzMFHZnnsTzqD' )
106
141
} )
107
142
108
143
it ( 'should allow a pregenerated secp256k1 key to be used' , async ( ) => {
109
- await init ( { privateKey : secpPrivateKey } )
144
+ await init ( { init : { privateKey : secpPrivateKey } } )
110
145
111
146
const config = await repo . config . getAll ( )
112
147
expect ( config . Identity ?. PeerID ) . is . equal ( '16Uiu2HAm5qw8UyXP2RLxQUx5KvtSN8DsTKz8quRGqGNC3SYiaB8E' )
113
148
} )
114
149
115
150
it ( 'should write init docs' , async ( ) => {
116
- await init ( { bits : 512 } )
151
+ await init ( )
117
152
const multihash = CID . parse ( 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB' )
118
153
119
154
const node = await ipfs . object . get ( multihash , { enc : 'base58' } )
120
155
expect ( node . Links ) . to . exist ( )
121
156
} )
122
157
123
158
it ( 'should allow init with an empty repo' , async ( ) => {
124
- await init ( { bits : 512 , emptyRepo : true } )
159
+ await init ( { init : { emptyRepo : true } } )
125
160
126
161
// Should not have default assets
127
162
const multihash = CID . parse ( 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB' )
128
163
await expect ( ipfs . object . get ( multihash , { } ) ) . to . eventually . be . rejected ( ) . with . property ( 'code' , 'ERR_NOT_FOUND' )
129
164
} )
130
165
131
166
it ( 'should apply one profile' , async ( ) => {
132
- await init ( { bits : 512 , profiles : [ 'test' ] } )
167
+ await init ( { init : { profiles : [ 'test' ] } } )
133
168
134
169
const config = await repo . config . getAll ( )
135
170
expect ( config . Bootstrap ) . to . be . empty ( )
136
171
} )
137
172
138
173
it ( 'should apply multiple profiles' , async ( ) => {
139
- await init ( { bits : 512 , profiles : [ 'test' , 'local-discovery' ] } )
174
+ await init ( { init : { profiles : [ 'test' , 'local-discovery' ] } } )
140
175
141
176
const config = await repo . config . getAll ( )
142
177
expect ( config . Bootstrap ) . to . be . empty ( )
0 commit comments