git ssb

0+

Dominic / ssb-peer-invites



Tree: 31ba9f2ced690940575b567c8e7a790e97e21ec3

Files: 31ba9f2ced690940575b567c8e7a790e97e21ec3 / test / accept3.js

2864 bytesRaw
1//WARNING: this test currently only passes
2//if the computer has a network.
3var crypto = require('crypto')
4var I = require('../valid')
5var createClient = require('ssb-client')
6var u = require('../util')
7
8var ssbKeys = require('ssb-keys')
9var tape = require('tape')
10var pull = require('pull-stream')
11var ref = require('ssb-ref')
12
13var 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
28function toId(msg) {
29 return '%'+ssbKeys.hash(JSON.stringify(msg, null, 2))
30}
31
32function all(stream, cb) {
33 return pull(stream, pull.collect(cb))
34}
35
36var caps = {
37 sign: crypto.randomBytes(32),//.toString('base64'),
38 peerInvite: crypto.randomBytes(32),//.toString('base64'),
39 shs: crypto.randomBytes(32),//.toString('base64'),
40}
41
42var alice = createSbot({
43 temp: true,
44 timeout: 1000,
45 port: 12342,
46 keys:ssbKeys.generate(),
47 caps: caps
48})
49var bob = createSbot({
50 temp: true,
51 timeout: 1000,
52 port: 12343,
53 keys:ssbKeys.generate(),
54 caps: caps
55})
56var carol = ssbKeys.generate()
57
58tape('create an invite', function (t) {
59
60 var seed = crypto.randomBytes(32)
61
62 //in this test, we use a separate identity to create the invite,
63 //to test multiple identity support, and also simulate confirmation by pub.
64 alice.identities.create(function (err, carol_id) {
65 if(err) throw err
66 alice.peerInvites.create({id: carol_id, allowWithoutPubs: true}, function (err, _invite) {
67 if(err) throw err
68 var invite = u.parse(_invite)
69 var seed = invite.seed
70 var invite_id = invite.invite
71
72 //use device address, just for tests
73 invite.pubs.push(alice.getAddress('device'))
74
75 bob.peerInvites.openInvite(invite, function (err, invite_msg, data) {
76 if(err) throw err
77 t.ok(invite)
78 t.equal(invite_msg.author, carol_id)
79 t.equal(toId(invite_msg), invite_id)
80 t.deepEqual(data, {reveal: undefined, private: undefined})
81 //check this invite is valid. would throw if it wasn't.
82 bob.peerInvites.acceptInvite(invite, function (err, confirm) {
83 if(err) throw err
84 t.equal(confirm.author, alice.id)
85 //check that alice and bob both understand the other to be following them.
86 bob.friends.hops({reverse: true}, function (err, hops) {
87 t.equal(hops[carol_id], 1)
88 alice.friends.hops({reverse: true, start: carol_id}, function (err, hops) {
89 t.equal(hops[bob.id], 1)
90 alice.close()
91 bob.close()
92 t.end()
93 })
94 })
95 })
96 })
97 })
98 })
99})
100
101

Built with git-ssb-web