Permalink
Browse files

[plugin] setuid [fix] tests

  • Loading branch information...
1 parent 19decba commit fc6e1214edef6cee5ee21ca079a39022f9fc0d8d @bmeck bmeck committed Apr 16, 2012
Showing with 18 additions and 42 deletions.
  1. +3 −2 bin/carapace
  2. +4 −0 lib/cli.js
  3. +6 −25 lib/net.js
  4. +0 −8 lib/plugins/chdir.js
  5. +2 −4 test/net/net-multiple-servers-test.js
  6. +3 −3 test/spawn/local-run-test.js
View
@@ -1,6 +1,7 @@
#!/usr/bin/env node
var path = require('path'),
+ _send = process.send || function(){},
async = require('async'),
carapace = require('../lib/carapace');
@@ -66,11 +67,11 @@ function configure (next) {
function runAndReport () {
carapace.run(carapace.script, true, function () {
- console.log('carapace has wrapped: ' + carapace.script);
+ _send.call(process, 'carapace has wrapped: ' + carapace.script);
function logArray (array, msg, delim) {
return array && array.length
- ? console.log(msg + array.join(delim))
+ ? _send.call(process, msg + array.join(delim))
@mmalecki

mmalecki May 25, 2012

Contributor

Why these console.log => _send changes?

@indexzero

indexzero May 25, 2012

Owner

Yeah, that seems wrong to me. Doesnt send only take JSON?

@bmeck

bmeck May 25, 2012

Contributor

There were issues where users were seeing this message in logs. Send can take any valid Json in this case for now haibu ignores these but sees the messages. This seems to have been clobbered into a single commit.

: null;
}
View
@@ -23,6 +23,10 @@ var defaultOptions = exports.defaultOptions = {
description: 'Path to the chroot jail to use',
string: true
},
+ setuid: {
+ description: 'User to run as',
+ string: true
+ },
chdir: {
description: 'Default path to change to in the jail',
string: true,
View
@@ -20,26 +20,6 @@ function toPort(x) {
}
//
-// ### function nextPort (port)
-// #### @port {Number} Port to increment from.
-// Gets the next port in sequence from the
-// specified `port`.
-//
-function nextPort(port) {
- return 0;
-
- //
- // Find the next port that we are not supposed to ignore or cause errors on
- //
- var unavailable = carapace.ports.ignore.concat(carapace.ports.throw);
- do {
- port = port + 1;
- } while (unavailable.indexOf(port) !== -1);
-
- return port;
-}
-
-//
// ### functon reservedPort
// #### @desired {Number} Desired port to bind to.
// Helper function which will emit an error if the
@@ -214,7 +194,7 @@ exports._listen2 = function overrideNet() {
// Since desired is not on a throwing port
// we want to skip ports in both throw and ignore
//
- port || (port = nextPort(port));
+ port || (port = 0);
//
// We rely on `error` event to check if address it taken/available, however
@@ -268,7 +248,7 @@ exports._listen2 = function overrideNet() {
carapace.emit('port', {
id: carapace.id,
addr: address,
- port: port,
+ port: self.address().port,
desired: desired
});
@@ -296,10 +276,11 @@ exports._listen2 = function overrideNet() {
try { self.close() }
catch (ex) { }
- return self.emit('error', err);
+ self.emit('error', err);
+ }
+ else {
+ ourListen.call(self, '0.0.0.0', 0, addressType, desired);
}
-
- ourListen.call(self, address, nextPort(port), addressType, desired);
}
self.once('listening', onListen);
View
@@ -6,17 +6,9 @@ module.exports = function chdirPlugin(carapace) {
try { process.chdir(path.resolve(value)) }
catch (ex) { return done ? done(ex) : null }
- //
- // Append the request value to be the default dir
- // this should ALWAYS overwrite and previous value
- //
carapace.cli.defaultOptions['chdir'].default = value;
carapace.cli.defaultOptions['chdir'].required = true;
return done ? done() : null;
};
-
- carapace.on('chdir::path', function () {
- carapace.chdir.apply(this, [].slice.call(arguments, 1));
- });
}
};
@@ -54,12 +54,10 @@ vows.describe('carapace/net/dolisten').addBatch({
assert.equal(info.exitCode, 0);
},
"and 3x emit the `port` event with the correct port": function (_, info, child) {
- var desired = testPort,
- basePort = desired;
+ var desired = testPort;
assert.equal(info.events.length, 3);
- info.events.forEach(function (event) {
- assert.equal(event.info.port, basePort++);
+ info.events.forEach(function (event, index) {
assert.equal(event.info.desired, desired);
});
}
@@ -29,11 +29,11 @@ vows.describe('carapace/spawn/local').addBatch({
},
"with the correct port": function (err, info) {
assert.equal(carapace.event, 'port');
- assert.equal(info.port, 1337);
+ assert.equal(info.desired, 1337);
},
"should correctly start the HTTP server": {
- topic: function () {
- request({ uri: 'http://localhost:' + carapace._module.exports.port }, this.callback);
+ topic: function (info) {
+ request({ uri: 'http://localhost:' + info.port }, this.callback);
},
"that responds with a cwd": function (err, res, body) {
assert.equal(body, process.cwd());

0 comments on commit fc6e121

Please sign in to comment.