Skip to content

Commit

Permalink
Merge pull request #26 from trs/test-updates
Browse files Browse the repository at this point in the history
Test updates
  • Loading branch information
trs authored Jun 16, 2017
2 parents 3c533a5 + 9be8ffa commit 63777c0
Show file tree
Hide file tree
Showing 39 changed files with 585 additions and 563 deletions.
3 changes: 2 additions & 1 deletion src/connector/passive.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class Passive extends Connector {
this.server.options.pasv_range.split('-').map(v => v ? parseInt(v) : v) :
[this.server.options.pasv_range];
return findPort(min, max);
} else return undefined;
}
throw new errors.ConnectorError('Invalid pasv_range');
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class FtpServer {

setupTLS(_tls) {
if (!tls) return false;
return _.assign(_tls, {
return _.assign({}, _tls, {
cert: _tls.cert ? fs.readFileSync(_tls.cert) : undefined,
key: _tls.key ? fs.readFileSync(_tls.key) : undefined,
ca: _tls.ca ? Array.isArray(_tls.ca) ? _tls.ca.map(_ca => fs.readFileSync(_ca)) : [fs.readFileSync(_tls.ca)] : undefined
Expand Down
16 changes: 6 additions & 10 deletions test/commands/registration/abor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,25 @@ describe(CMD, function () {
sandbox.restore();
});

it('// successful | no active connection', done => {
it('// successful | no active connection', () => {
mockClient.connector.waitForConnection.restore();
sandbox.stub(mockClient.connector, 'waitForConnection').rejects();

cmdFn()
return cmdFn()
.then(() => {
expect(mockClient.connector.waitForConnection.callCount).to.equal(1);
expect(mockClient.connector.end.callCount).to.equal(0);
expect(mockClient.reply.args[0][0]).to.equal(226);
done();
})
.catch(done);
});
});

it('// successful | active connection', done => {
cmdFn()
it('// successful | active connection', () => {
return cmdFn()
.then(() => {
expect(mockClient.connector.waitForConnection.callCount).to.equal(1);
expect(mockClient.connector.end.callCount).to.equal(1);
expect(mockClient.reply.args[0][0]).to.equal(426);
expect(mockClient.reply.args[1][0]).to.equal(226);
done();
})
.catch(done);
});
});
});
8 changes: 3 additions & 5 deletions test/commands/registration/allo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ describe(CMD, function () {
sandbox.restore();
});

it('// successful', done => {
cmdFn()
it('// successful', () => {
return cmdFn()
.then(() => {
expect(mockClient.reply.args[0][0]).to.equal(202);
done();
})
.catch(done);
});
});
});
24 changes: 9 additions & 15 deletions test/commands/registration/auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,25 @@ describe(CMD, function () {
sandbox.restore();
});

it('TLS // supported', done => {
cmdFn({command: { arg: 'TLS', directive: CMD}})
it('TLS // supported', () => {
return cmdFn({command: { arg: 'TLS', directive: CMD}})
.then(() => {
expect(mockClient.reply.args[0][0]).to.equal(234);
expect(mockClient.secure).to.equal(true);
done();
})
.catch(done);
});
});

it('SSL // not supported', done => {
cmdFn({command: { arg: 'SSL', directive: CMD}})
it('SSL // not supported', () => {
return cmdFn({command: { arg: 'SSL', directive: CMD}})
.then(() => {
expect(mockClient.reply.args[0][0]).to.equal(504);
done();
})
.catch(done);
});
});

it('bad // bad', done => {
cmdFn({command: { arg: 'bad', directive: CMD}})
it('bad // bad', () => {
return cmdFn({command: { arg: 'bad', directive: CMD}})
.then(() => {
expect(mockClient.reply.args[0][0]).to.equal(504);
done();
})
.catch(done);
});
});
});
8 changes: 3 additions & 5 deletions test/commands/registration/cdup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ describe(CMD, function () {
sandbox.restore();
});

it('.. // successful', done => {
cmdFn({log, command: {directive: CMD}})
it('.. // successful', () => {
return cmdFn({log, command: {directive: CMD}})
.then(() => {
expect(mockClient.reply.args[0][0]).to.equal(250);
expect(mockClient.fs.chdir.args[0][0]).to.equal('..');
done();
})
.catch(done);
});
});
});
43 changes: 18 additions & 25 deletions test/commands/registration/cwd.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,63 +23,56 @@ describe(CMD, function () {
});

describe('// check', function () {
it('fails on no fs', done => {
it('fails on no fs', () => {
const badMockClient = { reply: () => {} };
const badCmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient);
sandbox.stub(badMockClient, 'reply').resolves();
badCmdFn()

return badCmdFn()
.then(() => {
expect(badMockClient.reply.args[0][0]).to.equal(550);
done();
})
.catch(done);
});
});

it('fails on no fs chdir command', done => {
it('fails on no fs chdir command', () => {
const badMockClient = { reply: () => {}, fs: {} };
const badCmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient);
sandbox.stub(badMockClient, 'reply').resolves();
badCmdFn()

return badCmdFn()
.then(() => {
expect(badMockClient.reply.args[0][0]).to.equal(402);
done();
})
.catch(done);
});
});
});

