Files: b6540cc83c887c7a955b7a6e3e2280c017951e30 / test / accept4.js
2633 bytesRaw
1 | var crypto = require('crypto') |
2 | var I = require('../valid') |
3 | var createClient = require('ssb-client') |
4 | var u = require('../util') |
5 | |
6 | var ssbKeys = require('ssb-keys') |
7 | var tape = require('tape') |
8 | //var explain = require('explain-error') |
9 | var pull = require('pull-stream') |
10 | //var u = require('../lib/util') |
11 | var ref = require('ssb-ref') |
12 | |
13 | var createSbot = require('scuttlebot') |
14 | .use(require('ssb-links')) |
15 | .use({ |
16 | name: 'replicate', version: '1.0.0', |
17 | manifest: { request: 'sync' }, |
18 | init: function () { |
19 | return { request: function () {} } |
20 | } |
21 | }) |
22 | .use(require('ssb-query')) |
23 | .use(require('ssb-device-address')) |
24 | .use(require('ssb-identities')) |
25 | .use(require('ssb-friends')) |
26 | .use(require('../')) |
27 | |
28 | function toId(msg) { |
29 | return '%'+ssbKeys.hash(JSON.stringify(msg, null, 2)) |
30 | } |
31 | |
32 | function all(stream, cb) { |
33 | return pull(stream, pull.collect(cb)) |
34 | } |
35 | |
36 | var caps = { |
37 | sign: crypto.randomBytes(32),//.toString('base64'), |
38 | userInvite: crypto.randomBytes(32),//.toString('base64'), |
39 | shs: crypto.randomBytes(32),//.toString('base64'), |
40 | } |
41 | |
42 | var alice = createSbot({ |
43 | temp: true, |
44 | timeout: 1000, |
45 | port: 12342, |
46 | keys:ssbKeys.generate(), |
47 | caps: caps |
48 | }) |
49 | var bob = createSbot({ |
50 | temp: true, |
51 | timeout: 1000, |
52 | port: 12343, |
53 | keys:ssbKeys.generate(), |
54 | caps: caps |
55 | }) |
56 | |
57 | tape('create an invite', function (t) { |
58 | |
59 | alice.userInvites.create({allowWithoutPubs: true}, function (err, _invite) { |
60 | if(err) throw err |
61 | var invite = u.parse(_invite) |
62 | var seed = invite.seed |
63 | var invite_id = invite.invite |
64 | |
65 | //use device address, just for tests |
66 | invite.pubs.push(alice.getAddress('device')) |
67 | |
68 | bob.userInvites.openInvite(invite, function (err, invite_msg, data) { |
69 | if(err) throw err |
70 | t.ok(invite) |
71 | t.equal(toId(invite_msg), invite_id) |
72 | t.deepEqual(data, {reveal: undefined, private: undefined}) |
73 | |
74 | //bob publishes accept_content manually. simulates that he crashed |
75 | //before causing confirm. |
76 | var accept_content = I.createAccept(invite_msg, seed, bob.id, caps) |
77 | bob.publish(accept_content, function (err, accept) { |
78 | if(err) throw err |
79 | |
80 | bob.userInvites.acceptInvite(invite, function (err, confirm) { |
81 | if(err) throw err |
82 | |
83 | //check that alice and bob both understand the other to be following them. |
84 | bob.friends.hops({reverse: true}, function (err, hops) { |
85 | t.equal(hops[alice.id], 1) |
86 | alice.friends.hops({reverse: true}, function (err, hops) { |
87 | t.equal(hops[bob.id], 1) |
88 | alice.close() |
89 | bob.close() |
90 | t.end() |
91 | }) |
92 | }) |
93 | }) |
94 | }) |
95 | }) |
96 | }) |
97 | }) |
98 | |
99 |
Built with git-ssb-web