git ssb

1+

kieran / horcrux-schemas-and-thoughts



Commit 0bebd57e201531188e6d1b2b1b4f586d2000fa1b

test invite flumeView

Kieran committed on 4/17/2018, 2:35:26 AM
Parent: 68c5144682ae892eea922813d3a9926745a0dda3

Files changed

index.jschanged
test/index.jschanged
index.jsView
@@ -3,9 +3,9 @@
33 const get = require('lodash/get')
44 const extend = require('xtend')
55 const pry = require('pryjs')
66
7-const FLUME_VIEW_VERSION = 1.311223122
7 +const FLUME_VIEW_VERSION = 1.3112231222
88 const FLUME_VIEW_NAME = "secrets"
99
1010 const MODULE_NAME = "secrets"
1111 const MSG_TYPES = ["root", "invite", "response", "contract", "secret", "announcement"]
@@ -14,29 +14,36 @@
1414 name: FLUME_VIEW_NAME,
1515 version: '1.0.0',
1616 manifest: {
1717 root: {
18 + publish: 'async',
1819 get: 'async',
1920 stream: 'source'
2021 },
2122 invites: {
23 + publish: 'async',
2224 get: 'async',
2325 stream: 'source'
2426 },
27 + response: {
28 + publish: 'async'
29 + },
2530 secrets: {
31 + publish: 'async',
2632 get: 'async',
2733 stream: 'source'
2834 }
2935 },
3036 init: function (server, config) {
3137 const root = server._flumeUse("root", flumeView(FLUME_VIEW_VERSION, (accumulator, content) => {
38 + accumulator = accumulator || {}
3239 var roots = accumulator[content.author] || []
3340 if (!(roots.filter(root => root.id === content.id).length > 0)) roots.push(content.id)
3441 accumulator[content.author] = roots
3542 return accumulator
3643 }, (msg) => {
3744 var { author, content } = msg.value
38- content = server.private.unbox(content, config.keys.private)
45 + content = server.private.unbox(content)
3946 if (!(content && content.module && content.module === MODULE_NAME && content.type === "root")) return null
4047 return {
4148 id: msg.key,
4249 author: author
@@ -47,17 +54,13 @@
4754 var invites = accumulator[content.root] || []
4855 var invite = invites.filter(invite => invite.id === content.id)[0]
4956 if (!invite) {
5057 if (isResponse()) {
51- console.log("Hit the response")
5258 var inviteIndex = invites.findIndex(invite => invite.id === content.invite)
53- console.log("Index: ", inviteIndex)
5459 if (inviteIndex !== -1) {
5560 invites[inviteIndex].accepted = content.accepted
56- console.log("Invites: ", invites)
5761 }
5862 } else {
59- console.log("Seems to think its a new invite")
6063 invites.push({
6164 id: content.id,
6265 recps: content.recps
6366 })
@@ -70,16 +73,10 @@
7073 return true && content.invite
7174 }
7275 }, (msg) => {
7376 var { author, content } = msg.value
74- content = server.private.unbox(content, config.keys.private)
75- console.log(content)
76- console.log("\n")
77 + content = server.private.unbox(content)
7778 if (!(content && isSecretsModule() && inviteOrResponse())) return null
78- console.log("Invite: ", msg.key)
79- console.log("Author: ", author)
80- console.log("Invitees: ", content.recps)
81- console.log("Type: ", content.type)
8279 return {
8380 id: msg.key,
8481 root: content.root,
8582 recps: content.recps,
@@ -113,16 +110,44 @@
113110 }, null, {}))
114111
115112 return {
116113 root: {
114 + publish: (opts, cb) => {
115 + server.private.publish(extend({
116 + module: 'secrets',
117 + type: 'root'
118 + }, opts))
119 + },
117120 get: root.get,
118121 stream: root.stream
119122 },
120123 invites: {
124 + publish: (opts, cb) => {
125 + server.private.publish(extend({
126 + module: 'secrets',
127 + type: 'invite'
128 + }, opts))
129 + },
121130 get: invites.get,
122131 stream: invites.stream
123132 },
133 + response: {
134 + publish: (opts, cb) => {
135 + server.private.publish(extend({
136 + module: 'secrets',
137 + type: 'response'
138 + }))
139 + }
140 + },
124141 secrets: {
142 + publish: (opts, cb) => {
143 + servder.private.publish(extend({
144 + module: 'secrets',
145 + type: 'secret'
146 + }), [
147 +
148 + ], cb)
149 + },
125150 get: secrets.get,
126151 stream: secrets.stream
127152 }
128153 }
test/index.jsView
@@ -1,43 +1,77 @@
11 const Server = require('scuttle-testbot')
22 const Keys = require('ssb-keys')
3-const test = require('tape')
3 +const Test = require('tape')
4 +
5 +const pull = require('pull-stream')
46 const get = require('lodash/get')
7 +
58 const pry = require('pryjs')
69
7-Server
8- .use(require('ssb-private'))
9- .use(require('../index.js'))
10 +// Generate two identities and start two test servers
1011
1112 const alice = Keys.generate()
1213 const bob = Keys.generate()
1314
14-console.log("*** Generating Keys ***", "\n")
15-console.log("Alice: ", alice, "\n")
16-console.log("Bob: ", bob, "\n")
15 +Server
16 + .use(require('ssb-private'))
17 + .use(require('../index.js'))
1718
18-console.log("*** Starting Alice's Server ***", "\n")
1919 const aliceConfig = { name: "alicetestbot", keys: alice }
20-const aliceServer = Server(aliceConfig)
21-console.log(aliceServer)
20 +const aliceServer = new Server(aliceConfig)
2221
23-test("it should publish an encrypted secret root", t => {
22 +Server
23 + .use(require('ssb-private'))
24 + .use(require('../index.js'))
25 +
26 +const bobConfig = { name: "bobtestbot", keys: bob }
27 +const bobServer = new Server(bobConfig)
28 +
29 +var root
30 +
31 +Test("it publishes an encrypted secret root that is only visible to Alice", t => {
2432 aliceServer.private.publish({
25- module: "secret",
33 + module: "secrets",
2634 type: "root"
2735 }, [
2836 aliceConfig.keys.id
2937 ], (err, msg) => {
3038 var { author, content } = msg.value
31- var decrypt = aliceServer.private.unbox(content, alice.private)
39 + root = msg.key
3240
33- t.equal(author, alice.id)
34- t.equal("secret", decrypt.module)
35- t.equal("root", decrypt.type)
41 + // Author is Alice
42 + t.equal(alice.id, author)
43 + t.notEqual(bob.id, author)
44 +
45 + // Decrypt
46 + var decryptByAlice = aliceServer.private.unbox(content)
47 + var decryptByBob = bobServer.private.unbox(content)
48 +
49 + t.equal(get(decryptByAlice, "module"), "secrets")
50 + t.notEqual(get(decryptByBob, "module"), "secrets")
51 +
52 + t.equal(get(decryptByAlice, "type"), "root")
53 + t.notEqual(get(decryptByBob, "type"), "root")
54 +
3655 t.end()
3756 })
3857 })
3958
40-test("it should return a collection of root IDs", t => {
41- t.equal(0, 0)
42- t.end()
59 +Test("it returns a collection of invites", t => {
60 + aliceServer.private.publish({
61 + module: "secrets",
62 + type: "invite",
63 + root: root
64 + }, [
65 + aliceConfig.keys.id,
66 + bobConfig.keys.id
67 + ], (err, invite) => {
68 + pull(
69 + aliceServer.secrets.invites.stream(),
70 + pull.drain(msg => {
71 + t.equal(msg[root].length, 1)
72 + t.equal(msg[root][0].id, invite.key)
73 + t.end()
74 + })
75 + )
76 + })
4377 })

Built with git-ssb-web