Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test: allow testing uid and gid separately
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 committed Jan 9, 2017
commit b9abeeccc0c7af9d33cdb7865b01ff8587962e5f
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);
}