git ssb

4+

Dominic / scuttlebot



Tree: 4250819350e538b6f5b1c63433e0b4b3f27ff6be

Files: 4250819350e538b6f5b1c63433e0b4b3f27ff6be / test / block3.js

2325 bytesRaw
1var cont = require('cont')
2var tape = require('tape')
3var pull = require('pull-stream')
4var u = require('./util')
5
6var replicate = require('../plugins/replicate')
7var friends = require('../plugins/friends')
8var block = require('../plugins/block')
9var ssbKeys = require('ssb-keys')
10var toAddress = require('../lib/util').toAddress
11
12
13// alice, bob, and carol all follow each other,
14// but then bob offends alice, and she blocks him.
15// this means that:
16//
17// 1. when bob tries to connect to alice, she refuses.
18// 2. alice never tries to connect to bob. (removed from peers)
19// 3. carol will not give bob any, she will not give him any data from alice.
20
21var createSbot = require('../')
22 .use(require('../plugins/friends'))
23 .use(require('../plugins/replicate'))
24 .use(require('../plugins/block'))
25
26var alice = createSbot({
27 temp: 'test-block-alice', timeout: 1000,
28 keys: ssbKeys.generate()
29 })
30
31var bob = createSbot({
32 temp: 'test-block-bob', timeout: 1000,
33 keys: ssbKeys.generate()
34 })
35
36var carol = createSbot({
37 temp: 'test-block-carol', timeout: 1000,
38 keys: ssbKeys.generate()
39 })
40
41
42
43tape('alice blocks bob while he is connected, she should disconnect him', function (t) {
44
45 //in the beginning alice and bob follow each other
46 cont.para([
47 alice.publish(u.follow(bob.id)),
48 bob .publish(u.follow(alice.id)),
49 carol.publish(u.follow(alice.id))
50 ]) (function (err) {
51 if(err) throw err
52
53 var n = 3, rpc
54
55 bob.connect(carol.getAddress(), function (err, rpc) {
56 if(err) throw err
57 })
58
59 carol.connect(alice.getAddress(), function (err, rpc) {
60 if(err) throw err
61 })
62
63 bob.on('replicate:finish', function (vclock) {
64 //I don't care which messages bob doesn't have of alice's
65 t.ok(vclock[alice.id] < 2, 'bob has alices first message')
66 alice.close();bob.close();carol.close()
67 t.end()
68 })
69
70 var once = false
71 var bobCancel = bob.post(function (op) {
72 console.log('BOB RECV', op, bob.id)
73 if(once) throw new Error('should only be called once')
74 once = true
75 //should be the alice's follow(bob) message.
76
77 t.equal(op.value.author, alice.id)
78 t.equal(op.value.content.contact, bob.id)
79 alice.publish(u.block(bob.id))
80 (function (err) { if(err) throw err })
81 }, false)
82 })
83})
84
85

Built with git-ssb-web