git ssb

0+

Dominic / ssb-peer-invites



Commit 5b1f218a3f28e90d43dcf6b0798da47536ee7fb7

more accept tests, to check various aspects of the server or client crashing or the network failing

Dominic Tarr committed on 12/16/2018, 2:08:20 AM
Parent: 7de0b4662d47ce3bf132efbafab7cfe78166ff80

Files changed

test/accept.jschanged
test/accept3.jschanged
test/accept4.jsadded
test/accept5.jsadded
test/accept.jsView
@@ -106,7 +106,4 @@
106106 )
107107 })
108108 })
109109
110-
111-
112-
test/accept3.jsView
@@ -24,8 +24,13 @@
2424 .use(require('ssb-identities'))
2525 .use(require('ssb-friends'))
2626 .use(require('../'))
2727
28 +
29 +function toId(msg) {
30 + return '%'+ssbKeys.hash(JSON.stringify(msg, null, 2))
31 +}
32 +
2833 function all(stream, cb) {
2934 return pull(stream, pull.collect(cb))
3035 }
3136
@@ -50,12 +55,8 @@
5055 caps: caps
5156 })
5257 var carol = ssbKeys.generate()
5358
54-function toId(msg) {
55- return '%'+ssbKeys.hash(JSON.stringify(msg, null, 2))
56-}
57-
5859 tape('create an invite', function (t) {
5960
6061 var seed = crypto.randomBytes(32)
6162
@@ -96,4 +97,5 @@
9697 })
9798 })
9899 })
99100
101 +
test/accept4.jsView
@@ -1,0 +1,107 @@
1 +var crypto = require('crypto')
2 +var I = require('../valid')
3 +var createClient = require('ssb-client')
4 +
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({}, function (err, invite) {
60 + if(err) throw err
61 + var seed = invite.seed
62 + var invite_id = invite.invite
63 +
64 + //use device address, just for tests
65 + invite.pubs.push(alice.getAddress('device'))
66 +
67 + bob.userInvites.openInvite(invite, function (err, invite_msg, data) {
68 + if(err) throw err
69 + t.ok(invite)
70 + t.equal(toId(invite_msg), invite_id)
71 + t.deepEqual(data, {reveal: undefined, private: undefined})
72 +
73 + //bob publishes accept_content manually. simulates that he crashed
74 + //before causing confirm.
75 + var accept_content = I.createAccept(invite_msg, seed, bob.id, caps)
76 + bob.publish(accept_content, function (err, accept) {
77 + if(err) throw err
78 +
79 + bob.userInvites.acceptInvite(invite, function (err, confirm) {
80 + if(err) throw err
81 +
82 + //check that alice and bob both understand the other to be following them.
83 + bob.friends.hops({reverse: true}, function (err, hops) {
84 + t.equal(hops[alice.id], 1)
85 + alice.friends.hops({reverse: true}, function (err, hops) {
86 + t.equal(hops[bob.id], 1)
87 + alice.close()
88 + bob.close()
89 + t.end()
90 + })
91 + })
92 + })
93 + })
94 + })
95 + })
96 +})
97 +
98 +
99 +
100 +
101 +
102 +
103 +
104 +
105 +
106 +
107 +
test/accept5.jsView
@@ -1,0 +1,119 @@
1 +var crypto = require('crypto')
2 +var I = require('../valid')
3 +var createClient = require('ssb-client')
4 +
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({}, function (err, invite) {
60 + if(err) throw err
61 + var seed = invite.seed
62 + var invite_id = invite.invite
63 +
64 + //use device address, just for tests
65 + invite.pubs.push(alice.getAddress('device'))
66 +
67 + bob.userInvites.openInvite(invite, function (err, invite_msg, data) {
68 + if(err) throw err
69 + t.ok(invite)
70 + t.equal(toId(invite_msg), invite_id)
71 + t.deepEqual(data, {reveal: undefined, private: undefined})
72 +
73 + //bob publishes accept_content manually. simulates that he crashed
74 + //before causing confirm.
75 + var accept_content = I.createAccept(invite_msg, seed, bob.id, caps)
76 + bob.publish(accept_content, function (err, accept) {
77 + if(err) throw err
78 +
79 + //alice manually creates confrim, to simulate receiving it, but crashing
80 + //before bob receives it back, and so he calls again.
81 +
82 + alice.publish(I.createConfirm(accept.value), function (err, _confirm) {
83 + if(err) throw err
84 + bob.userInvites.acceptInvite(invite, function (err, confirm) {
85 + if(err) throw err
86 + //alice returns the same confirm message, does not create a new one
87 + t.equal(toId(confirm), toId(_confirm.value), 'id is equal')
88 + t.deepEqual(confirm, _confirm.value)
89 +
90 + //check that alice and bob both understand the other to be following them.
91 + bob.friends.hops({reverse: true}, function (err, hops) {
92 + t.equal(hops[alice.id], 1)
93 + alice.friends.hops({reverse: true}, function (err, hops) {
94 + t.equal(hops[bob.id], 1)
95 + alice.close()
96 + bob.close()
97 + t.end()
98 + })
99 + })
100 + })
101 + })
102 + })
103 + })
104 + })
105 +})
106 +
107 +
108 +
109 +
110 +
111 +
112 +
113 +
114 +
115 +
116 +
117 +
118 +
119 +

Built with git-ssb-web