diff options
author | isaacs <i@izs.me> | 2011-01-10 18:20:12 -0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2011-01-11 13:54:51 -0800 |
commit | 435ece505897c8931548162a1ccc5389e3fc558c (patch) | |
tree | 06abab8d6f9da4537c861cc0d7078100e9d8d7d8 /test/disabled | |
parent | b92329667ff1f32a112e277bbb3cd6bc192c6f6d (diff) | |
download | node-new-435ece505897c8931548162a1ccc5389e3fc558c.tar.gz |
child_process: Support setting uid/gid by name
Diffstat (limited to 'test/disabled')
-rw-r--r-- | test/disabled/test-child-process-uid-gid.js | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/test/disabled/test-child-process-uid-gid.js b/test/disabled/test-child-process-uid-gid.js index 71513c0e0e..b63e2255d2 100644 --- a/test/disabled/test-child-process-uid-gid.js +++ b/test/disabled/test-child-process-uid-gid.js @@ -1,13 +1,20 @@ -// must be run as sudo, otherwise the gid/uid setting will fail. -var child_process = require("child_process"), - constants = require("constants"), - passwd = require("fs").readFileSync("/etc/passwd", "utf8"), - myUid = process.getuid(), - myGid = process.getgid(); +var assert = require("assert"); +var spawn = require("child_process").spawn; +var fs = require('fs'); + +var myUid = process.getuid(); +var myGid = process.getgid(); + +if (myUid != 0) { + console.error('must be run as root, otherwise the gid/uid setting will fail.'); + process.exit(1); +} // get a different user. // don't care who it is, as long as it's not root +var passwd = fs.readFileSync('/etc/passwd', 'utf8'); passwd = passwd.trim().split(/\n/); + for (var i = 0, l = passwd.length; i < l; i ++) { if (passwd[i].charAt(0) === "#") continue; passwd[i] = passwd[i].split(":"); @@ -20,22 +27,31 @@ for (var i = 0, l = passwd.length; i < l; i ++) { break; } } -if (!otherUid && !otherGid) throw new Error("failed getting passwd info."); +if (!otherUid && !otherGid) throw new Error('failed getting passwd info.'); -console.error("name, id, gid = %j", [otherName, otherUid, otherGid]); +console.error('name, id, gid = %j', [otherName, otherUid, otherGid]); -var whoNumber = child_process.spawn("id",[], {uid:otherUid,gid:otherGid}), - assert = require("assert"); +var whoNumber = spawn('id', [], { uid: otherUid, gid: otherGid }); +var whoName = spawn('id', [], { uid: otherName, gid: otherGid }); -whoNumber.stdout.buf = "byNumber:"; -whoNumber.stdout.on("data", onData); +whoNumber.stdout.buf = 'byNumber:'; +whoName.stdout.buf = 'byName:'; +whoNumber.stdout.on('data', onData); +whoName.stdout.on('data', onData); function onData (c) { this.buf += c; } whoNumber.on("exit", onExit); +whoName.on("exit", onExit); + function onExit (code) { var buf = this.stdout.buf; console.log(buf); - var expr = new RegExp("^byNumber:uid="+otherUid+"\\("+ - otherName+"\\) gid="+otherGid+"\\("); - assert.ok(buf.match(expr), "uid and gid should match "+otherName); + var expr = new RegExp("^(byName|byNumber):uid=" + + otherUid + + "\\(" + + otherName + + "\\) gid=" + + otherGid + + "\\("); + assert.ok(buf.match(expr), "uid and gid should match " + otherName); } |