Skip to content

Commit

Permalink
test: allow testing uid and gid separately
Browse files Browse the repository at this point in the history
This commit lets the uid and gid options of spawn() to be
tested independently of one another based on the user's uid
and gid.

Fixes: nodejs#10646
PR-URL: nodejs#10647
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
  • Loading branch information
cjihrig authored and italoacasas committed Jan 25, 2017
1 parent 2b3dab0 commit 1867a01
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions test/parallel/test-child-process-uid-gid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;

if (!common.isWindows && process.getuid() === 0) {
common.skip('as this test should not be run as `root`');
return;
}

const expectedError = common.isWindows ? /\bENOTSUP\b/ : /\bEPERM\b/;

assert.throws(() => {
spawn('echo', ['fhqwhgads'], {uid: 0});
}, expectedError);
if (common.isWindows || process.getuid() !== 0) {
assert.throws(() => {
spawn('echo', ['fhqwhgads'], {uid: 0});
}, expectedError);
}

assert.throws(() => {
spawn('echo', ['fhqwhgads'], {gid: 0});
}, expectedError);
if (common.isWindows || !process.getgroups().some((gid) => gid === 0)) {
assert.throws(() => {
spawn('echo', ['fhqwhgads'], {gid: 0});
}, expectedError);
}

0 comments on commit 1867a01

Please sign in to comment.