From 1f1f23312c180c332e3b912b9e70c11c9c16c0bc Mon Sep 17 00:00:00 2001 From: Walker Date: Tue, 16 Apr 2019 21:08:36 -0300 Subject: [PATCH 01/23] test: add todo test --- src/bot.test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/bot.test.js b/src/bot.test.js index 14ad945..8391b58 100644 --- a/src/bot.test.js +++ b/src/bot.test.js @@ -386,4 +386,19 @@ test('publish a post using template on sbot', t => { } bot(config)(null, sbot) }); +}) + +test.todo('deny when a non-admin tries to add a feed', t => { + const publish = (post) => { + t.is(post.type, 'post') + t.truthy( + post.text.includes('Sorry, you\'re not allowed to do this') + ) + t.end() + } + const sbot = { publish, whoami() { } } + const config = { + feedUrls: ['thefeedUrl'], + } + bot(config)(null, sbot) }) \ No newline at end of file From db31e0308655ee3bbd742011c1625cd644211a16 Mon Sep 17 00:00:00 2001 From: Walker Date: Tue, 16 Apr 2019 21:09:17 -0300 Subject: [PATCH 02/23] fix: fix error --- src/bot.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bot.test.js b/src/bot.test.js index 8391b58..5b8f3b7 100644 --- a/src/bot.test.js +++ b/src/bot.test.js @@ -388,7 +388,7 @@ test('publish a post using template on sbot', t => { }); }) -test.todo('deny when a non-admin tries to add a feed', t => { +test.skip('deny when a non-admin tries to add a feed', t => { const publish = (post) => { t.is(post.type, 'post') t.truthy( From 497a6f7d9a82cab204cec28e61def000ca9f84f7 Mon Sep 17 00:00:00 2001 From: Walker Date: Tue, 16 Apr 2019 22:07:20 -0300 Subject: [PATCH 03/23] test: re add test --- src/bot.test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bot.test.js b/src/bot.test.js index 5b8f3b7..68e430f 100644 --- a/src/bot.test.js +++ b/src/bot.test.js @@ -388,7 +388,7 @@ test('publish a post using template on sbot', t => { }); }) -test.skip('deny when a non-admin tries to add a feed', t => { +test.skip('deny when a non-admin tries to add a feed', async t => { const publish = (post) => { t.is(post.type, 'post') t.truthy( @@ -397,7 +397,10 @@ test.skip('deny when a non-admin tries to add a feed', t => { t.end() } const sbot = { publish, whoami() { } } + const feedMonitor = { + } const config = { + feedMonitor, feedUrls: ['thefeedUrl'], } bot(config)(null, sbot) From ce0be871eee92d2f44407e39f86fc18e3781e089 Mon Sep 17 00:00:00 2001 From: Walker Date: Tue, 16 Apr 2019 22:08:53 -0300 Subject: [PATCH 04/23] fix: fix feedMonitor mock --- src/bot.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bot.test.js b/src/bot.test.js index 68e430f..734ff1a 100644 --- a/src/bot.test.js +++ b/src/bot.test.js @@ -398,6 +398,8 @@ test.skip('deny when a non-admin tries to add a feed', async t => { } const sbot = { publish, whoami() { } } const feedMonitor = { + create() { }, + destroy() { }, } const config = { feedMonitor, From 7689ad4ab24cff2892bc0cf87579e874fc314ea1 Mon Sep 17 00:00:00 2001 From: Walker Date: Tue, 16 Apr 2019 22:22:33 -0300 Subject: [PATCH 05/23] feat: add createUserStream --- src/bot.test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bot.test.js b/src/bot.test.js index 734ff1a..a553cd9 100644 --- a/src/bot.test.js +++ b/src/bot.test.js @@ -396,14 +396,15 @@ test.skip('deny when a non-admin tries to add a feed', async t => { ) t.end() } - const sbot = { publish, whoami() { } } + const createUserStream = ({ live, id }) => { } + const sbot = { publish, createUserStream, whoami() { } } const feedMonitor = { create() { }, destroy() { }, } const config = { feedMonitor, - feedUrls: ['thefeedUrl'], + feedUrls: [], } bot(config)(null, sbot) }) \ No newline at end of file From 9591bc47d3fbbb41c287e7d086faab874da36d1e Mon Sep 17 00:00:00 2001 From: Walker Date: Tue, 16 Apr 2019 22:27:07 -0300 Subject: [PATCH 06/23] test: add createUserStream assertions --- src/bot.test.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bot.test.js b/src/bot.test.js index a553cd9..cad7819 100644 --- a/src/bot.test.js +++ b/src/bot.test.js @@ -389,6 +389,8 @@ test('publish a post using template on sbot', t => { }) test.skip('deny when a non-admin tries to add a feed', async t => { + t.plan(4) + const fakeId = 'fakeId' const publish = (post) => { t.is(post.type, 'post') t.truthy( @@ -396,8 +398,12 @@ test.skip('deny when a non-admin tries to add a feed', async t => { ) t.end() } - const createUserStream = ({ live, id }) => { } - const sbot = { publish, createUserStream, whoami() { } } + const createUserStream = ({ live, id }) => { + t.is(live, true) + t.is(id, fakeId) + } + const whoami = () => fakeId + const sbot = { publish, createUserStream, whoami } const feedMonitor = { create() { }, destroy() { }, From ad88d3905a6ee9a77e85e3e35340225ad6c4efc6 Mon Sep 17 00:00:00 2001 From: Walker Date: Tue, 16 Apr 2019 22:38:31 -0300 Subject: [PATCH 07/23] fix: fix whoami --- src/bot.js | 5 ++++- src/bot.test.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bot.js b/src/bot.js index 383671b..50f024e 100644 --- a/src/bot.js +++ b/src/bot.js @@ -25,6 +25,7 @@ Link: [{link}]({link}) export default config => (err, sbot) => { if (err) throw err const { feedMonitor, feedUrls, postTemplate = defaultPostTemplate } = config; + let id; const createFeedMonitor = feedMonitor.create; const onPostPublished = (err, msg) => { @@ -123,13 +124,15 @@ export default config => (err, sbot) => { } const onSbotConnect = (_, keys) => { + id = keys.id console.log( 'feedMonitor user ID:', - keys.id + id ) } sbot.whoami(onSbotConnect) + sbot.createUserStream({live: true, id}) createFeedMonitor(feedUrls, { onPost, onError }) } \ No newline at end of file diff --git a/src/bot.test.js b/src/bot.test.js index cad7819..afbcce1 100644 --- a/src/bot.test.js +++ b/src/bot.test.js @@ -402,7 +402,7 @@ test.skip('deny when a non-admin tries to add a feed', async t => { t.is(live, true) t.is(id, fakeId) } - const whoami = () => fakeId + const whoami = cb => cb(null, { id: fakeId }) const sbot = { publish, createUserStream, whoami } const feedMonitor = { create() { }, From 20046fce701d0b11a8fd7b646be4d3ee4720d6e1 Mon Sep 17 00:00:00 2001 From: Walker Date: Tue, 16 Apr 2019 23:07:22 -0300 Subject: [PATCH 08/23] test: add unbox mock --- src/bot.test.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/bot.test.js b/src/bot.test.js index afbcce1..2376427 100644 --- a/src/bot.test.js +++ b/src/bot.test.js @@ -389,21 +389,28 @@ test('publish a post using template on sbot', t => { }) test.skip('deny when a non-admin tries to add a feed', async t => { - t.plan(4) - const fakeId = 'fakeId' + t.plan(5) + const fakeId = '@fakeId' + const fakePost = { + key: '%someKey', + content: 'Pl**eas****e add feed ht****t***ps*:**/**/*ww*w.feedfo***ral***l.com/samp****le.*xml' + } const publish = (post) => { t.is(post.type, 'post') - t.truthy( - post.text.includes('Sorry, you\'re not allowed to do this') - ) + t.is(post.text, 'Sorry, you\'re not allowed to do this') t.end() } + const unbox = (cypher, cb) => { + t.is(cypher, fakePost.content) + cb(null, cypher.replaceAll(/\*/g, '')) + } const createUserStream = ({ live, id }) => { t.is(live, true) t.is(id, fakeId) + return pull.values([fakePost]) } const whoami = cb => cb(null, { id: fakeId }) - const sbot = { publish, createUserStream, whoami } + const sbot = { publish, unbox, createUserStream, whoami } const feedMonitor = { create() { }, destroy() { }, From 761aa99acc709379bf4fdd2eb6001cf7d29a8eda Mon Sep 17 00:00:00 2001 From: Walker Date: Tue, 16 Apr 2019 23:13:09 -0300 Subject: [PATCH 09/23] feat: add userStream --- src/bot.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bot.js b/src/bot.js index 50f024e..fefcb44 100644 --- a/src/bot.js +++ b/src/bot.js @@ -25,7 +25,7 @@ Link: [{link}]({link}) export default config => (err, sbot) => { if (err) throw err const { feedMonitor, feedUrls, postTemplate = defaultPostTemplate } = config; - let id; + let id, userStream; const createFeedMonitor = feedMonitor.create; const onPostPublished = (err, msg) => { @@ -125,6 +125,7 @@ export default config => (err, sbot) => { const onSbotConnect = (_, keys) => { id = keys.id + userStream = sbot.createUserStream({ live: true, id }) console.log( 'feedMonitor user ID:', id @@ -132,7 +133,6 @@ export default config => (err, sbot) => { } sbot.whoami(onSbotConnect) - sbot.createUserStream({live: true, id}) createFeedMonitor(feedUrls, { onPost, onError }) } \ No newline at end of file From 95cbaea7d73b9c1d61c9af99b62f889016bbb865 Mon Sep 17 00:00:00 2001 From: Walker Date: Wed, 17 Apr 2019 20:26:30 -0300 Subject: [PATCH 10/23] feat: add stream pipe --- src/bot.js | 1 + src/bot.test.js | 1 + src/commandFilter.js | 0 src/commandFilter.test.js | 0 4 files changed, 2 insertions(+) create mode 100644 src/commandFilter.js create mode 100644 src/commandFilter.test.js diff --git a/src/bot.js b/src/bot.js index fefcb44..d2eb73f 100644 --- a/src/bot.js +++ b/src/bot.js @@ -126,6 +126,7 @@ export default config => (err, sbot) => { const onSbotConnect = (_, keys) => { id = keys.id userStream = sbot.createUserStream({ live: true, id }) + pull(userStream, commandFilter, onSbotCommand) console.log( 'feedMonitor user ID:', id diff --git a/src/bot.test.js b/src/bot.test.js index 2376427..6d691a5 100644 --- a/src/bot.test.js +++ b/src/bot.test.js @@ -402,6 +402,7 @@ test.skip('deny when a non-admin tries to add a feed', async t => { } const unbox = (cypher, cb) => { t.is(cypher, fakePost.content) + t.end() cb(null, cypher.replaceAll(/\*/g, '')) } const createUserStream = ({ live, id }) => { diff --git a/src/commandFilter.js b/src/commandFilter.js new file mode 100644 index 0000000..e69de29 diff --git a/src/commandFilter.test.js b/src/commandFilter.test.js new file mode 100644 index 0000000..e69de29 From 0f973d41257d698209a160a8617786d932b7a16b Mon Sep 17 00:00:00 2001 From: Walker Date: Wed, 17 Apr 2019 21:11:38 -0300 Subject: [PATCH 11/23] feat: add commandFilter --- src/commandFilter.js | 18 ++++++++++++++++++ src/commandFilter.test.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/commandFilter.js b/src/commandFilter.js index e69de29..7652c2d 100644 --- a/src/commandFilter.js +++ b/src/commandFilter.js @@ -0,0 +1,18 @@ +export const commands = [ + 'add', + 'delete', + 'remove' +] + +function toRegex(commands) { + return commands.join('|') +} + +export default function commandFilter(data) { + const regex = new RegExp(toRegex(commands)) + return ( + data && + data.content && + data.content.match(regex) + ) +} \ No newline at end of file diff --git a/src/commandFilter.test.js b/src/commandFilter.test.js index e69de29..233cb34 100644 --- a/src/commandFilter.test.js +++ b/src/commandFilter.test.js @@ -0,0 +1,34 @@ +import test from "ava" +import pull from 'pull-stream' +import commandFilter from './commandFilter' + +function doCommandTest(content, result, t) { + return new Promise((resolve) => { + const mock = { content } + const onResult = (e, res) => { + t.is(result, res.length) + resolve(); + } + pull( + pull.values([mock]), + pull.filter(commandFilter), + pull.collect(onResult) + ) + }); +} + +test('commandFilter ignore no related msgs', (t) => { + return doCommandTest('foo bar', 0, t) +}) + +test('commandFilter filter valid add', (t) => { + return doCommandTest('add http://foobar', 1, t) +}) + +test('commandFilter filter valid delete', (t) => { + return doCommandTest('delete http://foobar', 1, t) +}) + +test('commandFilter filter valid remove', (t) => { + return doCommandTest('remove http://foobar', 1, t) +}) From 97b433d442bd84935aacbcf70f53e8ac5ae6a2ba Mon Sep 17 00:00:00 2001 From: Walker Date: Wed, 17 Apr 2019 21:19:18 -0300 Subject: [PATCH 12/23] fix: fix filter call --- src/bot.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bot.js b/src/bot.js index d2eb73f..c85c10a 100644 --- a/src/bot.js +++ b/src/bot.js @@ -126,7 +126,11 @@ export default config => (err, sbot) => { const onSbotConnect = (_, keys) => { id = keys.id userStream = sbot.createUserStream({ live: true, id }) - pull(userStream, commandFilter, onSbotCommand) + pull( + userStream, + pull.filter(commandFilter), + onSbotCommand + ) console.log( 'feedMonitor user ID:', id From c897d66d4904ecebbfdc5733fc84b5268ea39790 Mon Sep 17 00:00:00 2001 From: Walker Date: Wed, 17 Apr 2019 21:20:12 -0300 Subject: [PATCH 13/23] fix: fix undefined --- src/bot.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bot.js b/src/bot.js index c85c10a..24702c4 100644 --- a/src/bot.js +++ b/src/bot.js @@ -3,6 +3,7 @@ import striptags from 'striptags' import pull from 'pull-stream' import toPull from 'stream-to-pull-stream' import request from 'request' +import commandFilter from './commandFilter' function setCallbackTimeout(cb, onTimeout, waitingTime = 5000) { const checker = setTimeout(onTimeout, waitingTime) From dc2711ed20f18ad890eb9baf419153b93da8cebb Mon Sep 17 00:00:00 2001 From: Walker Date: Wed, 17 Apr 2019 21:24:22 -0300 Subject: [PATCH 14/23] feat: add onSbotCommand --- src/bot.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bot.js b/src/bot.js index 24702c4..3c66824 100644 --- a/src/bot.js +++ b/src/bot.js @@ -124,13 +124,17 @@ export default config => (err, sbot) => { ) } + const onSbotCommand = (data) => { + return true + } + const onSbotConnect = (_, keys) => { id = keys.id userStream = sbot.createUserStream({ live: true, id }) pull( userStream, pull.filter(commandFilter), - onSbotCommand + pull.take(onSbotCommand) ) console.log( 'feedMonitor user ID:', From c8a11094dff234e2bd2be91ec4156f5f1918d0d8 Mon Sep 17 00:00:00 2001 From: Walker Date: Wed, 17 Apr 2019 21:37:30 -0300 Subject: [PATCH 15/23] feat: add decodePrivate --- src/bot.js | 2 ++ src/decodePrivate.js | 0 src/decodePrivate.test.js | 0 3 files changed, 2 insertions(+) create mode 100644 src/decodePrivate.js create mode 100644 src/decodePrivate.test.js diff --git a/src/bot.js b/src/bot.js index 3c66824..ca01e3d 100644 --- a/src/bot.js +++ b/src/bot.js @@ -4,6 +4,7 @@ import pull from 'pull-stream' import toPull from 'stream-to-pull-stream' import request from 'request' import commandFilter from './commandFilter' +import decodePrivate from './decodePrivate' function setCallbackTimeout(cb, onTimeout, waitingTime = 5000) { const checker = setTimeout(onTimeout, waitingTime) @@ -133,6 +134,7 @@ export default config => (err, sbot) => { userStream = sbot.createUserStream({ live: true, id }) pull( userStream, + pull.mapAsync(decodePrivate), pull.filter(commandFilter), pull.take(onSbotCommand) ) diff --git a/src/decodePrivate.js b/src/decodePrivate.js new file mode 100644 index 0000000..e69de29 diff --git a/src/decodePrivate.test.js b/src/decodePrivate.test.js new file mode 100644 index 0000000..e69de29 From ec2947cf8971df60d50c0bf34847b6260811c35c Mon Sep 17 00:00:00 2001 From: Walker Date: Wed, 17 Apr 2019 21:43:06 -0300 Subject: [PATCH 16/23] feat: add decodePrivate test --- src/decodePrivate.js | 3 +++ src/decodePrivate.test.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/decodePrivate.js b/src/decodePrivate.js index e69de29..ae17958 100644 --- a/src/decodePrivate.js +++ b/src/decodePrivate.js @@ -0,0 +1,3 @@ +export default function (data, cb) { + cb(null, data) +} \ No newline at end of file diff --git a/src/decodePrivate.test.js b/src/decodePrivate.test.js index e69de29..81b94d3 100644 --- a/src/decodePrivate.test.js +++ b/src/decodePrivate.test.js @@ -0,0 +1,16 @@ +import test from "ava" +import decodePrivate from './decodePrivate.js' + +test('ignore not encrypted msgs', (t) => { + const data = { + content: {} + } + return new Promise((resolve) => { + const done = (err, d) => { + t.is(null, err) + t.is(data, d) + resolve(); + } + decodePrivate(data, done) + }); +}) \ No newline at end of file From 302937d808732073cfd109a1404ca75d5e8a5325 Mon Sep 17 00:00:00 2001 From: Walker Date: Wed, 17 Apr 2019 21:44:21 -0300 Subject: [PATCH 17/23] fix: fix decodePrivate fn --- src/decodePrivate.js | 2 +- src/decodePrivate.test.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/decodePrivate.js b/src/decodePrivate.js index ae17958..8dd2bd4 100644 --- a/src/decodePrivate.js +++ b/src/decodePrivate.js @@ -1,3 +1,3 @@ -export default function (data, cb) { +export default (sbot) => (data, cb) => { cb(null, data) } \ No newline at end of file diff --git a/src/decodePrivate.test.js b/src/decodePrivate.test.js index 81b94d3..efae2a4 100644 --- a/src/decodePrivate.test.js +++ b/src/decodePrivate.test.js @@ -11,6 +11,7 @@ test('ignore not encrypted msgs', (t) => { t.is(data, d) resolve(); } - decodePrivate(data, done) + const sbot = {} + decodePrivate(sbot)(data, done) }); }) \ No newline at end of file From e35f62c2aa98556fcb497010b1ebdf602c8629d0 Mon Sep 17 00:00:00 2001 From: Walker Date: Wed, 17 Apr 2019 21:44:36 -0300 Subject: [PATCH 18/23] fix: fix decodePrivate --- src/bot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bot.js b/src/bot.js index ca01e3d..94cd7b8 100644 --- a/src/bot.js +++ b/src/bot.js @@ -134,7 +134,7 @@ export default config => (err, sbot) => { userStream = sbot.createUserStream({ live: true, id }) pull( userStream, - pull.mapAsync(decodePrivate), + pull.mapAsync(decodePrivate(sbot)), pull.filter(commandFilter), pull.take(onSbotCommand) ) From 17f2650f930623ae0663d7b5870ae3e8c44bb64d Mon Sep 17 00:00:00 2001 From: Walker Date: Wed, 17 Apr 2019 21:52:20 -0300 Subject: [PATCH 19/23] test: add decodePrivate test --- src/decodePrivate.test.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/decodePrivate.test.js b/src/decodePrivate.test.js index efae2a4..d9fe251 100644 --- a/src/decodePrivate.test.js +++ b/src/decodePrivate.test.js @@ -1,6 +1,10 @@ import test from "ava" import decodePrivate from './decodePrivate.js' +function unecrypt(data) { + return data.replace(/\*/g, '') +} + test('ignore not encrypted msgs', (t) => { const data = { content: {} @@ -14,4 +18,28 @@ test('ignore not encrypted msgs', (t) => { const sbot = {} decodePrivate(sbot)(data, done) }); +}) + +test('decode encrypted msgs', (t) => { + t.plan(3) + const data = { + content: "e*n*cry**p*t*e*dmsg" + } + const sbot = { + unbox(cypher, cb) { + t.is(cypher, data.content) + cb(null, unecrypt(cypher)) + } + } + return new Promise((resolve) => { + const done = (err, d) => { + t.is(err, null) + t.is( + d.content.text, + unecrypt(data.content) + ) + resolve() + } + decodePrivate(sbot)(data, done) + }); }) \ No newline at end of file From 1cfa5fef5af78ae70528098dcd107095983639bd Mon Sep 17 00:00:00 2001 From: Walker Date: Wed, 17 Apr 2019 22:07:47 -0300 Subject: [PATCH 20/23] feat: finish decodePrivate --- src/decodePrivate.js | 14 +++++++++++++- src/decodePrivate.test.js | 6 +++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/decodePrivate.js b/src/decodePrivate.js index 8dd2bd4..ba944ec 100644 --- a/src/decodePrivate.js +++ b/src/decodePrivate.js @@ -1,3 +1,15 @@ export default (sbot) => (data, cb) => { - cb(null, data) + if (typeof data.content === 'string') { + sbot.unbox(data.content, (err, unboxed) => { + cb( + err, + { + ...data, + content: unboxed + } + ) + }) + } else { + cb(null, data) + } } \ No newline at end of file diff --git a/src/decodePrivate.test.js b/src/decodePrivate.test.js index d9fe251..d467b3f 100644 --- a/src/decodePrivate.test.js +++ b/src/decodePrivate.test.js @@ -1,7 +1,7 @@ import test from "ava" import decodePrivate from './decodePrivate.js' -function unecrypt(data) { +function uncrypt(data) { return data.replace(/\*/g, '') } @@ -28,7 +28,7 @@ test('decode encrypted msgs', (t) => { const sbot = { unbox(cypher, cb) { t.is(cypher, data.content) - cb(null, unecrypt(cypher)) + cb(null, { text: uncrypt(cypher) }) } } return new Promise((resolve) => { @@ -36,7 +36,7 @@ test('decode encrypted msgs', (t) => { t.is(err, null) t.is( d.content.text, - unecrypt(data.content) + uncrypt(data.content) ) resolve() } From 74ad69d586c759c1d0cb081baa128e310c9ca10d Mon Sep 17 00:00:00 2001 From: Walker Date: Wed, 17 Apr 2019 22:09:59 -0300 Subject: [PATCH 21/23] fix: fix async fn --- src/bot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bot.js b/src/bot.js index 94cd7b8..00d8b2f 100644 --- a/src/bot.js +++ b/src/bot.js @@ -134,7 +134,7 @@ export default config => (err, sbot) => { userStream = sbot.createUserStream({ live: true, id }) pull( userStream, - pull.mapAsync(decodePrivate(sbot)), + pull.asyncMap(decodePrivate(sbot)), pull.filter(commandFilter), pull.take(onSbotCommand) ) From 1b7d340c14df36e4ccc83bdf06d61a044900305a Mon Sep 17 00:00:00 2001 From: Walker Date: Sat, 14 Aug 2021 16:14:29 -0300 Subject: [PATCH 22/23] test: upgrade to ava async fn --- src/bot.test.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/bot.test.js b/src/bot.test.js index 6d691a5..3591d09 100644 --- a/src/bot.test.js +++ b/src/bot.test.js @@ -395,11 +395,6 @@ test.skip('deny when a non-admin tries to add a feed', async t => { key: '%someKey', content: 'Pl**eas****e add feed ht****t***ps*:**/**/*ww*w.feedfo***ral***l.com/samp****le.*xml' } - const publish = (post) => { - t.is(post.type, 'post') - t.is(post.text, 'Sorry, you\'re not allowed to do this') - t.end() - } const unbox = (cypher, cb) => { t.is(cypher, fakePost.content) t.end() @@ -411,7 +406,6 @@ test.skip('deny when a non-admin tries to add a feed', async t => { return pull.values([fakePost]) } const whoami = cb => cb(null, { id: fakeId }) - const sbot = { publish, unbox, createUserStream, whoami } const feedMonitor = { create() { }, destroy() { }, @@ -420,5 +414,13 @@ test.skip('deny when a non-admin tries to add a feed', async t => { feedMonitor, feedUrls: [], } - bot(config)(null, sbot) + return new Promise((resolve) => { + const publish = (post) => { + t.is(post.type, 'post') + t.is(post.text, 'Sorry, you\'re not allowed to do this') + resolve(); + } + const sbot = { publish, unbox, createUserStream, whoami } + bot(config)(null, sbot) + }); }) \ No newline at end of file From a69c3c9572f1e4cebe6f99e1723ef4b539332758 Mon Sep 17 00:00:00 2001 From: Walker Date: Sat, 14 Aug 2021 16:20:28 -0300 Subject: [PATCH 23/23] test: fix resolve place --- src/bot.test.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/bot.test.js b/src/bot.test.js index 3591d09..290a17b 100644 --- a/src/bot.test.js +++ b/src/bot.test.js @@ -395,11 +395,6 @@ test.skip('deny when a non-admin tries to add a feed', async t => { key: '%someKey', content: 'Pl**eas****e add feed ht****t***ps*:**/**/*ww*w.feedfo***ral***l.com/samp****le.*xml' } - const unbox = (cypher, cb) => { - t.is(cypher, fakePost.content) - t.end() - cb(null, cypher.replaceAll(/\*/g, '')) - } const createUserStream = ({ live, id }) => { t.is(live, true) t.is(id, fakeId) @@ -414,11 +409,15 @@ test.skip('deny when a non-admin tries to add a feed', async t => { feedMonitor, feedUrls: [], } + const publish = (post) => { + t.is(post.type, 'post') + t.is(post.text, 'Sorry, you\'re not allowed to do this') + } return new Promise((resolve) => { - const publish = (post) => { - t.is(post.type, 'post') - t.is(post.text, 'Sorry, you\'re not allowed to do this') + const unbox = (cypher, cb) => { + t.is(cypher, fakePost.content) resolve(); + cb(null, cypher.replaceAll(/\*/g, '')) } const sbot = { publish, unbox, createUserStream, whoami } bot(config)(null, sbot)