git ssb

0+

Dominic / ssb-peer-invites



Tree: 3f14a6dcd8d9c4cb8d9fa48e216e5c4c1e91d52a

Files: 3f14a6dcd8d9c4cb8d9fa48e216e5c4c1e91d52a / test / accept3.js

2543 bytesRaw
1//WARNING: this test currently only passes
2//if the computer has a network.
3var crypto = require('crypto')
4var u = require('../util')
5
6var ssbKeys = require('ssb-keys')
7var tape = require('tape')
8var pull = require('pull-stream')
9var ref = require('ssb-ref')
10
11var createSbot = require('ssb-server')
12 .use(require('ssb-links'))
13 .use({
14 name: 'replicate', version: '1.0.0',
15 manifest: { request: 'sync' },
16 init: function () {
17 return { request: function () {} }
18 }
19 })
20 .use(require('ssb-query'))
21 .use(require('ssb-device-address'))
22 .use(require('ssb-identities'))
23 .use(require('ssb-friends'))
24 .use(require('../'))
25
26function toId(msg) {
27 return '%'+ssbKeys.hash(JSON.stringify(msg, null, 2))
28}
29
30var caps = require('./randcaps')()
31
32var alice = createSbot({
33 temp: true,
34 timeout: 1000,
35 port: 12342,
36 keys:ssbKeys.generate(),
37 caps: caps
38})
39var bob = createSbot({
40 temp: true,
41 timeout: 1000,
42 port: 12343,
43 keys:ssbKeys.generate(),
44 caps: caps
45})
46
47tape('create an invite', function (t) {
48
49 //in this test, we use a separate identity to create the invite,
50 //to test multiple identity support, and also simulate confirmation by pub.
51 alice.identities.create(function (err, carol_id) {
52 if(err) throw err
53 alice.peerInvites.create({id: carol_id, allowWithoutPubs: true}, function (err, _invite) {
54 if(err) throw err
55 var invite = u.parse(_invite)
56 var invite_id = invite.invite
57
58 //use device address, just for tests
59 invite.pubs.push(alice.getAddress('device'))
60
61 bob.peerInvites.openInvite(invite, function (err, invite_msg, data) {
62 if(err) throw err
63 t.ok(invite)
64 t.equal(invite_msg.author, carol_id)
65 t.equal(toId(invite_msg), invite_id)
66 t.deepEqual(data, {reveal: undefined, private: undefined})
67 //check this invite is valid. would throw if it wasn't.
68 bob.peerInvites.acceptInvite(invite, function (err, confirm) {
69 if(err) throw err
70 t.equal(confirm.author, alice.id)
71 //check that alice and bob both understand the other to be following them.
72 bob.friends.hops({reverse: true}, function (err, hops) {
73 if(err) throw err
74 t.equal(hops[carol_id], 1)
75 alice.friends.hops({reverse: true, start: carol_id}, function (err, hops) {
76 if(err) throw err
77 t.equal(hops[bob.id], 1)
78 alice.close()
79 bob.close()
80 t.end()
81 })
82 })
83 })
84 })
85 })
86 })
87})
88
89

Built with git-ssb-web