git ssb

0+

Dominic / ssb-peer-invites



Tree: 2dcc95969b2766ca87d3f0c22dbf0f0f397bf642

Files: 2dcc95969b2766ca87d3f0c22dbf0f0f397bf642 / test / accept3.js

2779 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')
6
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
28
29function toId(msg) {
30 return '%'+ssbKeys.hash(JSON.stringify(msg, null, 2))
31}
32
33function all(stream, cb) {
34 return pull(stream, pull.collect(cb))
35}
36
37var caps = {
38 sign: crypto.randomBytes(32),//.toString('base64'),
39 userInvite: crypto.randomBytes(32),//.toString('base64'),
40 shs: crypto.randomBytes(32),//.toString('base64'),
41}
42
43var alice = createSbot({
44 temp: true,
45 timeout: 1000,
46 port: 12342,
47 keys:ssbKeys.generate(),
48 caps: caps
49})
50var bob = createSbot({
51 temp: true,
52 timeout: 1000,
53 port: 12343,
54 keys:ssbKeys.generate(),
55 caps: caps
56})
57var carol = ssbKeys.generate()
58
59tape('create an invite', function (t) {
60
61 var seed = crypto.randomBytes(32)
62
63 //in this test, we use a separate identity to create the invite,
64 //to test multiple identity support, and also simulate confirmation by pub.
65 alice.identities.create(function (err, carol_id) {
66 if(err) throw err
67 alice.userInvites.create({id: carol_id}, function (err, invite) {
68 if(err) throw err
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.userInvites.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.userInvites.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
102

Built with git-ssb-web