From 0e23874730f790368f103f3133b24763968d7eef Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Wed, 28 Mar 2018 20:42:28 +0200 Subject: [PATCH] test: add test for handshake to expose error bubbling issue --- test/secio.spec.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/secio.spec.js b/test/secio.spec.js index 8f22aa7..b499730 100644 --- a/test/secio.spec.js +++ b/test/secio.spec.js @@ -18,6 +18,8 @@ const Listener = ms.Listener const Dialer = ms.Dialer const secio = require('../src') +const State = require('../src/state') +const handshake = require('../src/handshake') describe('secio', () => { let peerA @@ -144,4 +146,30 @@ describe('secio', () => { secio.encrypt(peerA, new Connection(p[0]), peerC, check) secio.encrypt(peerB, new Connection(p[1]), peerA, check) }) + + it('bubbles errors from handshake failures properly', (done) => { + const p = pair() + const timeout = 60 * 1000 * 5 + const stateA = new State(peerA, peerC, timeout, () => { }) + const stateB = new State(peerB, peerA, timeout, () => { }) + const connA = new Connection(p[0]) + const connB = new Connection(p[1]) + + function finish (err) { + expect(err).to.exist() + done() + } + + pull( + connA, + handshake(stateA, finish), + connA + ) + + pull( + connB, + handshake(stateB, finish), + connB + ) + }) })