diff --git a/README.md b/README.md index be0c9d7..2a7146d 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,13 @@ Type: `Boolean` Perform a shallow clone. Default: `false`. +#### strictHost + +Type: `String` + +Sets the option to enable or disable StrictHostKeyChecking for the SSH connection. + + ### Usage example ```js @@ -118,7 +125,8 @@ shipit: { ignores: ['.git', 'node_modules'], keepReleases: 2, key: '/path/to/key', - shallowClone: true + shallowClone: true, + strictHost: 'no' }, staging: { servers: 'user@myserver.com' diff --git a/lib/ssh/connection.js b/lib/ssh/connection.js index 0d387cd..3b2b30a 100644 --- a/lib/ssh/connection.js +++ b/lib/ssh/connection.js @@ -157,5 +157,8 @@ function buildSSHArgs(options) { if (options.key) { args.push('-i ' + options.key); } + if(options.strictHost) { + args.push('-o StrictHostKeyChecking=' + options.strictHost); + } return args; } diff --git a/test/unit/ssh/connection.js b/test/unit/ssh/connection.js index 4a71c42..c0a260a 100644 --- a/test/unit/ssh/connection.js +++ b/test/unit/ssh/connection.js @@ -138,6 +138,18 @@ describe('SSH Connection', function () { 'ssh -p 12345 -i /path/to/key user@host "my-command -x"' ); }); + + it('should use StrictHostKeyChecking if present', function () { + connection = new Connection({ + remote: 'user@host', + logger: logger, + strictHost: 'no' + }); + connection.run('my-command -x', function () {}); + expect(childProcess.exec).to.be.calledWith( + 'ssh -o StrictHostKeyChecking=no user@host "my-command -x"' + ); + }); }); describe('#copy', function () { @@ -193,6 +205,17 @@ describe('SSH Connection', function () { connection.copy('/src/dir', '/dest/dir', done); expect(childProcess.exec).to.be.calledWith('rsync -az -e "ssh -p 12345 -i /path/to/key" /src/dir user@host:/dest/dir'); }); + + it('should use StrictHostKeyChecking if present', function (done) { + connection = new Connection({ + remote: 'user@host', + logger: logger, + strictHost: 'yes' + }); + connection.copy('/src/dir', '/dest/dir', done); + expect(childProcess.exec).to.be.calledWith('rsync -az -e "ssh -o StrictHostKeyChecking=yes" /src/dir user@host:/dest/dir'); + }); + }); });