git ssb

4+

Dominic / scuttlebot



Tree: a4af2ae17277b41330b06887b35138e2fab83b39

Files: a4af2ae17277b41330b06887b35138e2fab83b39 / test / caps.js

2340 bytesRaw
1
2var cont = require('cont')
3var deepEqual = require('deep-equal')
4var tape = require('tape')
5var pull = require('pull-stream')
6var ssbKeys = require('ssb-keys')
7
8var 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
14var createSbot = require('../')
15 .use(require('../plugins/friends'))
16 .use(require('../plugins/replicate'))
17 .use(require('../plugins/gossip'))
18 .use(require('../plugins/logging'))
19
20var createHash = require('crypto').createHash
21
22function hash (data) {
23 return createHash('sha256').update(data, 'utf8').digest()
24}
25
26var sign_cap1 = hash('test-sign-cap1')
27var shs_cap1 = hash('test-shs-cap1')
28
29var alice, bob, carol
30var 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
42var 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
51var 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
63tape('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
79tape('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
90tape('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
99tape('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
107tape('cleanup', function (t) {
108 dbA.close()
109 dbB.close()
110 dbC.close()
111 t.end()
112})
113
114

Built with git-ssb-web