Files: 7f5b9989dbc45ee625499416f98f9ce28de20509 / test / fork.js
2324 bytesRaw
1 | |
2 | var tape = require('tape') |
3 | var pull = require('pull-stream') |
4 | var ssbKeys = require('ssb-keys') |
5 | var createFeed = require('../') |
6 | var ssbkeys = ssbKeys |
7 | |
8 | var crypto = require('crypto') |
9 | |
10 | var seed = crypto.createHash('sha256').update('test1').digest() |
11 | var sign_cap = crypto.createHash('sha256').update('test1').digest() |
12 | var assert = require('assert') |
13 | |
14 | module.exports = function (createMock, createAsync, opts) { |
15 | |
16 | |
17 | tape('simple', function (t) { |
18 | createAsync(function (async) { |
19 | var ssb1 = createMock(async, {}) |
20 | var ssb2 = createMock(async, {caps: {sign: sign_cap}}) |
21 | |
22 | var feed = createFeed(ssb1, ssbkeys.generate('ed25519', seed), opts) |
23 | |
24 | feed.add({type: 'msg', value: 'hello there!'}, function (err, msg) { |
25 | if(err) throw err |
26 | console.log('added', msg) |
27 | assert.ok(!!msg) |
28 | assert.ok(!!msg.key) |
29 | assert.ok(!!msg.value) |
30 | ssb2.add(msg.value, function (err) { |
31 | t.ok(err) |
32 | t.ok(/signature was invalid/.test(err.message)) |
33 | console.log(err) |
34 | t.end() |
35 | }) |
36 | }) |
37 | }) |
38 | }) |
39 | |
40 | tape('check that default validates old default messages', function (t) { |
41 | createAsync(function (async) { |
42 | |
43 | var ssb1 = createMock(async, {}) |
44 | var ssb2 = createMock(async, {caps: {sign: sign_cap}}) |
45 | |
46 | var data = { //first message in my log. |
47 | "key": "%7iU6nEO35X37x7lFGXpwx8fWFDFIwAaxQNu2ySVVz10=.sha256", |
48 | "value": { |
49 | "previous": null, |
50 | "author": "@EMovhfIrFk4NihAKnRNhrfRaqIhBv1Wj8pTxJNgvCCY=.ed25519", |
51 | "sequence": 1, |
52 | "timestamp": 1449201626119, |
53 | "hash": "sha256", |
54 | "content": { |
55 | "type": "about", |
56 | "about": "@EMovhfIrFk4NihAKnRNhrfRaqIhBv1Wj8pTxJNgvCCY=.ed25519", |
57 | "name": "Dominic_2" |
58 | }, |
59 | "signature": "vyn7WnkamEjHvQ1/crAZgKUi6ucOcHkpG4uRdSMjZdJnT8eyyH63rCmsC4A0bmhDaDPEwCVHoOF4NQHiVS+0Cg==.sig.ed25519" |
60 | }, |
61 | "timestamp": 1472327253354 |
62 | } |
63 | |
64 | ssb1.add(data.value, function (err, msg) { |
65 | if(err) throw err |
66 | |
67 | ssb2.add(data.value, function (err) { |
68 | t.ok(/signature was invalid/.test(err.message)) |
69 | t.end() |
70 | }) |
71 | }) |
72 | }) |
73 | }) |
74 | } |
75 | |
76 | |
77 | |
78 | |
79 | if(!module.parent) { |
80 | module.exports(require('./mock'), require('./util').sync) |
81 | |
82 | } |
83 | |
84 | |
85 | |
86 | |
87 | |
88 | |
89 | |
90 | |
91 | |
92 |
Built with git-ssb-web