Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Merge pull request #271 from bookchin/master
Browse files Browse the repository at this point in the history
v2.0.4
  • Loading branch information
bookchin committed Jul 22, 2016
2 parents 32bfad2 + 17dcb89 commit 6b4fd35
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/tunnel/server.js
Expand Up @@ -268,6 +268,10 @@ TunnelServer.prototype._handleClient = function(client) {
client.close(400, { error: err.message });
})
.on('data', function(data) {
if (ws.OPEN !== client.readyState) {
return cleanup();
}

client.send(data, { binary: true });
})
.source(gateway);
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "storj",
"version": "2.0.3",
"version": "2.0.4",
"description": "implementation of the storj protocol for node.js and the browser",
"main": "index.js",
"directories": {
Expand Down
24 changes: 24 additions & 0 deletions test/tunnel/server.unit.js
Expand Up @@ -222,6 +222,30 @@ describe('TunnelServer', function() {
badDemuxer.emit('data', { type: 'invalid' });
});

it('should cleanup on muxer data if the client is closed', function(done) {
var muxer = new EventEmitter();
muxer.source = sinon.stub();
var client = new EventEmitter();
client.upgradeReq = { url: 'ws://127.0.0.1:1337/tun?token=sometoken' };
client.readyState = 0;
var MuxerStubTunServer = proxyquire('../../lib/tunnel/server', {
'./multiplexer': function() {
return muxer;
}
});
var ts = new MuxerStubTunServer({ server: http.Server() });
ts._gateways.sometoken = new EventEmitter();
ts._gateways.sometoken.close = sinon.stub();
ts._handleClient(client);
setImmediate(function() {
muxer.emit('data', {});
setImmediate(function() {
expect(ts._gateways.sometoken.close.called).to.equal(true);
done();
});
});
});

});

describe('#_getAvailablePort', function() {
Expand Down

0 comments on commit 6b4fd35

Please sign in to comment.