Files
ftp-server/test/helpers/find-port.spec.js
Tyler Stewart a51678ae70 feat: start pasv port selection from last checked port (#111)
* Update find-port.js

Reuse the Port Number Generator

* feat(passive): initialize port factory in server

Ensures that each passive connection does not have to start from the beginning of the pasv port range

https://github.com/trs/ftp-srv/pull/110

* fix(connector): ensure data socket is destroyed and resolved

If there was a data socket, this would never resolve

* test: use bluebird promises for tests, fix stubs

* fix(commands): ensure connector is ended before resuming
2018-09-02 16:20:48 +00:00

53 lines
1.2 KiB
JavaScript

/* eslint no-unused-expressions: 0 */
const {expect} = require('chai');
const net = require('net');
const sinon = require('sinon');
const {getNextPortFactory} = require('../../src/helpers/find-port');
describe('helpers // find-port', function () {
let sandbox;
let getNextPort;
beforeEach(() => {
sandbox = sinon.sandbox.create().usingPromise(Promise);
getNextPort = getNextPortFactory(1, 2);
});
afterEach(() => {
sandbox.restore();
});
it('finds a port', () => {
sandbox.stub(net.Server.prototype, 'listen').callsFake(function (port) {
this.address = () => ({port});
setImmediate(() => this.emit('listening'));
});
return getNextPort()
.then(port => {
expect(port).to.equal(1);
});
});
it('restarts count', () => {
sandbox.stub(net.Server.prototype, 'listen').callsFake(function (port) {
this.address = () => ({port});
setImmediate(() => this.emit('listening'));
});
return getNextPort()
.then(port => {
expect(port).to.equal(1);
})
.then(() => getNextPort())
.then(port => {
expect(port).to.equal(2);
})
.then(() => getNextPort())
.then(port => {
expect(port).to.equal(1);
});
});
});