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 <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
cjihrig authored and MylesBorins committed Mar 9, 2017
1 parent 2f1d231 commit f43a876
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 f43a876

Please sign in to comment.