diff --git a/.env b/.env index 0fc5ab2a..c8cc77e3 100755 --- a/.env +++ b/.env @@ -1,3 +1,2 @@ FTP_URL=ftp://127.0.0.1:8880 PASV_RANGE=8881 -LOG_LEVEL=fatal diff --git a/config/testUnit/mocha.opts b/config/testUnit/mocha.opts index 198672c2..98275371 100644 --- a/config/testUnit/mocha.opts +++ b/config/testUnit/mocha.opts @@ -1,4 +1,3 @@ test/**/*.spec.js ---reporter list ---no-timeouts +--reporter mocha-pretty-bunyan-nyan --ui bdd diff --git a/config/testUnit/thresholds.json b/config/testUnit/thresholds.json index 21cc820b..cba363f2 100644 --- a/config/testUnit/thresholds.json +++ b/config/testUnit/thresholds.json @@ -1,14 +1,14 @@ { "global": { - "statements": 70, - "branches": 60, - "functions": 80, - "lines": 80 + "statements": 90, + "branches": 80, + "functions": 90, + "lines": 90 }, "each": { - "statements": 0, - "branches": 0, - "functions": 0, - "lines": 0 + "statements": 70, + "branches": 40, + "functions": 60, + "lines": 70 } } diff --git a/package.json b/package.json index ee390df8..89362d79 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ "dependencies": { "bunyan": "^1.8.9", "lodash": "^4.17.4", - "minimist-string": "^1.0.2", "moment": "^2.18.1", "uuid": "^3.0.1", "when": "^3.7.8" @@ -68,6 +67,7 @@ "husky": "0.13.1", "istanbul": "0.4.5", "mocha": "3.2.0", + "mocha-pretty-bunyan-nyan": "^1.0.4", "npm-run-all": "4.0.1", "rimraf": "2.5.4", "semantic-release": "^6.3.2", diff --git a/src/commands/index.js b/src/commands/index.js index f8e79ab3..17ff4cc2 100644 --- a/src/commands/index.js +++ b/src/commands/index.js @@ -11,11 +11,22 @@ class FtpCommands { this.whitelist = _.get(this.connection, 'server.options.whitelist', []).map(cmd => _.upperCase(cmd)); } + parse(message) { + const [directive, ...args] = message.replace(/"/g, '').split(' '); + const command = { + directive: _.chain(directive).trim().toUpper().value(), + arg: _.compact(args).join(' ') || null, + raw: message + }; + return command; + } + handle(command) { + if (typeof command === 'string') command = this.parse(command); + // Obfuscate password from logs - const logCommand = _.cloneDeep(command); - command.directive = _.upperCase(command._[0]); - if (command.directive === 'PASS') logCommand._[1] = '********'; + const logCommand = _.clone(command); + if (logCommand.directive === 'PASS') logCommand.arg = '********'; const log = this.connection.log.child({directive: command.directive}); log.trace({command: logCommand}, 'Handle command'); @@ -45,7 +56,7 @@ class FtpCommands { const handler = commandRegister.handler.bind(this.connection); return when.try(handler, { log, command, previous_command: this.previousCommand }) .finally(() => { - this.previousCommand = _.cloneDeep(command); + this.previousCommand = _.clone(command); }); } } diff --git a/src/commands/registration/auth.js b/src/commands/registration/auth.js index 4ad9ec68..17d5c3f2 100644 --- a/src/commands/registration/auth.js +++ b/src/commands/registration/auth.js @@ -3,7 +3,7 @@ const _ = require('lodash'); module.exports = { directive: 'AUTH', handler: function ({command} = {}) { - const method = _.upperCase(command._[1]); + const method = _.upperCase(command.arg); switch (method) { case 'TLS': return handleTLS.call(this); diff --git a/src/commands/registration/cdup.js b/src/commands/registration/cdup.js index ac72f8d8..815ebd6d 100644 --- a/src/commands/registration/cdup.js +++ b/src/commands/registration/cdup.js @@ -3,7 +3,7 @@ const cwd = require('./cwd').handler; module.exports = { directive: ['CDUP', 'XCUP'], handler: function (args) { - args.command._ = [args.command._[0], '..']; + args.command.arg = '..'; return cwd.call(this, args); }, syntax: '{{cmd}}', diff --git a/src/commands/registration/cwd.js b/src/commands/registration/cwd.js index 1977ce9b..4496fcdb 100644 --- a/src/commands/registration/cwd.js +++ b/src/commands/registration/cwd.js @@ -7,7 +7,7 @@ module.exports = { if (!this.fs) return this.reply(550, 'File system not instantiated'); if (!this.fs.chdir) return this.reply(402, 'Not supported by file system'); - return when.try(this.fs.chdir.bind(this.fs), command._[1]) + return when.try(this.fs.chdir.bind(this.fs), command.arg) .then(cwd => { const path = cwd ? `"${escapePath(cwd)}"` : undefined; return this.reply(250, path); diff --git a/src/commands/registration/dele.js b/src/commands/registration/dele.js index e843c280..9900945b 100644 --- a/src/commands/registration/dele.js +++ b/src/commands/registration/dele.js @@ -6,7 +6,7 @@ module.exports = { if (!this.fs) return this.reply(550, 'File system not instantiated'); if (!this.fs.delete) return this.reply(402, 'Not supported by file system'); - return when.try(this.fs.delete.bind(this.fs), command._[1]) + return when.try(this.fs.delete.bind(this.fs), command.arg) .then(() => { return this.reply(250); }) diff --git a/src/commands/registration/help.js b/src/commands/registration/help.js index a6d8ba40..2a550565 100644 --- a/src/commands/registration/help.js +++ b/src/commands/registration/help.js @@ -4,7 +4,7 @@ module.exports = { directive: 'HELP', handler: function ({command} = {}) { const registry = require('../registry'); - const directive = _.upperCase(command._[1]); + const directive = _.upperCase(command.arg); if (directive) { if (!registry.hasOwnProperty(directive)) return this.reply(502, `Unknown command ${directive}.`); diff --git a/src/commands/registration/list.js b/src/commands/registration/list.js index 8952d4de..e7219583 100644 --- a/src/commands/registration/list.js +++ b/src/commands/registration/list.js @@ -13,7 +13,7 @@ module.exports = { const simple = command.directive === 'NLST'; let dataSocket; - const directory = command._[1] || '.'; + const directory = command.arg || '.'; return this.connector.waitForConnection() .then(socket => { this.commandSocket.pause(); diff --git a/src/commands/registration/mdtm.js b/src/commands/registration/mdtm.js index ff5c0e7e..a465d724 100644 --- a/src/commands/registration/mdtm.js +++ b/src/commands/registration/mdtm.js @@ -7,7 +7,7 @@ module.exports = { if (!this.fs) return this.reply(550, 'File system not instantiated'); if (!this.fs.get) return this.reply(402, 'Not supported by file system'); - return when.try(this.fs.get.bind(this.fs), command._[1]) + return when.try(this.fs.get.bind(this.fs), command.arg) .then(fileStat => { const modificationTime = moment.utc(fileStat.mtime).format('YYYYMMDDHHmmss.SSS'); return this.reply(213, modificationTime); diff --git a/src/commands/registration/mkd.js b/src/commands/registration/mkd.js index 2b48c850..2d0bc92a 100644 --- a/src/commands/registration/mkd.js +++ b/src/commands/registration/mkd.js @@ -7,7 +7,7 @@ module.exports = { if (!this.fs) return this.reply(550, 'File system not instantiated'); if (!this.fs.mkdir) return this.reply(402, 'Not supported by file system'); - return when.try(this.fs.mkdir.bind(this.fs), command._[1]) + return when.try(this.fs.mkdir.bind(this.fs), command.arg) .then(dir => { const path = dir ? `"${escapePath(dir)}"` : undefined; return this.reply(257, path); diff --git a/src/commands/registration/mode.js b/src/commands/registration/mode.js index 3b896725..478bdb77 100644 --- a/src/commands/registration/mode.js +++ b/src/commands/registration/mode.js @@ -1,7 +1,7 @@ module.exports = { directive: 'MODE', handler: function ({command} = {}) { - return this.reply(/^S$/i.test(command._[1]) ? 200 : 504); + return this.reply(/^S$/i.test(command.arg) ? 200 : 504); }, syntax: '{{cmd}} [mode]', description: 'Sets the transfer mode (Stream, Block, or Compressed)', diff --git a/src/commands/registration/pass.js b/src/commands/registration/pass.js index d52af503..a1db1b40 100644 --- a/src/commands/registration/pass.js +++ b/src/commands/registration/pass.js @@ -9,7 +9,7 @@ module.exports = { // 332 : require account name (ACCT) - const password = command._[1]; + const password = command.arg; return this.login(this.username, password) .then(() => { return this.reply(230); diff --git a/src/commands/registration/port.js b/src/commands/registration/port.js index ded315ee..453b844b 100644 --- a/src/commands/registration/port.js +++ b/src/commands/registration/port.js @@ -5,7 +5,7 @@ module.exports = { directive: 'PORT', handler: function ({command} = {}) { this.connector = new ActiveConnector(this); - const rawConnection = _.get(command, '_[1]', '').split(','); + const rawConnection = _.get(command, 'arg', '').split(','); if (rawConnection.length !== 6) return this.reply(425); const ip = rawConnection.slice(0, 4).join('.'); diff --git a/src/commands/registration/retr.js b/src/commands/registration/retr.js index 1e8f4b81..364bac26 100644 --- a/src/commands/registration/retr.js +++ b/src/commands/registration/retr.js @@ -12,7 +12,7 @@ module.exports = { this.commandSocket.pause(); dataSocket = socket; }) - .then(() => when.try(this.fs.read.bind(this.fs), command._[1])) + .then(() => when.try(this.fs.read.bind(this.fs), command.arg)) .then(stream => { return when.promise((resolve, reject) => { dataSocket.on('error', err => stream.emit('error', err)); diff --git a/src/commands/registration/rnfr.js b/src/commands/registration/rnfr.js index c84e59f2..93420907 100644 --- a/src/commands/registration/rnfr.js +++ b/src/commands/registration/rnfr.js @@ -6,7 +6,7 @@ module.exports = { if (!this.fs) return this.reply(550, 'File system not instantiated'); if (!this.fs.get) return this.reply(402, 'Not supported by file system'); - const fileName = command._[1]; + const fileName = command.arg; return when.try(this.fs.get.bind(this.fs), fileName) .then(() => { this.renameFrom = fileName; diff --git a/src/commands/registration/rnto.js b/src/commands/registration/rnto.js index 755c7145..3f66c9da 100644 --- a/src/commands/registration/rnto.js +++ b/src/commands/registration/rnto.js @@ -9,7 +9,7 @@ module.exports = { if (!this.fs.rename) return this.reply(402, 'Not supported by file system'); const from = this.renameFrom; - const to = command._[1]; + const to = command.arg; return when.try(this.fs.rename.bind(this.fs), from, to) .then(() => { diff --git a/src/commands/registration/site/chmod.js b/src/commands/registration/site/chmod.js index e0954c04..a37628db 100644 --- a/src/commands/registration/site/chmod.js +++ b/src/commands/registration/site/chmod.js @@ -4,7 +4,8 @@ module.exports = function ({log, command} = {}) { if (!this.fs) return this.reply(550, 'File system not instantiated'); if (!this.fs.chmod) return this.reply(402, 'Not supported by file system'); - const [, mode, fileName] = command._; + const [mode, ...fileNameParts] = command.arg.split(' '); + const fileName = fileNameParts.join(' '); return when.try(this.fs.chmod.bind(this.fs), fileName, parseInt(mode, 8)) .then(() => { return this.reply(200); diff --git a/src/commands/registration/site/index.js b/src/commands/registration/site/index.js index ee1a04ab..ef7be539 100644 --- a/src/commands/registration/site/index.js +++ b/src/commands/registration/site/index.js @@ -1,21 +1,15 @@ -const _ = require('lodash'); const when = require('when'); module.exports = { directive: 'SITE', handler: function ({log, command} = {}) { const registry = require('./registry'); - let [, subverb, ...subparameters] = command._; - subverb = _.upperCase(subverb); - const subLog = log.child({subverb}); + const subCommand = this.commands.parse(command.arg); + const subLog = log.child({subverb: subCommand.directive}); - if (!registry.hasOwnProperty(subverb)) return this.reply(502); + if (!registry.hasOwnProperty(subCommand.directive)) return this.reply(502); - const subCommand = { - _: [subverb, ...subparameters], - directive: subverb - }; - const handler = registry[subverb].handler.bind(this); + const handler = registry[subCommand.directive].handler.bind(this); return when.try(handler, { log: subLog, command: subCommand }); }, syntax: '{{cmd}} [subVerb] [subParams]', diff --git a/src/commands/registration/size.js b/src/commands/registration/size.js index 2f1a6258..1a940a02 100644 --- a/src/commands/registration/size.js +++ b/src/commands/registration/size.js @@ -6,7 +6,7 @@ module.exports = { if (!this.fs) return this.reply(550, 'File system not instantiated'); if (!this.fs.get) return this.reply(402, 'Not supported by file system'); - return when.try(this.fs.get.bind(this.fs), command._[1]) + return when.try(this.fs.get.bind(this.fs), command.arg) .then(fileStat => { return this.reply(213, {message: fileStat.size}); }) diff --git a/src/commands/registration/stat.js b/src/commands/registration/stat.js index 4aa18434..a611e9df 100644 --- a/src/commands/registration/stat.js +++ b/src/commands/registration/stat.js @@ -6,7 +6,7 @@ module.exports = { directive: 'STAT', handler: function (args = {}) { const {log, command} = args; - const path = _.get(command, '_[1]'); + const path = _.get(command, 'arg'); if (path) { if (!this.fs) return this.reply(550, 'File system not instantiated'); if (!this.fs.get) return this.reply(402, 'Not supported by file system'); diff --git a/src/commands/registration/stor.js b/src/commands/registration/stor.js index 2575d67b..d59facf9 100644 --- a/src/commands/registration/stor.js +++ b/src/commands/registration/stor.js @@ -7,7 +7,7 @@ module.exports = { if (!this.fs.write) return this.reply(402, 'Not supported by file system'); const append = command.directive === 'APPE'; - const fileName = command._[1]; + const fileName = command.arg; let dataSocket; return this.connector.waitForConnection() diff --git a/src/commands/registration/stou.js b/src/commands/registration/stou.js index 6720bb61..8bfdf631 100644 --- a/src/commands/registration/stou.js +++ b/src/commands/registration/stou.js @@ -8,14 +8,14 @@ module.exports = { if (!this.fs) return this.reply(550, 'File system not instantiated'); if (!this.fs.get || !this.fs.getUniqueName) return this.reply(402, 'Not supported by file system'); - const fileName = args.command._[1]; + const fileName = args.command.arg; return when.try(() => { return when.try(this.fs.get.bind(this.fs), fileName) .then(() => when.try(this.fs.getUniqueName.bind(this.fs))) .catch(() => when.resolve(fileName)); }) .then(name => { - args.command._[1] = name; + args.command.arg = name; return stor.call(this, args); }); }, diff --git a/src/commands/registration/stru.js b/src/commands/registration/stru.js index cb4484dd..1d5ad394 100644 --- a/src/commands/registration/stru.js +++ b/src/commands/registration/stru.js @@ -1,7 +1,7 @@ module.exports = { directive: 'STRU', handler: function ({command} = {}) { - return this.reply(/^F$/i.test(command._[1]) ? 200 : 504); + return this.reply(/^F$/i.test(command.arg) ? 200 : 504); }, syntax: '{{cmd}} [structure]', description: 'Set file transfer structure', diff --git a/src/commands/registration/type.js b/src/commands/registration/type.js index 81b622a9..9cce7a5f 100644 --- a/src/commands/registration/type.js +++ b/src/commands/registration/type.js @@ -9,7 +9,7 @@ const ENCODING_TYPES = { module.exports = { directive: 'TYPE', handler: function ({command} = {}) { - const encoding = _.upperCase(command._[1]); + const encoding = _.upperCase(command.arg); if (!ENCODING_TYPES.hasOwnProperty(encoding)) return this.reply(501); this.encoding = ENCODING_TYPES[encoding]; diff --git a/src/commands/registration/user.js b/src/commands/registration/user.js index b7cb8ff3..ae9a981d 100644 --- a/src/commands/registration/user.js +++ b/src/commands/registration/user.js @@ -3,7 +3,7 @@ module.exports = { handler: function ({log, command} = {}) { if (this.username) return this.reply(530, 'Username already set'); - this.username = command._[1]; + this.username = command.arg; if (!this.username) return this.reply(501, 'Must send username requirement'); if (this.server.options.anonymous === true) { diff --git a/src/connection.js b/src/connection.js index 4832f93b..9b973f82 100644 --- a/src/connection.js +++ b/src/connection.js @@ -2,7 +2,6 @@ const _ = require('lodash'); const uuid = require('uuid'); const when = require('when'); const sequence = require('when/sequence'); -const parseCommandString = require('minimist-string'); const BaseConnector = require('./connector/base'); const FileSystem = require('./fs'); @@ -26,12 +25,7 @@ class FtpConnection { }); this.commandSocket.on('data', data => { const messages = _.compact(data.toString('utf-8').split('\r\n')); - const handleMessage = message => { - const command = parseCommandString(message); - return this.commands.handle(command); - }; - - return sequence(messages.map(message => handleMessage.bind(this, message))); + return sequence(messages.map(message => this.commands.handle.bind(this.commands, message))); }); this.commandSocket.on('timeout', () => {}); this.commandSocket.on('close', () => { @@ -64,7 +58,7 @@ class FtpConnection { return this.server.emit('login', {connection: this, username, password}); } }) - .then(({root = '/', cwd = '/', fs, blacklist = [], whitelist = []} = {}) => { + .then(({root, cwd, fs, blacklist = [], whitelist = []} = {}) => { this.authenticated = true; this.commands.blacklist = _.concat(this.commands.blacklist, blacklist); this.commands.whitelist = _.concat(this.commands.whitelist, whitelist); diff --git a/src/fs.js b/src/fs.js index fae20fbf..b1ec848c 100644 --- a/src/fs.js +++ b/src/fs.js @@ -8,29 +8,22 @@ const fs = whenNode.liftAll(syncFs); const errors = require('./errors'); class FileSystem { - constructor(connection, { - root = '/', - cwd = '/' - } = {}) { + constructor(connection, { root, cwd } = {}) { this.connection = connection; - this.cwd = this._normalize(cwd); - this.root = this._normalize(root); + this.cwd = cwd || nodePath.sep; + this.root = root || process.cwd(); } - _normalize(path) { - return nodePath.normalize(path - .replace(/\\/g, '\/') // replaces \ with / - .replace(/\\\\/g, '\/') // replaces \\ with / - .replace(/\/\//g, '\/') // replaces // with / - ); - } + _resolvePath(path = '') { + const isFromRoot = _.startsWith(path, '/') || _.startsWith(path, nodePath.sep); + const cwd = isFromRoot ? nodePath.sep : this.cwd || nodePath.sep; + const serverPath = nodePath.join(nodePath.sep, cwd, path); + const fsPath = nodePath.join(this.root, serverPath); - _resolvePath(path) { - const pathParts = { - root: this.root, - base: nodePath.join(this.cwd, this._normalize(path)) + return { + serverPath, + fsPath }; - return nodePath.format(pathParts); } currentDirectory() { @@ -38,17 +31,17 @@ class FileSystem { } get(fileName) { - const path = this._resolvePath(fileName); - return fs.stat(path) + const {fsPath} = this._resolvePath(fileName); + return fs.stat(fsPath) .then(stat => _.set(stat, 'name', fileName)); } list(path = '.') { - path = this._resolvePath(path); - return fs.readdir(path) + const {fsPath} = this._resolvePath(path); + return fs.readdir(fsPath) .then(fileNames => { return when.map(fileNames, fileName => { - const filePath = nodePath.join(path, fileName); + const filePath = nodePath.join(fsPath, fileName); return fs.access(filePath, syncFs.constants.F_OK) .then(() => { return fs.stat(filePath) @@ -61,60 +54,60 @@ class FileSystem { } chdir(path = '.') { - path = this._resolvePath(path); - return fs.stat(path) + const {fsPath, serverPath} = this._resolvePath(path); + return fs.stat(fsPath) .tap(stat => { if (!stat.isDirectory()) throw new errors.FileSystemError('Not a valid directory'); }) .then(() => { - this.cwd = path.substring(this.root.length) || '/'; + this.cwd = serverPath; return this.currentDirectory(); }); } write(fileName, {append = false} = {}) { - const path = this._resolvePath(fileName); - const stream = syncFs.createWriteStream(path, {flags: !append ? 'w+' : 'a+'}); - stream.on('error', () => fs.unlink(path)); + const {fsPath} = this._resolvePath(fileName); + const stream = syncFs.createWriteStream(fsPath, {flags: !append ? 'w+' : 'a+'}); + stream.on('error', () => fs.unlink(fsPath)); return stream; } read(fileName) { - const path = this._resolvePath(fileName); - return fs.stat(path) + const {fsPath} = this._resolvePath(fileName); + return fs.stat(fsPath) .tap(stat => { if (stat.isDirectory()) throw new errors.FileSystemError('Cannot read a directory'); }) .then(() => { - const stream = syncFs.createReadStream(path, {flags: 'r'}); + const stream = syncFs.createReadStream(fsPath, {flags: 'r'}); return stream; }); } delete(path) { - path = this._resolvePath(path); - return fs.stat(path) + const {fsPath} = this._resolvePath(path); + return fs.stat(fsPath) .then(stat => { - if (stat.isDirectory()) return fs.rmdir(path); - else return fs.unlink(path); + if (stat.isDirectory()) return fs.rmdir(fsPath); + else return fs.unlink(fsPath); }); } mkdir(path) { - path = this._resolvePath(path); - return fs.mkdir(path) - .then(() => path); + const {fsPath} = this._resolvePath(path); + return fs.mkdir(fsPath) + .then(() => fsPath); } rename(from, to) { - const fromPath = this._resolvePath(from); - const toPath = this._resolvePath(to); + const {fsPath: fromPath} = this._resolvePath(from); + const {fsPath: toPath} = this._resolvePath(to); return fs.rename(fromPath, toPath); } chmod(path, mode) { - path = this._resolvePath(path); - return fs.chmod(path, mode); + const {fsPath} = this._resolvePath(path); + return fs.chmod(fsPath, mode); } getUniqueName() { diff --git a/test/commands/index.spec.js b/test/commands/index.spec.js new file mode 100644 index 00000000..86676628 --- /dev/null +++ b/test/commands/index.spec.js @@ -0,0 +1,95 @@ +const {expect} = require('chai'); +const when = require('when'); +const bunyan = require('bunyan'); +const sinon = require('sinon'); + +const FtpCommands = require('../../src/commands'); + +describe('FtpCommands', function () { + let sandbox; + let commands; + let mockConnection = { + authenticated: false, + log: bunyan.createLogger({name: 'FtpCommands'}), + reply: () => when.resolve({}), + server: { + options: { + blacklist: ['allo'] + } + } + }; + + beforeEach(() => { + sandbox = sinon.sandbox.create(); + + commands = new FtpCommands(mockConnection); + + sandbox.spy(mockConnection, 'reply'); + sandbox.spy(commands, 'handle'); + sandbox.spy(commands, 'parse'); + }); + afterEach(() => { + sandbox.restore(); + }); + + describe('parse', function () { + it('no args: test', () => { + const cmd = commands.parse('test'); + expect(cmd.directive).to.equal('TEST'); + expect(cmd.arg).to.equal(null); + expect(cmd.raw).to.equal('test'); + }); + + it('one arg: test arg', () => { + const cmd = commands.parse('test arg'); + expect(cmd.directive).to.equal('TEST'); + expect(cmd.arg).to.equal('arg'); + expect(cmd.raw).to.equal('test arg'); + }); + + it('two args: test arg1 arg2', () => { + const cmd = commands.parse('test arg1 arg2'); + expect(cmd.directive).to.equal('TEST'); + expect(cmd.arg).to.equal('arg1 arg2'); + expect(cmd.raw).to.equal('test arg1 arg2'); + }); + }); + + describe('handle', function () { + it('fails with unsupported command', () => { + return commands.handle('bad') + .then(() => { + expect(mockConnection.reply.callCount).to.equal(1); + expect(mockConnection.reply.args[0][0]).to.equal(402); + }); + }); + + it('fails with blacklisted command', () => { + return commands.handle('allo') + .then(() => { + expect(mockConnection.reply.callCount).to.equal(1); + expect(mockConnection.reply.args[0][0]).to.equal(502); + expect(mockConnection.reply.args[0][1]).to.match(/blacklisted/); + }); + }); + + it('fails with non whitelisted command', () => { + commands.whitelist.push('USER'); + return commands.handle('auth') + .then(() => { + expect(mockConnection.reply.callCount).to.equal(1); + expect(mockConnection.reply.args[0][0]).to.equal(502); + expect(mockConnection.reply.args[0][1]).to.match(/whitelisted/); + }); + }); + + it('fails due to being unauthenticated', () => { + return commands.handle('stor') + .then(() => { + expect(mockConnection.reply.callCount).to.equal(1); + expect(mockConnection.reply.args[0][0]).to.equal(530); + expect(mockConnection.reply.args[0][1]).to.match(/authentication/); + }); + }); + }); +}); diff --git a/test/commands/abor.spec.js b/test/commands/registration/abor.spec.js similarity index 92% rename from test/commands/abor.spec.js rename to test/commands/registration/abor.spec.js index 89f50bfb..97aae3b4 100644 --- a/test/commands/abor.spec.js +++ b/test/commands/registration/abor.spec.js @@ -12,7 +12,7 @@ describe(CMD, function () { end: () => when.resolve() } }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); diff --git a/test/commands/allo.spec.js b/test/commands/registration/allo.spec.js similarity index 83% rename from test/commands/allo.spec.js rename to test/commands/registration/allo.spec.js index 327e5ae1..8c9f1eff 100644 --- a/test/commands/allo.spec.js +++ b/test/commands/registration/allo.spec.js @@ -8,7 +8,7 @@ describe(CMD, function () { const mockClient = { reply: () => when.resolve() }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); diff --git a/test/commands/auth.spec.js b/test/commands/registration/auth.spec.js similarity index 75% rename from test/commands/auth.spec.js rename to test/commands/registration/auth.spec.js index e7541425..c2ff6847 100644 --- a/test/commands/auth.spec.js +++ b/test/commands/registration/auth.spec.js @@ -8,7 +8,7 @@ describe(CMD, function () { const mockClient = { reply: () => when.resolve() }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -20,7 +20,7 @@ describe(CMD, function () { }); it('TLS // not supported', done => { - cmdFn({command: {_: [CMD, 'TLS'], directive: CMD}}) + cmdFn({command: { arg: 'TLS', directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(504); done(); @@ -29,7 +29,7 @@ describe(CMD, function () { }); it('SSL // not supported', done => { - cmdFn({command: {_: [CMD, 'SSL'], directive: CMD}}) + cmdFn({command: { arg: 'SSL', directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(504); done(); @@ -38,7 +38,7 @@ describe(CMD, function () { }); it('bad // bad', done => { - cmdFn({command: {_: [CMD, 'bad'], directive: CMD}}) + cmdFn({command: { arg: 'bad', directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(504); done(); diff --git a/test/commands/cdup.spec.js b/test/commands/registration/cdup.spec.js similarity index 82% rename from test/commands/cdup.spec.js rename to test/commands/registration/cdup.spec.js index 60d2d9c6..87205aea 100644 --- a/test/commands/cdup.spec.js +++ b/test/commands/registration/cdup.spec.js @@ -13,7 +13,7 @@ describe(CMD, function () { chdir: () => when.resolve() } }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -26,7 +26,7 @@ describe(CMD, function () { }); it('.. // successful', done => { - cmdFn({log, command: {_: [CMD], directive: CMD}}) + cmdFn({log, command: {directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(250); expect(mockClient.fs.chdir.args[0][0]).to.equal('..'); diff --git a/test/commands/cwd.spec.js b/test/commands/registration/cwd.spec.js similarity index 79% rename from test/commands/cwd.spec.js rename to test/commands/registration/cwd.spec.js index 522003a6..6ed6d2b3 100644 --- a/test/commands/cwd.spec.js +++ b/test/commands/registration/cwd.spec.js @@ -10,7 +10,7 @@ describe(CMD, function () { reply: () => {}, fs: { chdir: () => {} } }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -25,7 +25,7 @@ describe(CMD, function () { describe('// check', function () { it('fails on no fs', done => { const badMockClient = { reply: () => {} }; - const badCmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); + const badCmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); sandbox.stub(badMockClient, 'reply').resolves(); badCmdFn() .then(() => { @@ -37,7 +37,7 @@ describe(CMD, function () { it('fails on no fs chdir command', done => { const badMockClient = { reply: () => {}, fs: {} }; - const badCmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); + const badCmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); sandbox.stub(badMockClient, 'reply').resolves(); badCmdFn() .then(() => { @@ -49,7 +49,7 @@ describe(CMD, function () { }); it('test // successful', done => { - cmdFn({log, command: {_: [CMD, 'test'], directive: CMD}}) + 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'); @@ -61,7 +61,7 @@ describe(CMD, function () { it('test // successful', done => { mockClient.fs.chdir.restore(); sandbox.stub(mockClient.fs, 'chdir').resolves('/test'); - cmdFn({log, command: {_: [CMD, 'test'], directive: CMD}}) + 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'); @@ -74,7 +74,7 @@ describe(CMD, function () { mockClient.fs.chdir.restore(); sandbox.stub(mockClient.fs, 'chdir').rejects(new Error('Bad')); - cmdFn({log, command: {_: [CMD, 'bad'], directive: CMD}}) + 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'); diff --git a/test/commands/dele.spec.js b/test/commands/registration/dele.spec.js similarity index 78% rename from test/commands/dele.spec.js rename to test/commands/registration/dele.spec.js index f356a7fe..2317f868 100644 --- a/test/commands/dele.spec.js +++ b/test/commands/registration/dele.spec.js @@ -10,7 +10,7 @@ describe(CMD, function () { reply: () => {}, fs: { delete: () => {} } }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -25,7 +25,7 @@ describe(CMD, function () { describe('// check', function () { it('fails on no fs', done => { const badMockClient = { reply: () => {} }; - const badCmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); + const badCmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); sandbox.stub(badMockClient, 'reply').resolves(); badCmdFn() .then(() => { @@ -37,7 +37,7 @@ describe(CMD, function () { it('fails on no fs delete command', done => { const badMockClient = { reply: () => {}, fs: {} }; - const badCmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); + const badCmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); sandbox.stub(badMockClient, 'reply').resolves(); badCmdFn() .then(() => { @@ -49,7 +49,7 @@ describe(CMD, function () { }); it('test // successful', done => { - cmdFn({log, command: {_: [CMD, 'test'], directive: CMD}}) + 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'); @@ -62,7 +62,7 @@ describe(CMD, function () { mockClient.fs.delete.restore(); sandbox.stub(mockClient.fs, 'delete').rejects(new Error('Bad')); - cmdFn({log, command: {_: [CMD, 'bad'], directive: CMD}}) + 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'); diff --git a/test/commands/help.spec.js b/test/commands/registration/help.spec.js similarity index 75% rename from test/commands/help.spec.js rename to test/commands/registration/help.spec.js index 7410e78c..061a10a3 100644 --- a/test/commands/help.spec.js +++ b/test/commands/registration/help.spec.js @@ -8,7 +8,7 @@ describe(CMD, function () { const mockClient = { reply: () => when.resolve() }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -20,7 +20,7 @@ describe(CMD, function () { }); it('// successful', done => { - cmdFn({command: {_: [CMD], directive: CMD}}) + cmdFn({command: { directive: CMD }}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(211); done(); @@ -29,7 +29,7 @@ describe(CMD, function () { }); it('help // successful', done => { - cmdFn({command: {_: [CMD, 'help'], directive: CMD}}) + cmdFn({command: { arg: 'help', directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(214); done(); @@ -38,7 +38,7 @@ describe(CMD, function () { }); it('help // successful', done => { - cmdFn({command: {_: [CMD, 'allo'], directive: CMD}}) + cmdFn({command: { arg: 'allo', directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(214); done(); @@ -47,7 +47,7 @@ describe(CMD, function () { }); it('bad // unsuccessful', done => { - cmdFn({command: {_: [CMD, 'bad'], directive: CMD}}) + cmdFn({command: { arg: 'bad', directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(502); done(); diff --git a/test/commands/list.spec.js b/test/commands/registration/list.spec.js similarity index 84% rename from test/commands/list.spec.js rename to test/commands/registration/list.spec.js index f9f0fa14..60e4ced7 100644 --- a/test/commands/list.spec.js +++ b/test/commands/registration/list.spec.js @@ -19,7 +19,7 @@ describe(CMD, function () { pause: () => {} } }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -51,7 +51,7 @@ describe(CMD, function () { describe('// check', function () { it('fails on no fs', done => { const badMockClient = { reply: () => {} }; - const badCmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); + const badCmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); sandbox.stub(badMockClient, 'reply').resolves(); badCmdFn() .then(() => { @@ -63,7 +63,7 @@ describe(CMD, function () { it('fails on no fs list command', done => { const badMockClient = { reply: () => {}, fs: {} }; - const badCmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); + const badCmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); sandbox.stub(badMockClient, 'reply').resolves(); badCmdFn() .then(() => { @@ -75,7 +75,7 @@ describe(CMD, function () { }); it('. // successful', done => { - cmdFn({log, command: {_: [CMD], directive: CMD}}) + cmdFn({log, command: {directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(150); expect(mockClient.reply.args[1][1]).to.have.property('raw'); @@ -91,7 +91,7 @@ describe(CMD, function () { mockClient.fs.list.restore(); sandbox.stub(mockClient.fs, 'list').rejects(new Error()); - cmdFn({log, command: {_: [CMD], directive: CMD}}) + cmdFn({log, command: {directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(451); done(); @@ -102,7 +102,7 @@ describe(CMD, function () { it('. // unsuccessful (timeout)', done => { sandbox.stub(mockClient.connector, 'waitForConnection').returns(when.reject(new when.TimeoutError())); - cmdFn({log, command: {_: [CMD], directive: CMD}}) + cmdFn({log, command: {directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(425); done(); diff --git a/test/commands/mdtm.spec.js b/test/commands/registration/mdtm.spec.js similarity index 78% rename from test/commands/mdtm.spec.js rename to test/commands/registration/mdtm.spec.js index 7bcb721d..431734a3 100644 --- a/test/commands/mdtm.spec.js +++ b/test/commands/registration/mdtm.spec.js @@ -10,7 +10,7 @@ describe(CMD, function () { reply: () => {}, fs: { get: () => {} } }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -25,7 +25,7 @@ describe(CMD, function () { describe('// check', function () { it('fails on no fs', done => { const badMockClient = { reply: () => {} }; - const badCmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); + const badCmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); sandbox.stub(badMockClient, 'reply').resolves(); badCmdFn() .then(() => { @@ -37,7 +37,7 @@ describe(CMD, function () { it('fails on no fs get command', done => { const badMockClient = { reply: () => {}, fs: {} }; - const badCmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); + const badCmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); sandbox.stub(badMockClient, 'reply').resolves(); badCmdFn() .then(() => { @@ -49,7 +49,7 @@ describe(CMD, function () { }); it('. // successful', done => { - cmdFn({log, command: {_: [CMD], directive: CMD}}) + cmdFn({log, command: {directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(213); //expect(mockClient.reply.args[0][1]).to.equal('20111010172411.000'); @@ -62,7 +62,7 @@ describe(CMD, function () { mockClient.fs.get.restore(); sandbox.stub(mockClient.fs, 'get').rejects(new Error()); - cmdFn({log, command: {_: [CMD], directive: CMD}}) + cmdFn({log, command: {directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(550); done(); diff --git a/test/commands/mkd.spec.js b/test/commands/registration/mkd.spec.js similarity index 79% rename from test/commands/mkd.spec.js rename to test/commands/registration/mkd.spec.js index 8f4863d9..5375e3ac 100644 --- a/test/commands/mkd.spec.js +++ b/test/commands/registration/mkd.spec.js @@ -10,7 +10,7 @@ describe(CMD, function () { reply: () => {}, fs: { mkdir: () => {} } }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -25,7 +25,7 @@ describe(CMD, function () { describe('// check', function () { it('fails on no fs', done => { const badMockClient = { reply: () => {} }; - const badCmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); + const badCmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); sandbox.stub(badMockClient, 'reply').resolves(); badCmdFn() .then(() => { @@ -37,7 +37,7 @@ describe(CMD, function () { it('fails on no fs mkdir command', done => { const badMockClient = { reply: () => {}, fs: {} }; - const badCmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); + const badCmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); sandbox.stub(badMockClient, 'reply').resolves(); badCmdFn() .then(() => { @@ -49,7 +49,7 @@ describe(CMD, function () { }); it('test // successful', done => { - cmdFn({log, command: {_: [CMD, 'test'], directive: CMD}}) + cmdFn({log, command: {arg: 'test', directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(257); expect(mockClient.fs.mkdir.args[0][0]).to.equal('test'); @@ -61,7 +61,7 @@ describe(CMD, function () { it('test // successful', done => { mockClient.fs.mkdir.restore(); sandbox.stub(mockClient.fs, 'mkdir').resolves('test'); - cmdFn({log, command: {_: [CMD, 'test'], directive: CMD}}) + cmdFn({log, command: {arg: 'test', directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(257); expect(mockClient.fs.mkdir.args[0][0]).to.equal('test'); @@ -74,7 +74,7 @@ describe(CMD, function () { mockClient.fs.mkdir.restore(); sandbox.stub(mockClient.fs, 'mkdir').rejects(new Error('Bad')); - cmdFn({log, command: {_: [CMD, 'bad'], directive: CMD}}) + cmdFn({log, command: {arg: 'bad', directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(550); expect(mockClient.fs.mkdir.args[0][0]).to.equal('bad'); diff --git a/test/commands/mode.spec.js b/test/commands/registration/mode.spec.js similarity index 79% rename from test/commands/mode.spec.js rename to test/commands/registration/mode.spec.js index 7054f12a..4ee7e292 100644 --- a/test/commands/mode.spec.js +++ b/test/commands/registration/mode.spec.js @@ -8,7 +8,7 @@ describe(CMD, function () { const mockClient = { reply: () => when.resolve() }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -20,7 +20,7 @@ describe(CMD, function () { }); it('S // successful', done => { - cmdFn({command: {_: [CMD, 'S']}}) + cmdFn({command: {arg: 'S'}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(200); done(); @@ -29,7 +29,7 @@ describe(CMD, function () { }); it('Q // unsuccessful', done => { - cmdFn({command: {_: [CMD, 'Q']}}) + cmdFn({command: {arg: 'Q'}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(504); done(); diff --git a/test/commands/nlst.spec.js b/test/commands/registration/nlst.spec.js similarity index 90% rename from test/commands/nlst.spec.js rename to test/commands/registration/nlst.spec.js index 09d089f4..604adb3f 100644 --- a/test/commands/nlst.spec.js +++ b/test/commands/registration/nlst.spec.js @@ -19,7 +19,7 @@ describe(CMD, function () { pause: () => {} } }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -49,7 +49,7 @@ describe(CMD, function () { }); it('. // successful', done => { - cmdFn({log, command: {_: [CMD], directive: CMD}}) + cmdFn({log, command: {directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(150); expect(mockClient.reply.args[1][1]).to.have.property('raw'); diff --git a/test/commands/noop.spec.js b/test/commands/registration/noop.spec.js similarity index 83% rename from test/commands/noop.spec.js rename to test/commands/registration/noop.spec.js index 34bc52a0..19f1c682 100644 --- a/test/commands/noop.spec.js +++ b/test/commands/registration/noop.spec.js @@ -8,7 +8,7 @@ describe(CMD, function () { const mockClient = { reply: () => when.resolve() }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); diff --git a/test/commands/opts.spec.js b/test/commands/registration/opts.spec.js similarity index 83% rename from test/commands/opts.spec.js rename to test/commands/registration/opts.spec.js index a079e8c0..e3efba02 100644 --- a/test/commands/opts.spec.js +++ b/test/commands/registration/opts.spec.js @@ -8,7 +8,7 @@ describe(CMD, function () { const mockClient = { reply: () => when.resolve() }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); diff --git a/test/commands/pass.spec.js b/test/commands/registration/pass.spec.js similarity index 82% rename from test/commands/pass.spec.js rename to test/commands/registration/pass.spec.js index 33dccd74..09e45ba8 100644 --- a/test/commands/pass.spec.js +++ b/test/commands/registration/pass.spec.js @@ -12,7 +12,7 @@ describe(CMD, function () { server: { options: { anonymous: false } }, username: 'user' }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -25,7 +25,7 @@ describe(CMD, function () { }); it('pass // successful', done => { - cmdFn({log, command: {_: [CMD, 'pass'], directive: CMD}}) + cmdFn({log, command: {arg: 'pass', directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(230); expect(mockClient.login.args[0]).to.eql(['user', 'pass']); @@ -37,7 +37,7 @@ describe(CMD, function () { it('// successful (anonymous)', done => { mockClient.server.options.anonymous = true; mockClient.authenticated = true; - cmdFn({log, command: {_: [CMD], directive: CMD}}) + cmdFn({log, command: {directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(230); expect(mockClient.login.callCount).to.equal(0); @@ -52,7 +52,7 @@ describe(CMD, function () { mockClient.login.restore(); sandbox.stub(mockClient, 'login').rejects('bad'); - cmdFn({log, command: {_: [CMD, 'bad'], directive: CMD}}) + cmdFn({log, command: {arg: 'bad', directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(530); done(); @@ -64,7 +64,7 @@ describe(CMD, function () { mockClient.login.restore(); sandbox.stub(mockClient, 'login').rejects({}); - cmdFn({log, command: {_: [CMD, 'bad'], directive: CMD}}) + cmdFn({log, command: {arg: 'bad', directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(530); done(); @@ -74,7 +74,7 @@ describe(CMD, function () { it('bad // unsuccessful', done => { delete mockClient.username; - cmdFn({log, command: {_: [CMD, 'bad'], directive: CMD}}) + cmdFn({log, command: {arg: 'bad', directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(503); done(); diff --git a/test/commands/port.spec.js b/test/commands/registration/port.spec.js similarity index 79% rename from test/commands/port.spec.js rename to test/commands/registration/port.spec.js index af02e05a..09d51d97 100644 --- a/test/commands/port.spec.js +++ b/test/commands/registration/port.spec.js @@ -2,7 +2,7 @@ const when = require('when'); const {expect} = require('chai'); const sinon = require('sinon'); -const ActiveConnector = require('../../src/connector/active'); +const ActiveConnector = require('../../../src/connector/active'); const CMD = 'PORT'; describe(CMD, function () { @@ -10,7 +10,7 @@ describe(CMD, function () { const mockClient = { reply: () => when.resolve() }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -32,7 +32,7 @@ describe(CMD, function () { }); it('// unsuccessful | invalid argument', done => { - cmdFn({ command: { _: [CMD, '1,2,3,4,5'] } }) + cmdFn({ command: { arg: '1,2,3,4,5' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(425); done(); @@ -41,7 +41,7 @@ describe(CMD, function () { }); it('// successful', done => { - cmdFn({ command: { _: [CMD, '192,168,0,100,137,214'] } }) + cmdFn({ command: { arg: '192,168,0,100,137,214' } }) .then(() => { const [ip, port] = ActiveConnector.prototype.setupConnection.args[0]; expect(mockClient.reply.args[0][0]).to.equal(200); diff --git a/test/commands/pwd.spec.js b/test/commands/registration/pwd.spec.js similarity index 78% rename from test/commands/pwd.spec.js rename to test/commands/registration/pwd.spec.js index 457b8ccd..2e64e68b 100644 --- a/test/commands/pwd.spec.js +++ b/test/commands/registration/pwd.spec.js @@ -10,7 +10,7 @@ describe(CMD, function () { reply: () => {}, fs: { currentDirectory: () => {} } }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -25,7 +25,7 @@ describe(CMD, function () { describe('// check', function () { it('fails on no fs', done => { const badMockClient = { reply: () => {} }; - const badCmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); + const badCmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); sandbox.stub(badMockClient, 'reply').resolves(); badCmdFn() .then(() => { @@ -37,7 +37,7 @@ describe(CMD, function () { it('fails on no fs currentDirectory command', done => { const badMockClient = { reply: () => {}, fs: {} }; - const badCmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); + const badCmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(badMockClient); sandbox.stub(badMockClient, 'reply').resolves(); badCmdFn() .then(() => { @@ -49,7 +49,7 @@ describe(CMD, function () { }); it('// successful', done => { - cmdFn({log, command: {_: [CMD, 'test'], directive: CMD}}) + cmdFn({log, command: { arg: 'test', directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(257); done(); @@ -61,7 +61,7 @@ describe(CMD, function () { mockClient.fs.currentDirectory.restore(); sandbox.stub(mockClient.fs, 'currentDirectory').resolves('/test'); - cmdFn({log, command: {_: [CMD, 'test'], directive: CMD}}) + cmdFn({log, command: {arg: 'test', directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(257); done(); @@ -73,7 +73,7 @@ describe(CMD, function () { mockClient.fs.currentDirectory.restore(); sandbox.stub(mockClient.fs, 'currentDirectory').rejects(new Error('Bad')); - cmdFn({log, command: {_: [CMD, 'bad'], directive: CMD}}) + cmdFn({log, command: {arg: 'bad', directive: CMD}}) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(550); done(); diff --git a/test/commands/quit.spec.js b/test/commands/registration/quit.spec.js similarity index 82% rename from test/commands/quit.spec.js rename to test/commands/registration/quit.spec.js index a35b45f0..e453aa52 100644 --- a/test/commands/quit.spec.js +++ b/test/commands/registration/quit.spec.js @@ -7,7 +7,7 @@ describe(CMD, function () { const mockClient = { close: () => {} }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); diff --git a/test/commands/rnfr.spec.js b/test/commands/registration/rnfr.spec.js similarity index 86% rename from test/commands/rnfr.spec.js rename to test/commands/registration/rnfr.spec.js index 44fa5153..0c51dc52 100644 --- a/test/commands/rnfr.spec.js +++ b/test/commands/registration/rnfr.spec.js @@ -7,7 +7,7 @@ describe(CMD, function () { let sandbox; const mockLog = { error: () => {} }; const mockClient = { reply: () => when.resolve() }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -50,7 +50,7 @@ describe(CMD, function () { mockClient.fs.get.restore(); sandbox.stub(mockClient.fs, 'get').rejects(new Error('test')); - cmdFn({ log: mockLog, command: { _: [CMD, 'test'] } }) + cmdFn({ log: mockLog, command: { arg: 'test' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(550); done(); @@ -59,7 +59,7 @@ describe(CMD, function () { }); it('test // successful', done => { - cmdFn({ log: mockLog, command: { _: [CMD, 'test'] } }) + cmdFn({ log: mockLog, command: { arg: 'test' } }) .then(() => { expect(mockClient.fs.get.args[0][0]).to.equal('test'); expect(mockClient.reply.args[0][0]).to.equal(350); diff --git a/test/commands/rnto.spec.js b/test/commands/registration/rnto.spec.js similarity index 89% rename from test/commands/rnto.spec.js rename to test/commands/registration/rnto.spec.js index 587671cd..84aff483 100644 --- a/test/commands/rnto.spec.js +++ b/test/commands/registration/rnto.spec.js @@ -7,7 +7,7 @@ describe(CMD, function () { let sandbox; const mockLog = { error: () => {} }; const mockClient = { reply: () => when.resolve() }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -62,7 +62,7 @@ describe(CMD, function () { mockClient.fs.rename.restore(); sandbox.stub(mockClient.fs, 'rename').rejects(new Error('test')); - cmdFn({ log: mockLog, command: { _: [CMD, 'new'] } }) + cmdFn({ log: mockLog, command: { arg: 'new' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(550); done(); @@ -71,7 +71,7 @@ describe(CMD, function () { }); it('new // successful', done => { - cmdFn({ command: { _: [CMD, 'new'] } }) + cmdFn({ command: { arg: 'new' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(250); expect(mockClient.fs.rename.args[0]).to.eql(['test', 'new']); diff --git a/test/commands/site/chmod.spec.js b/test/commands/registration/site/chmod.spec.js similarity index 86% rename from test/commands/site/chmod.spec.js rename to test/commands/registration/site/chmod.spec.js index 56d92064..52136182 100644 --- a/test/commands/site/chmod.spec.js +++ b/test/commands/registration/site/chmod.spec.js @@ -7,7 +7,7 @@ describe(CMD, function () { let sandbox; const mockLog = { error: () => {} }; const mockClient = { reply: () => when.resolve() }; - const cmdFn = require(`../../../src/commands/registration/site/${CMD.toLowerCase()}`).bind(mockClient); + const cmdFn = require(`../../../../src/commands/registration/site/${CMD.toLowerCase()}`).bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -49,7 +49,7 @@ describe(CMD, function () { mockClient.fs.chmod.restore(); sandbox.stub(mockClient.fs, 'chmod').rejects(new Error('test')); - cmdFn({ log: mockLog, command: { _: [CMD, '777', 'test'] } }) + cmdFn({ log: mockLog, command: { arg: '777 test' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(500); done(); @@ -58,7 +58,7 @@ describe(CMD, function () { }); it('777 test // successful', done => { - cmdFn({ log: mockLog, command: { _: [CMD, '777', 'test'] } }) + cmdFn({ log: mockLog, command: { arg: '777 test' } }) .then(() => { expect(mockClient.fs.chmod.args[0]).to.eql(['test', 511]); expect(mockClient.reply.args[0][0]).to.equal(200); diff --git a/test/commands/size.spec.js b/test/commands/registration/size.spec.js similarity index 86% rename from test/commands/size.spec.js rename to test/commands/registration/size.spec.js index 1cfa9bfd..733c8d89 100644 --- a/test/commands/size.spec.js +++ b/test/commands/registration/size.spec.js @@ -7,7 +7,7 @@ describe(CMD, function () { let sandbox; const mockLog = { error: () => {} }; const mockClient = { reply: () => when.resolve() }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -47,7 +47,7 @@ describe(CMD, function () { it('// unsuccessful | file get fails', done => { sandbox.stub(mockClient.fs, 'get').rejects(new Error('test')); - cmdFn({ log: mockLog, command: { _: [CMD, 'test'] } }) + cmdFn({ log: mockLog, command: { arg: 'test' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(550); done(); @@ -56,7 +56,7 @@ describe(CMD, function () { }); it('// successful', done => { - cmdFn({ command: { _: [CMD, 'test'] } }) + cmdFn({ command: { arg: 'test' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(213); done(); diff --git a/test/commands/stat.spec.js b/test/commands/registration/stat.spec.js similarity index 89% rename from test/commands/stat.spec.js rename to test/commands/registration/stat.spec.js index 4a699262..5693f8bc 100644 --- a/test/commands/stat.spec.js +++ b/test/commands/registration/stat.spec.js @@ -7,7 +7,7 @@ describe(CMD, function () { let sandbox; const mockLog = { error: () => {} }; const mockClient = { reply: () => when.resolve() }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -35,7 +35,7 @@ describe(CMD, function () { it('// unsuccessful | no file system', done => { delete mockClient.fs; - cmdFn({ command: { _: [CMD, 'test'] } }) + cmdFn({ command: { arg: 'test' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(550); done(); @@ -46,7 +46,7 @@ describe(CMD, function () { it('// unsuccessful | file system does not have functions', done => { mockClient.fs = {}; - cmdFn({ command: { _: [CMD, 'test'] } }) + cmdFn({ command: { arg: 'test' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(402); done(); @@ -57,7 +57,7 @@ describe(CMD, function () { it('// unsuccessful | file get fails', done => { sandbox.stub(mockClient.fs, 'get').rejects(new Error('test')); - cmdFn({ log: mockLog, command: { _: [CMD, 'test'] } }) + cmdFn({ log: mockLog, command: { arg: 'test' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(450); done(); @@ -85,7 +85,7 @@ describe(CMD, function () { isDirectory: () => false }); - cmdFn({ command: { _: [CMD, 'test'] } }) + cmdFn({ command: { arg: 'test' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(212); done(); @@ -132,7 +132,7 @@ describe(CMD, function () { isDirectory: () => true }); - cmdFn({ command: { _: [CMD, 'test'] } }) + cmdFn({ command: { arg: 'test' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(213); done(); diff --git a/test/commands/stou.spec.js b/test/commands/registration/stou.spec.js similarity index 78% rename from test/commands/stou.spec.js rename to test/commands/registration/stou.spec.js index fae5943d..4337dc59 100644 --- a/test/commands/stou.spec.js +++ b/test/commands/registration/stou.spec.js @@ -2,7 +2,7 @@ const when = require('when'); const {expect} = require('chai'); const sinon = require('sinon'); -const stor = require('../../src/commands/registration/stor'); +const stor = require('../../../src/commands/registration/stor'); const CMD = 'STOU'; describe(CMD, function () { @@ -10,7 +10,7 @@ describe(CMD, function () { const mockClient = { reply: () => when.resolve() }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -56,12 +56,12 @@ describe(CMD, function () { mockClient.fs.get.restore(); sandbox.stub(mockClient.fs, 'get').rejects({}); - cmdFn({ command: { _: [CMD, 'good'] } }) + cmdFn({ command: { arg: 'good' } }) .then(() => { const call = stor.handler.call.args[0][1]; expect(call).to.have.property('command'); - expect(call.command).to.have.property('_'); - expect(call.command._).to.eql([CMD, 'good']); + expect(call.command).to.have.property('arg'); + expect(call.command.arg).to.eql('good'); expect(mockClient.fs.getUniqueName.callCount).to.equal(0); done(); }) @@ -69,12 +69,12 @@ describe(CMD, function () { }); it('// successful | generates unique name', done => { - cmdFn({ command: { _: [CMD, 'bad'] } }) + cmdFn({ command: { arg: 'bad' } }) .then(() => { const call = stor.handler.call.args[0][1]; expect(call).to.have.property('command'); - expect(call.command).to.have.property('_'); - expect(call.command._).to.eql([CMD, '4']); + expect(call.command).to.have.property('arg'); + expect(call.command.arg).to.eql('4'); expect(mockClient.fs.getUniqueName.callCount).to.equal(1); done(); }) diff --git a/test/commands/stru.spec.js b/test/commands/registration/stru.spec.js similarity index 78% rename from test/commands/stru.spec.js rename to test/commands/registration/stru.spec.js index 6d03cd85..db553549 100644 --- a/test/commands/stru.spec.js +++ b/test/commands/registration/stru.spec.js @@ -8,7 +8,7 @@ describe(CMD, function () { const mockClient = { reply: () => when.resolve() }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -20,7 +20,7 @@ describe(CMD, function () { }); it('// successful', done => { - cmdFn({command: { _: [CMD, 'F'] } }) + cmdFn({command: { arg: 'F' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(200); done(); @@ -29,7 +29,7 @@ describe(CMD, function () { }); it('// unsuccessful', done => { - cmdFn({command: { _: [CMD, 'X'] } }) + cmdFn({command: { arg: 'X' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(504); done(); diff --git a/test/commands/syst.spec.js b/test/commands/registration/syst.spec.js similarity index 83% rename from test/commands/syst.spec.js rename to test/commands/registration/syst.spec.js index 449e3b8f..2caf763c 100644 --- a/test/commands/syst.spec.js +++ b/test/commands/registration/syst.spec.js @@ -8,7 +8,7 @@ describe(CMD, function () { const mockClient = { reply: () => when.resolve() }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); diff --git a/test/commands/type.spec.js b/test/commands/registration/type.spec.js similarity index 81% rename from test/commands/type.spec.js rename to test/commands/registration/type.spec.js index 53f5a0a7..92caa29e 100644 --- a/test/commands/type.spec.js +++ b/test/commands/registration/type.spec.js @@ -8,7 +8,7 @@ describe(CMD, function () { const mockClient = { reply: () => when.resolve() }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -21,7 +21,7 @@ describe(CMD, function () { }); it('A // successful', done => { - cmdFn({ command: { _: [CMD, 'A'] } }) + cmdFn({ command: { arg: 'A' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(200); expect(mockClient.encoding).to.equal('utf-8'); @@ -31,7 +31,7 @@ describe(CMD, function () { }); it('I // successful', done => { - cmdFn({ command: { _: [CMD, 'I'] } }) + cmdFn({ command: { arg: 'I' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(200); expect(mockClient.encoding).to.equal('binary'); @@ -41,7 +41,7 @@ describe(CMD, function () { }); it('L // successful', done => { - cmdFn({ command: { _: [CMD, 'L'] } }) + cmdFn({ command: { arg: 'L' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(200); expect(mockClient.encoding).to.equal('binary'); @@ -51,7 +51,7 @@ describe(CMD, function () { }); it('X // successful', done => { - cmdFn({ command: { _: [CMD, 'X'] } }) + cmdFn({ command: { arg: 'X' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(501); expect(mockClient.encoding).to.equal(null); diff --git a/test/commands/user.spec.js b/test/commands/registration/user.spec.js similarity index 85% rename from test/commands/user.spec.js rename to test/commands/registration/user.spec.js index 860f65a1..8163e5f0 100644 --- a/test/commands/user.spec.js +++ b/test/commands/registration/user.spec.js @@ -13,7 +13,7 @@ describe(CMD, function () { server: { options: {} }, login: () => when.resolve() }; - const cmdFn = require(`../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); + const cmdFn = require(`../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient); beforeEach(() => { sandbox = sinon.sandbox.create(); @@ -29,7 +29,7 @@ describe(CMD, function () { }); it('test // successful | prompt for password', done => { - cmdFn({ command: { _: [CMD, 'test'] } }) + cmdFn({ command: { arg: 'test' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(331); done(); @@ -40,7 +40,7 @@ describe(CMD, function () { it('test // successful | anonymous login', done => { mockClient.server.options = {anonymous: true}; - cmdFn({ command: { _: [CMD, 'test'] } }) + cmdFn({ command: { arg: 'test' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(230); expect(mockClient.login.callCount).to.equal(1); @@ -50,7 +50,7 @@ describe(CMD, function () { }); it('test // unsuccessful | no username provided', done => { - cmdFn({ command: { _: [CMD] } }) + cmdFn({ command: { } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(501); expect(mockClient.login.callCount).to.equal(0); @@ -62,7 +62,7 @@ describe(CMD, function () { it('test // unsuccessful | already set username', done => { mockClient.username = 'test'; - cmdFn({ command: { _: [CMD, 'test'] } }) + cmdFn({ command: { arg: 'test' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(530); expect(mockClient.login.callCount).to.equal(0); @@ -77,7 +77,7 @@ describe(CMD, function () { mockClient.login.restore(); sandbox.stub(mockClient, 'login').rejects(new Error('test')); - cmdFn({ log: mockLog, command: { _: [CMD, 'test'] } }) + cmdFn({ log: mockLog, command: { arg: 'test' } }) .then(() => { expect(mockClient.reply.args[0][0]).to.equal(530); expect(mockClient.login.callCount).to.equal(1); diff --git a/test/index.spec.js b/test/index.spec.js index a8cf8149..1d703437 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -11,7 +11,6 @@ before(() => require('dotenv').load()); describe('FtpServer', function () { this.timeout(2000); let log = bunyan.createLogger({name: 'test'}); - log.level(process.env.LOG_LEVEL || 'debug'); let server; let client; diff --git a/test/mochabunyan.opts b/test/mochabunyan.opts new file mode 100644 index 00000000..c664ad12 --- /dev/null +++ b/test/mochabunyan.opts @@ -0,0 +1,5 @@ +{ + "mute":false, + "level":"fatal", + "reporter":"spec" +} diff --git a/test/start.js b/test/start.js new file mode 100644 index 00000000..b87c828c --- /dev/null +++ b/test/start.js @@ -0,0 +1,17 @@ +require('dotenv').load(); +const bunyan = require('bunyan'); + +const FtpServer = require('../src'); + +const log = bunyan.createLogger({name: 'test'}); +log.level('info'); +const server = new FtpServer('ftp://127.0.0.1:8880', { + log, + pasv_range: 8881 +}); +server.on('login', ({username, password}, resolve, reject) => { + console.log(username, password); + if (username === 'test' && password === 'test') resolve({ root: require('os').homedir() }); + else reject('Bad username or password'); +}); +server.listen();