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