Files: aefe1c57d403d6caf0ca29793121221ed00ff9cf / test / caps.js
2340 bytesRaw
1 | |
2 | var cont = require('cont') |
3 | var deepEqual = require('deep-equal') |
4 | var tape = require('tape') |
5 | var pull = require('pull-stream') |
6 | var ssbKeys = require('ssb-keys') |
7 | |
8 | var u = require('./util') |
9 | |
10 | // create 3 servers |
11 | // give them all pub servers (on localhost) |
12 | // and get them to follow each other... |
13 | |
14 | var createSbot = require('../') |
15 | .use(require('../plugins/friends')) |
16 | .use(require('../plugins/replicate')) |
17 | .use(require('../plugins/gossip')) |
18 | .use(require('../plugins/logging')) |
19 | |
20 | var createHash = require('crypto').createHash |
21 | |
22 | function hash (data) { |
23 | return createHash('sha256').update(data, 'utf8').digest() |
24 | } |
25 | |
26 | var sign_cap1 = hash('test-sign-cap1') |
27 | var shs_cap1 = hash('test-shs-cap1') |
28 | |
29 | var alice, bob, carol |
30 | var dbA = createSbot({ |
31 | temp: 'server-alice', |
32 | port: 45451, timeout: 1400, |
33 | keys: alice = ssbKeys.generate(), |
34 | caps: { |
35 | shs: shs_cap1, |
36 | sign: sign_cap1 |
37 | }, |
38 | level: 'info' |
39 | }) |
40 | |
41 | //uses default caps, incompatible with above |
42 | var dbB = createSbot({ |
43 | temp: 'server-bob', |
44 | port: 45452, timeout: 1400, |
45 | keys: bob = ssbKeys.generate(), |
46 | seeds: [dbA.getAddress()], |
47 | level: 'info' |
48 | }) |
49 | |
50 | //can connect to A |
51 | var dbC = createSbot({ |
52 | temp: 'server-carol', |
53 | port: 45453, timeout: 1400, |
54 | keys: alice = ssbKeys.generate(), |
55 | caps: { |
56 | shs: shs_cap1, |
57 | sign: sign_cap1 |
58 | }, |
59 | level: 'info' |
60 | }) |
61 | |
62 | |
63 | tape('signatures not accepted if made from different caps', function (t) { |
64 | |
65 | |
66 | dbA.publish({type: 'test', foo: true}, function (err, msg) { |
67 | |
68 | console.log(msg) |
69 | dbB.add(msg.value, function (err) { |
70 | t.ok(err) //should not be valid in this universe |
71 | t.ok(/signature was invalid/.test(err.message)) |
72 | console.log(err.stack) |
73 | t.end() |
74 | |
75 | }) |
76 | }) |
77 | }) |
78 | |
79 | tape('cannot connect if different shs caps, custom -> default', function (t) { |
80 | dbA.connect(dbB.getAddress(), function (err) { |
81 | t.ok(err) |
82 | console.log(err.stack) |
83 | |
84 | t.end() |
85 | |
86 | }) |
87 | |
88 | }) |
89 | |
90 | tape('cannot connect if different shs caps, default -> custom', function (t) { |
91 | dbB.connect(dbA.getAddress(), function (err) { |
92 | t.ok(err) |
93 | |
94 | console.log(err.stack) |
95 | t.end() |
96 | }) |
97 | }) |
98 | |
99 | tape('cannot connect if different shs caps, default -> custom', function (t) { |
100 | dbC.connect(dbA.getAddress(), function (err) { |
101 | if(err) throw err |
102 | t.end() |
103 | }) |
104 | }) |
105 | |
106 | |
107 | tape('cleanup', function (t) { |
108 | dbA.close() |
109 | dbB.close() |
110 | dbC.close() |
111 | t.end() |
112 | }) |
113 | |
114 |
Built with git-ssb-web