-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add eprt and epsv for IPv6 support
- Loading branch information
Showing
4 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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|)'); | ||
}); | ||
}); | ||
}); |