Files: 340ef7cdcc9255c17889664920a134eca6611486 / test / secret-stack.js
1246 bytesRaw
1 | var SecretStack = require('secret-stack') |
2 | var crypto = require('crypto') |
3 | var tape = require('tape') |
4 | var path = require('path') |
5 | var osenv = require('osenv') |
6 | var mkdirp = require('mkdirp') |
7 | var pull = require('pull-stream') |
8 | |
9 | //deterministic keys make testing easy. |
10 | function hash (s) { |
11 | return crypto.createHash('sha256').update(s).digest() |
12 | } |
13 | |
14 | var appkey = hash('TESTBLOBS') |
15 | |
16 | var create = SecretStack({ appKey: appkey }).use(require('../')) |
17 | |
18 | function tmp (name) { |
19 | var dir = path.join(osenv.tmpdir(), 'testblobs-'+Date.now()+'-'+name) |
20 | mkdirp.sync(dir) |
21 | return dir |
22 | } |
23 | |
24 | var alice = create({ seed: hash('ALICE'), path: tmp('alice') }) |
25 | var bob = create({ seed: hash('BOB'), path: tmp('bob') }) |
26 | |
27 | tape('alice pushes to bob', function (t) { |
28 | |
29 | alice.connect(bob.address(), function (err, rpc) { |
30 | if(err) throw err |
31 | }) |
32 | |
33 | var hello = new Buffer('Hello World'), _hash |
34 | |
35 | pull( |
36 | bob.blobs.ls({live: true, long: true}), |
37 | pull.take(1), |
38 | pull.collect(function (err, ary) { |
39 | t.equal(ary[0].id, _hash) |
40 | t.end() |
41 | alice.close() |
42 | bob.close() |
43 | }) |
44 | ) |
45 | |
46 | pull( |
47 | pull.values([hello]), |
48 | alice.blobs.add(function (err, hash) { |
49 | _hash = hash |
50 | alice.blobs.push(hash) |
51 | }) |
52 | ) |
53 | }) |
54 | |
55 |
Built with git-ssb-web