Comparing version 1.4.0 to 1.5.0
28
index.js
@@ -6,3 +6,4 @@ 'use strict'; | ||
childProcess = require('child_process'), | ||
util = require('util'); | ||
util = require('util'), | ||
EventEmitter = require('events').EventEmitter; | ||
@@ -15,3 +16,3 @@ var DEFAULTS = { | ||
var Tunnel = inherit({ | ||
var Tunnel = inherit(EventEmitter, { | ||
/** | ||
@@ -29,2 +30,4 @@ * Constuctor | ||
__constructor: function (opts) { | ||
EventEmitter.call(this); | ||
this.host = opts.host; | ||
@@ -54,4 +57,9 @@ this.port = this._generateRandomPort(opts.ports); | ||
var cleanup = function () { | ||
_this._tunnel.stderr.removeAllListeners('data'); | ||
}; | ||
this._tunnel.stderr.on('data', function (data) { | ||
if (/success/.test(data)) { | ||
cleanup(); | ||
return _this._resolveTunnel(); | ||
@@ -61,17 +69,13 @@ } | ||
if (/failed/.test(data)) { | ||
if (_this._tunnelDeferred.promise.isFulfilled()) { | ||
return; | ||
} | ||
cleanup(); | ||
return _this._rejectTunnel(); | ||
} | ||
}); | ||
if (/killed/i.test(data)) { | ||
var msg = data.toString().toLowerCase(); | ||
var killMsg = msg.slice(msg.indexOf('killed')).trim(); | ||
console.info('INFO: Tunnel is ' + killMsg); | ||
} | ||
this._tunnel.on('exit', function (code, signal) { | ||
_this.emit('exit', code, signal); | ||
}); | ||
this._tunnel.on('close', function (code) { | ||
this._tunnel.on('close', function (code, signal) { | ||
_this.emit('close', code, signal); | ||
return _this._closeTunnel(code); | ||
@@ -78,0 +82,0 @@ }); |
{ | ||
"name": "ssh-tun", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "Module for establishing ssh tunnel", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -164,22 +164,2 @@ var Tunnel = require('../'), | ||
it('should log a kill signal with which the tunnel is closed', function () { | ||
tunnel = createTunnel(); | ||
tunnel.open(); | ||
ssh.stderr.emit('data', 'channel 0: \nKilled BY signal 2'); | ||
expect(console.info.secondCall.args[0]) | ||
.to.be.equal('INFO: Tunnel is killed by signal 2'); | ||
}); | ||
it('should not log a kill signal if tunnel is closed successfully', function () { | ||
tunnel = createTunnel(); | ||
tunnel.open(); | ||
ssh.stderr.emit('data', 'Exit status 0'); | ||
expect(console.info).to.be.calledOnce; | ||
expect(console.info.firstCall.args[0]).to.not.match(/INFO: Tunnel is killed/); | ||
}); | ||
it('should reject tunnel opening if error occured', function () { | ||
@@ -249,2 +229,24 @@ tunnel = createTunnel(); | ||
}); | ||
it('should emit close event', function () { | ||
tunnel = createTunnel(); | ||
tunnel.open(); | ||
var closeHandler = sandbox.stub(); | ||
tunnel.on('close', closeHandler); | ||
ssh.emit('close', null, 'SIGKILL'); | ||
return expect(closeHandler).to.be.calledWith(null, 'SIGKILL'); | ||
}); | ||
it('should emit exit event', function () { | ||
tunnel = createTunnel(); | ||
tunnel.open(); | ||
var exitHandler = sandbox.stub(); | ||
tunnel.on('exit', exitHandler); | ||
ssh.emit('exit', 0, null); | ||
return expect(exitHandler).to.be.calledWith(0, null); | ||
}); | ||
}); | ||
@@ -251,0 +253,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
381
19116