Commit b6cf4825e0a4f6e6535fdf0109c9f48414be5b84
test loading presigil legacy edgecase
Dominic Tarr committed on 10/14/2015, 9:22:58 PMParent: d8f89fd8a1616d164ee6e69ede47bdeaf92c25ae
Files changed
test/index.js | changed |
test/index.js | ||
---|---|---|
@@ -1,11 +1,12 @@ | ||
1 | 1 | var tape = require('tape') |
2 | 2 | var ssbkeys = require('../') |
3 | 3 | var crypto = require('crypto') |
4 | 4 | var path = require('path').join(__dirname, 'keyfile') |
5 | +var fs = require('fs') | |
5 | 6 | |
6 | 7 | tape('create and load async', function (t) { |
7 | - try { require('fs').unlinkSync(path) } catch(e) {} | |
8 | + try { fs.unlinkSync(path) } catch(e) {} | |
8 | 9 | ssbkeys.create(path, function(err, k1) { |
9 | 10 | if (err) throw err |
10 | 11 | ssbkeys.load(path, function(err, k2) { |
11 | 12 | if (err) throw err |
@@ -17,9 +18,9 @@ | ||
17 | 18 | }) |
18 | 19 | }) |
19 | 20 | |
20 | 21 | tape('create and load sync', function (t) { |
21 | - try { require('fs').unlinkSync(path) } catch(e) {} | |
22 | + try { fs.unlinkSync(path) } catch(e) {} | |
22 | 23 | var k1 = ssbkeys.createSync(path) |
23 | 24 | var k2 = ssbkeys.loadSync(path) |
24 | 25 | t.equal(k1.id.toString('hex'), k2.id.toString('hex')) |
25 | 26 | t.equal(k1.private.toString('hex'), k2.private.toString('hex')) |
@@ -89,9 +90,9 @@ | ||
89 | 90 | t.end() |
90 | 91 | }) |
91 | 92 | |
92 | 93 | tape('create and load async, legacy', function (t) { |
93 | - try { require('fs').unlinkSync(path) } catch(e) {} | |
94 | + try { fs.unlinkSync(path) } catch(e) {} | |
94 | 95 | ssbkeys.create(path, 'k256', function(err, k1) { |
95 | 96 | if (err) throw err |
96 | 97 | ssbkeys.load(path, function(err, k2) { |
97 | 98 | if (err) throw err |
@@ -106,9 +107,9 @@ | ||
106 | 107 | }) |
107 | 108 | }) |
108 | 109 | |
109 | 110 | tape('create and load sync, legacy', function (t) { |
110 | - try { require('fs').unlinkSync(path) } catch(e) {} | |
111 | + try { fs.unlinkSync(path) } catch(e) {} | |
111 | 112 | var k1 = ssbkeys.createSync(path, 'k256', true) |
112 | 113 | var k2 = ssbkeys.loadSync(path) |
113 | 114 | |
114 | 115 | console.log(k2) |
@@ -152,4 +153,31 @@ | ||
152 | 153 | |
153 | 154 | t.end() |
154 | 155 | |
155 | 156 | }) |
157 | + | |
158 | +tape('create and load presigil-legacy async', function (t) { | |
159 | + try { fs.unlinkSync(path) } catch(e) {} | |
160 | + var keys = ssbkeys.generate('ed25519') | |
161 | + keys.id = keys.id.substring(1) | |
162 | + fs.writeFileSync(path, JSON.stringify(keys)) | |
163 | + | |
164 | + var k2 = ssbkeys.loadSync(path) | |
165 | + t.equal(k2.id, '@' + keys.id) | |
166 | + t.end() | |
167 | + | |
168 | +}) | |
169 | + | |
170 | +tape('create and load presigil-legacy', function (t) { | |
171 | + | |
172 | + try { fs.unlinkSync(path) } catch(e) {} | |
173 | + var keys = ssbkeys.generate('ed25519') | |
174 | + keys.id = keys.id.substring(1) | |
175 | + fs.writeFileSync(path, JSON.stringify(keys)) | |
176 | + | |
177 | + ssbkeys.load(path, function (err, k2) { | |
178 | + if(err) throw err | |
179 | + t.equal(k2.id, '@' + keys.id) | |
180 | + t.end() | |
181 | + }) | |
182 | + | |
183 | +}) |
Built with git-ssb-web