Skip to content

Commit

Permalink
Don't hook tribes.publish, it can't publish public anyway
Browse files Browse the repository at this point in the history
  • Loading branch information
Powersource committed Nov 24, 2023
1 parent 957fed3 commit a1cc675
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 36 deletions.
11 changes: 0 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,6 @@ module.exports = {
}
}

if (ssb.tribes && ssb.tribes.publish) {
ssb.tribes.publish.hook(publishHook(true))

ssb.tribes.publish.hook = () => {
throw new Error('ssb-recps-guard must be the last to hook ssb.tribes.publish')
// NOTE because of the last hook get run first we need to guarentee
// that no other hooks on publish occured after our, otherwise we cannot
// guarentee other hooks do not bypass the guard
}
}

if (ssb.db && ssb.db.create) {
ssb.db.create.hook((create, args) => {
const [input, cb] = args
Expand Down
26 changes: 1 addition & 25 deletions test/db2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test('db2', async t => {
await p(server.tribes.publish)(content)
.then(msg => t.error(msg, "shouldn't get msg on err"))
.catch((err) => {
t.match(err.message, /recps-guard: public messages of type "profile" not allowed/, 'public blocked')
t.match(err.message, /tribes.publish requires content.recps/, "tribes.publish can't publish public at all")
})

content = { type: 'profile', recps: [server.id] }
Expand All @@ -26,13 +26,6 @@ test('db2', async t => {
.catch(err => {
t.error(err, 'msgs with recps allowed')
})
await p(server.tribes.publish)(content)
.then(data => {
t.equal(typeof data.value.content, 'string', '(msg content encrypted)')
})
.catch(err => {
t.error(err, 'msgs with recps allowed')
})

content = { type: 'profile', name: 'mix' }
await p(server.db.create)({ content, options: { allowPublic: true } })
Expand All @@ -42,13 +35,6 @@ test('db2', async t => {
.catch(err => {
t.error(err, 'msgs { content, options: { allowPublic: true } allowed. db.create')
})
await p(server.tribes.publish)({ content, options: { allowPublic: true } })
.then(data => {
t.deepEqual(data.value.content, content, '(msg content unencrypted, allowPublic pruned). tribes.publish')
})
.catch(err => {
t.error(err, 'msgs { content, options: { allowPublic: true } allowed. tribes.publish')
})

const weird = {
content: { type: 'profile', recps: [server.id] },
Expand All @@ -64,16 +50,6 @@ test('db2', async t => {
'disallow recps AND allowPublic. db.create'
)
})
await p(server.tribes.publish)(weird)
.then(msg => {
t.error(msg, "it's supposed to error. tribes.publish")
}).catch(err => {
t.match(
err.message,
/recps-guard: should not have recps && allowPublic, check your code/,
'disallow recps AND allowPublic. tribes.publish'
)
})

await p(server.close)()
})
Expand Down

0 comments on commit a1cc675

Please sign in to comment.