git ssb

0+

Dominic / ssb-peer-invites



Tree: 391163e63d7f2d8f4b5c8568fb7bfe8c355a54d0

Files: 391163e63d7f2d8f4b5c8568fb7bfe8c355a54d0 / test / accept3.js

2578 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})
46var carol = ssbKeys.generate()
47
48tape('create an invite', function (t) {
49
50 var seed = crypto.randomBytes(32)
51
52 //in this test, we use a separate identity to create the invite,
53 //to test multiple identity support, and also simulate confirmation by pub.
54 alice.identities.create(function (err, carol_id) {
55 if(err) throw err
56 alice.peerInvites.create({id: carol_id, allowWithoutPubs: true}, function (err, _invite) {
57 if(err) throw err
58 var invite = u.parse(_invite)
59 var seed = invite.seed
60 var invite_id = invite.invite
61
62 //use device address, just for tests
63 invite.pubs.push(alice.getAddress('device'))
64
65 bob.peerInvites.openInvite(invite, function (err, invite_msg, data) {
66 if(err) throw err
67 t.ok(invite)
68 t.equal(invite_msg.author, carol_id)
69 t.equal(toId(invite_msg), invite_id)
70 t.deepEqual(data, {reveal: undefined, private: undefined})
71 //check this invite is valid. would throw if it wasn't.
72 bob.peerInvites.acceptInvite(invite, function (err, confirm) {
73 if(err) throw err
74 t.equal(confirm.author, alice.id)
75 //check that alice and bob both understand the other to be following them.
76 bob.friends.hops({reverse: true}, function (err, hops) {
77 t.equal(hops[carol_id], 1)
78 alice.friends.hops({reverse: true, start: carol_id}, function (err, hops) {
79 t.equal(hops[bob.id], 1)
80 alice.close()
81 bob.close()
82 t.end()
83 })
84 })
85 })
86 })
87 })
88 })
89})
90
91

Built with git-ssb-web