it('test // successful', done => {
cmdFn({log, command: { arg: 'test', directive: CMD}})
it('test // successful', () => {
return cmdFn({log, command: { arg: 'test', directive: CMD}})
.then(() => {
expect(mockClient.reply.args[0][0]).to.equal(250);
expect(mockClient.fs.chdir.args[0][0]).to.equal('test');
done();
})
.catch(done);
});
});

it('test // successful', done => {
it('test // successful', () => {
mockClient.fs.chdir.restore();
sandbox.stub(mockClient.fs, 'chdir').resolves('/test');
cmdFn({log, command: { arg: 'test', directive: CMD}})

return cmdFn({log, command: { arg: 'test', directive: CMD}})
.then(() => {
expect(mockClient.reply.args[0][0]).to.equal(250);
expect(mockClient.fs.chdir.args[0][0]).to.equal('test');
done();
})
.catch(done);
});
});

it('bad // unsuccessful', done => {
it('bad // unsuccessful', () => {
mockClient.fs.chdir.restore();
sandbox.stub(mockClient.fs, 'chdir').rejects(new Error('Bad'));

cmdFn({log, command: { arg: 'bad', directive: CMD}})
return cmdFn({log, command: { arg: 'bad', directive: CMD}})
.then(() => {
expect(mockClient.reply.args[0][0]).to.equal(550);
expect(mockClient.fs.chdir.args[0][0]).to.equal('bad');
done();
})
.catch(done);
});
});
});
34 changes: 14 additions & 20 deletions test/commands/registration/dele.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,45 @@ describe(CMD, function () {
});

describe('// check', function () {
it('fails on no fs', done => {
it('fails on no fs', () => {
const badMockClient = { reply: () => {} };
const badCmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient);
sandbox.stub(badMockClient, 'reply').resolves();
badCmdFn()

return badCmdFn()
.then(() => {
expect(badMockClient.reply.args[0][0]).to.equal(550);
done();
})
.catch(done);
});
});

it('fails on no fs delete command', done => {
it('fails on no fs delete command', () => {
const badMockClient = { reply: () => {}, fs: {} };
const badCmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient);
sandbox.stub(badMockClient, 'reply').resolves();
badCmdFn()

return badCmdFn()
.then(() => {
expect(badMockClient.reply.args[0][0]).to.equal(402);
done();
})
.catch(done);
});
});
});

it('test // successful', done => {
cmdFn({log, command: { arg: 'test', directive: CMD}})
it('test // successful', () => {
return cmdFn({log, command: { arg: 'test', directive: CMD}})
.then(() => {
expect(mockClient.reply.args[0][0]).to.equal(250);
expect(mockClient.fs.delete.args[0][0]).to.equal('test');
done();
})
.catch(done);
});
});

it('bad // unsuccessful', done => {
it('bad // unsuccessful', () => {
mockClient.fs.delete.restore();
sandbox.stub(mockClient.fs, 'delete').rejects(new Error('Bad'));

cmdFn({log, command: { arg: 'bad', directive: CMD}})
return cmdFn({log, command: { arg: 'bad', directive: CMD}})
.then(() => {
expect(mockClient.reply.args[0][0]).to.equal(550);
expect(mockClient.fs.delete.args[0][0]).to.equal('bad');
done();
})
.catch(done);
});
});
});
32 changes: 12 additions & 20 deletions test/commands/registration/help.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,31 @@ describe(CMD, function () {
sandbox.restore();
});

it('// successful', done => {
cmdFn({command: { directive: CMD }})
it('// successful', () => {
return cmdFn({command: { directive: CMD }})
.then(() => {
expect(mockClient.reply.args[0][0]).to.equal(211);
done();
})
.catch(done);
});
});

it('help // successful', done => {
cmdFn({command: { arg: 'help', directive: CMD}})
it('help // successful', () => {
return cmdFn({command: { arg: 'help', directive: CMD}})
.then(() => {
expect(mockClient.reply.args[0][0]).to.equal(214);
done();
})
.catch(done);
});
});

it('help // successful', done => {
cmdFn({command: { arg: 'allo', directive: CMD}})
it('allo // successful', () => {
return cmdFn({command: { arg: 'allo', directive: CMD}})
.then(() => {
expect(mockClient.reply.args[0][0]).to.equal(214);
done();
})
.catch(done);
});
});

it('bad // unsuccessful', done => {
cmdFn({command: { arg: 'bad', directive: CMD}})
it('bad // unsuccessful', () => {
return cmdFn({command: { arg: 'bad', directive: CMD}})
.then(() => {
expect(mockClient.reply.args[0][0]).to.equal(502);
done();
})
.catch(done);
});
});
});
Loading

0 comments on commit 63777c0

Please sign in to comment.