-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto encrypted publish when recps is set (#212)
* Add test for auto encrypted publish * Auto encrypt message in publish if recps is set * Fix tests * No need to substr recps * Tidy
- Loading branch information
Showing
4 changed files
with
59 additions
and
19 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const test = require('tape') | ||
const ssbKeys = require('ssb-keys') | ||
const path = require('path') | ||
const rimraf = require('rimraf') | ||
const mkdirp = require('mkdirp') | ||
const SecretStack = require('secret-stack') | ||
const caps = require('ssb-caps') | ||
|
||
const dir = '/tmp/ssb-db2-private' | ||
|
||
rimraf.sync(dir) | ||
mkdirp.sync(dir) | ||
|
||
const keys = ssbKeys.loadOrCreateSync(path.join(dir, 'secret')) | ||
|
||
const sbot = SecretStack({ appKey: caps.shs }).use(require('../')).call(null, { | ||
keys, | ||
path: dir, | ||
}) | ||
const db = sbot.db | ||
|
||
test('publish encrypted message', (t) => { | ||
let content = { type: 'post', text: 'super secret', recps: [keys.id] } | ||
content = ssbKeys.box( | ||
content, | ||
content.recps.map((x) => x.substr(1)) | ||
) | ||
|
||
db.publish(content, (err, privateMsg) => { | ||
t.error(err, 'no err') | ||
|
||
t.equal(typeof privateMsg.value.content, 'string') | ||
db.get(privateMsg.key, (err, msg) => { | ||
t.equal(msg.content.text, 'super secret') | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
|
||
test('publish: auto encrypt message with recps', (t) => { | ||
let content = { type: 'post', text: 'super secret', recps: [keys.id] } | ||
|
||
db.publish(content, (err, privateMsg) => { | ||
t.error(err, 'no err') | ||
|
||
t.equal(typeof privateMsg.value.content, 'string') | ||
db.get(privateMsg.key, (err, msg) => { | ||
t.equal(msg.content.text, 'super secret') | ||
sbot.close(t.end) | ||
}) | ||
}) | ||
}) |