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: #10646
PR-URL: #10647
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
  • Loading branch information
cjihrig authored and italoacasas committed Jan 27, 2017
1 parent 4aa32c1 commit 1329eb4
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 1329eb4

Please sign in to comment.