Skip to content

Commit f92026d

Browse files
committed
tests passing, slowly
why the need to break into chunks? i can encrypt large pieces in my integration test.
1 parent d410ba2 commit f92026d

File tree

2 files changed

+59
-46
lines changed

2 files changed

+59
-46
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"watch": "runwatch \"**/*.js\" -r \"npm test\""
88
},
99
"devDependencies": {
10+
"concat-stream": "^1.5.2",
1011
"runwatch": "^0.1.3",
1112
"tape": "^4.5.1"
1213
},

test/index.js

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,76 @@
11
var signalstream = require('..')
2-
var helpers = require('./helpers')
2+
var bobAliceSessionCiphers = require('./helpers')
33
var signal = require('signal-protocol')
44
var read = require('fs').createReadStream
55
var through = require('through2')
6+
var test = require('tape')
67

78
var l = require('../src/helpers')
89

9-
var ALICE_ADDRESS = new signal.SignalProtocolAddress("+14151111111", 1);
10-
var BOB_ADDRESS = new signal.SignalProtocolAddress("+14152222222", 1);
11-
12-
var aliceStore = new helpers.SignalStore();
13-
var bobStore = new helpers.SignalStore();
14-
15-
var bobPreKeyId = 1337;
16-
var bobSignedKeyId = 1;
17-
18-
Promise.all([
19-
helpers.generateIdentity(aliceStore),
20-
helpers.generateIdentity(bobStore),
21-
]).then(function() {
22-
return helpers.generatePreKeyBundle(bobStore, bobPreKeyId, bobSignedKeyId);
23-
}).then(function(preKeyBundle) {
24-
var builder = new signal.SessionBuilder(aliceStore, BOB_ADDRESS);
25-
return builder.processPreKey(preKeyBundle)
26-
}).then(function () {
27-
var aliceSessionCipher = new signal.SessionCipher(aliceStore, BOB_ADDRESS);
28-
var bobSessionCipher = new signal.SessionCipher(bobStore, ALICE_ADDRESS);
29-
return [ aliceSessionCipher, bobSessionCipher ]
30-
}).then(echo, log)
31-
3210
function log (note) {
3311
return function (x) {
3412
console.log(note, x)
3513
return x
3614
}
3715
}
3816

39-
// // // the world's slowest impl of `echo`
40-
function echo ([aliceCipher, bobCipher]) {
17+
function roundTripEcho (path, cb) {
4118

42-
let alice = require('..')(aliceCipher)
43-
let bob = require('..')(bobCipher)
19+
bobAliceSessionCiphers()
20+
.then(echo, log('ERR'))
4421

45-
console.log('starting')
22+
// // // the world's slowest impl of `echo`
23+
function echo ([aliceCipher, bobCipher]) {
24+
let alice = require('..')(aliceCipher)
25+
let bob = require('..')(bobCipher)
26+
let concat = require('concat-stream')
27+
read(path)
28+
.pipe(through(function (buf, enc, next) {
29+
let amt = 239
30+
for (let i=0; i<buf.length; i+=amt)
31+
this.push(buf.slice(i, i+amt))
32+
next()
33+
}))
34+
.pipe(alice.encrypt)
35+
.pipe(bob.decrypt)
36+
.pipe(bob.encrypt)
37+
.pipe(alice.decrypt)
38+
.pipe(through.obj((buff, enc, next) => {
39+
let b = new Buffer(buff, enc)
40+
next(null, b)
41+
}))
42+
.pipe(concat(cb))
43+
// .on('data', d => console.log(d))
44+
.on('error', err => console.log('err', err))
45+
}
46+
}
4647

47-
read(__dirname + '/story.txt')//, 'utf-8')
48-
.pipe(through(function (buf, enc, next) {
49-
let amt = 200
50-
for (let i=0; i<buf.length; i+=amt)
51-
this.push(buf.slice(i, i+amt))
52-
next()
53-
}))
54-
.pipe(alice.encrypt)
55-
.pipe(bob.decrypt)
56-
.pipe(bob.encrypt)
57-
.pipe(alice.decrypt)
58-
.on('data', d => {
59-
let pt = new Buffer.from(d).toString('utf-8')
60-
console.log(pt)
61-
})
48+
// test('can echo a short textfile from alice to bob to alice again', t => {
49+
// let filepath = __dirname + '/story.txt'
50+
// roundTripEcho(filepath, buff => {
51+
// let trueBuff = require('fs').readFileSync(filepath)
52+
// t.deepEqual(buff, trueBuff,
53+
// 'textfile buffer after round trip encrypt/decrypt/encrypt/decrypt identical to original buffer')
54+
// t.end()
55+
// })
56+
// })
6257

63-
.on('error', err => console.log('err', err))
64-
}
58+
// test('can echo long short textfile from alice to bob to alice again', t => {
59+
// let filepath = __dirname + '/story2.txt'
60+
// roundTripEcho(filepath, buff => {
61+
// let trueBuff = require('fs').readFileSync(filepath)
62+
// t.deepEqual(buff, trueBuff,
63+
// 'long textfile buffer perserved after roundtrip')
64+
// t.end()
65+
// })
66+
// })
67+
68+
test('can echo an image file', t => {
69+
let filepath = __dirname + '/oakland-bridge.jpg'
70+
roundTripEcho(filepath, buff => {
71+
let trueBuff = require('fs').readFileSync(filepath)
72+
t.deepEqual(buff, trueBuff,
73+
'long textfile buffer perserved after roundtrip')
74+
t.end()
75+
})
76+
})

0 commit comments

Comments
 (0)