Comparing version 1.4.2 to 1.5.0
@@ -56,3 +56,4 @@ var _ = require('lodash'); | ||
// In sudo mode, we use a TTY channel. | ||
var args = /^sudo/.exec(command) ? ['-tt'] : []; | ||
var isSudo = /^sudo/.exec(command); | ||
var args = isSudo ? ['-tt'] : []; | ||
args.push.apply(args, connection.sshArgs); | ||
@@ -64,2 +65,10 @@ args.push(remote.format(connection.remote)); | ||
if (_.isString(connection.options.asUser)) { | ||
if (isSudo) { | ||
command = command.replace('sudo', ''); | ||
} | ||
command = 'sudo -u ' + connection.options.asUser + command; | ||
} | ||
// Complete arguments. | ||
@@ -66,0 +75,0 @@ args = ['ssh'].concat(args).concat(['"' + command + '"']); |
{ | ||
"name": "ssh-pool", | ||
"version": "1.4.2", | ||
"version": "1.5.0", | ||
"description": "Run remote commands over a pool of server using SSH.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -173,2 +173,31 @@ var rewire = require('rewire'); | ||
describe('#run asUser', function () { | ||
var connection; | ||
beforeEach(function () { | ||
connection = new Connection({ | ||
remote: 'user@host', | ||
asUser: 'test' | ||
}); | ||
}); | ||
it('should handle sudo as user correctly', function (done) { | ||
connection.run('sudo my-command -x', {cwd: '/root'}, done); | ||
expect(childProcess.exec).to.be.calledWith( | ||
'ssh -tt user@host "sudo -u test my-command -x"', | ||
{cwd: '/root', maxBuffer: 1000 * 1024} | ||
); | ||
}); | ||
it('should handle sudo as user without double sudo', function (done) { | ||
connection.run('sudo my-command -x', {cwd: '/root'}, done); | ||
expect(childProcess.exec).to.be.calledWith( | ||
'ssh -tt user@host "sudo -u test my-command -x"', | ||
{cwd: '/root', maxBuffer: 1000 * 1024} | ||
); | ||
}); | ||
}); | ||
describe('#copy', function () { | ||
@@ -175,0 +204,0 @@ var connection; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54865
1415