-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
105 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,54 @@ | ||
module.exports = (server, t, cb) => { | ||
const msg = { type: 'profile' } | ||
server.publish(msg, (err, data) => { | ||
t.match(err.message, /recps-guard: public messages of type "profile" not allowed/, 'public blocked') | ||
|
||
const msg = { type: 'profile', recps: [server.id] } | ||
server.publish(msg, (err, data) => { | ||
t.error(err, 'msgs with recps allowed') | ||
t.equal(typeof data.value.content, 'string', '(msg content encrypted)') | ||
|
||
const msg = Buffer.from('cats are cool').toString('base64') + '.box7' | ||
server.publish(msg, (err, data) => { | ||
t.error(err, 'pre-encrypted content published fine') | ||
t.equal(typeof data.value.content, 'string', '(msg content encrypted)') | ||
|
||
const content = { type: 'profile', name: 'mix' } | ||
server.publish({ content, options: { allowPublic: true } }, (err, data) => { | ||
if (err) return cb(err) | ||
t.error(err, 'msgs { content, options: { allowPublic: true } allowed') | ||
t.deepEqual(data.value.content, content, '(msg content unencrypted, allowPublic pruned)') | ||
|
||
const weird = { | ||
content: { type: 'profile', recps: [server.id] }, | ||
options: { allowPublic: true } | ||
} | ||
server.publish(weird, (err, data) => { | ||
t.match( | ||
err.message, | ||
/recps-guard: should not have recps && allowPublic, check your code/, | ||
'disallow recps AND allowPublic' | ||
) | ||
|
||
cb(null) | ||
}) | ||
}) | ||
}) | ||
const { promisify: p } = require('util') | ||
|
||
module.exports = async (server, t, cb) => { | ||
let description, content, input | ||
|
||
description = 'public blocked' | ||
content = { type: 'profile' } | ||
await p(server.publish)(content) | ||
.then(() => t.fail(description)) | ||
.catch(err => { | ||
t.match(err.message, /recps-guard: public messages of type "profile" not allowed/, description) | ||
}) | ||
}) | ||
|
||
description = 'msgs with recps allowed' | ||
content = { type: 'profile', recps: [server.id] } | ||
await p(server.publish)(content) | ||
.then(data => t.equal(typeof data.value.content, 'string', description)) | ||
.catch(err => t.error(err, description)) | ||
|
||
description = 'pre-encrypted content published fine' | ||
content = Buffer.from('cats are cool').toString('base64') + '.box7' | ||
await p(server.publish)(content) | ||
.then(data => t.equal(typeof data.value.content, 'string', description)) | ||
.catch(err => t.fail(err, description)) | ||
|
||
description = 'msgs { content, allowPublic: true } allowed' | ||
content = { type: 'profile', name: 'mix' } | ||
input = { content, allowPublic: true } | ||
await p(server.publish)(input) | ||
.then(data => t.deepEqual(data.value.content, content, description)) | ||
.catch(err => t.fail(err, description)) | ||
|
||
description = 'legacy: msgs { content, options: { allowPublic: true } }' | ||
content = { type: 'profile', name: 'mix' } | ||
input = { content, options: { allowPublic: true } } | ||
await p(server.publish)(input) | ||
.then(data => t.deepEqual(data.value.content, content, description)) | ||
.catch(err => t.fail(err, description)) | ||
|
||
description = 'disallow recps AND allowPublic' | ||
input = { | ||
content: { type: 'profile', recps: [server.id] }, | ||
allowPublic: true | ||
} | ||
await p(server.publish)(input) | ||
.then(() => t.fail(description)) | ||
.catch(err => t.match( | ||
err.message, | ||
/recps-guard: should not have recps && allowPublic, check your code/, | ||
'disallow recps AND allowPublic' | ||
)) | ||
|
||
cb(null) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters