feat: add eprt and epsv for IPv6 support
This commit is contained in:
@@ -9,11 +9,11 @@ const FAMILY = {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
directive: 'EPRT',
|
directive: 'EPRT',
|
||||||
handler: function ({command} = {}) {
|
handler: function ({command} = {}) {
|
||||||
this.connector = new ActiveConnector(this);
|
const [, protocol, ip, port] = _.chain(command).get('arg', '').split('|').value();
|
||||||
const [protocol, ip, port] = _.compact(command.arg.split('|'));
|
|
||||||
const family = FAMILY[protocol];
|
const family = FAMILY[protocol];
|
||||||
if (!family) return this.reply(502, 'Unknown network protocol');
|
if (!family) return this.reply(504, 'Unknown network protocol');
|
||||||
|
|
||||||
|
this.connector = new ActiveConnector(this);
|
||||||
return this.connector.setupConnection(ip, port, family)
|
return this.connector.setupConnection(ip, port, family)
|
||||||
.then(() => this.reply(200));
|
.then(() => this.reply(200));
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -36,7 +36,9 @@ const commands = [
|
|||||||
require('./registration/type'),
|
require('./registration/type'),
|
||||||
require('./registration/user'),
|
require('./registration/user'),
|
||||||
require('./registration/pbsz'),
|
require('./registration/pbsz'),
|
||||||
require('./registration/prot')
|
require('./registration/prot'),
|
||||||
|
require('./registration/eprt'),
|
||||||
|
require('./registration/epsv')
|
||||||
];
|
];
|
||||||
|
|
||||||
const registry = commands.reduce((result, cmd) => {
|
const registry = commands.reduce((result, cmd) => {
|
||||||
|
|||||||
60
test/commands/registration/eprt.spec.js
Normal file
60
test/commands/registration/eprt.spec.js
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
const when = require('when');
|
||||||
|
const {expect} = require('chai');
|
||||||
|
const sinon = require('sinon');
|
||||||
|
|
||||||
|
const ActiveConnector = require('../../../src/connector/active');
|
||||||
|
|
||||||
|
const CMD = 'EPRT';
|
||||||
|
describe(CMD, function () {
|
||||||
|
let sandbox;
|
||||||
|
const mockClient = {
|
||||||
|
reply: () => when.resolve()
|
||||||
|
};
|
||||||
|
const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient);
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
sandbox = sinon.sandbox.create();
|
||||||
|
|
||||||
|
sandbox.spy(mockClient, 'reply');
|
||||||
|
sandbox.stub(ActiveConnector.prototype, 'setupConnection').resolves();
|
||||||
|
});
|
||||||
|
afterEach(() => {
|
||||||
|
sandbox.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('// unsuccessful | no argument', () => {
|
||||||
|
return cmdFn()
|
||||||
|
.then(() => {
|
||||||
|
expect(mockClient.reply.args[0][0]).to.equal(504);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('// unsuccessful | invalid argument', () => {
|
||||||
|
return cmdFn({command: {arg: 'blah'}})
|
||||||
|
.then(() => {
|
||||||
|
expect(mockClient.reply.args[0][0]).to.equal(504);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('// successful IPv4', () => {
|
||||||
|
return cmdFn({command: {arg: '|1|192.168.0.100|35286|'}})
|
||||||
|
.then(() => {
|
||||||
|
const [ip, port, family] = ActiveConnector.prototype.setupConnection.args[0];
|
||||||
|
expect(mockClient.reply.args[0][0]).to.equal(200);
|
||||||
|
expect(ip).to.equal('192.168.0.100');
|
||||||
|
expect(port).to.equal('35286');
|
||||||
|
expect(family).to.equal(4);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('// successful IPv6', () => {
|
||||||
|
return cmdFn({command: {arg: '|2|8536:933f:e7f3:3e91:6dc1:e8c6:8482:7b23|35286|'}})
|
||||||
|
.then(() => {
|
||||||
|
const [ip, port, family] = ActiveConnector.prototype.setupConnection.args[0];
|
||||||
|
expect(mockClient.reply.args[0][0]).to.equal(200);
|
||||||
|
expect(ip).to.equal('8536:933f:e7f3:3e91:6dc1:e8c6:8482:7b23');
|
||||||
|
expect(port).to.equal('35286');
|
||||||
|
expect(family).to.equal(6);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
35
test/commands/registration/epsv.spec.js
Normal file
35
test/commands/registration/epsv.spec.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
const when = require('when');
|
||||||
|
const {expect} = require('chai');
|
||||||
|
const sinon = require('sinon');
|
||||||
|
|
||||||
|
const PassiveConnector = require('../../../src/connector/passive');
|
||||||
|
|
||||||
|
const CMD = 'EPSV';
|
||||||
|
describe(CMD, function () {
|
||||||
|
let sandbox;
|
||||||
|
const mockClient = {
|
||||||
|
reply: () => when.resolve()
|
||||||
|
};
|
||||||
|
const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient);
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
sandbox = sinon.sandbox.create();
|
||||||
|
|
||||||
|
sandbox.stub(mockClient, 'reply').resolves();
|
||||||
|
sandbox.stub(PassiveConnector.prototype, 'setupServer').resolves({
|
||||||
|
address: () => ({port: 12345})
|
||||||
|
});
|
||||||
|
});
|
||||||
|
afterEach(() => {
|
||||||
|
sandbox.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('// successful IPv4', () => {
|
||||||
|
return cmdFn()
|
||||||
|
.then(() => {
|
||||||
|
const [code, message] = mockClient.reply.args[0];
|
||||||
|
expect(code).to.equal(229);
|
||||||
|
expect(message).to.equal('EPSV OK (|||12345|)');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user