Browse Source

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: https://github.com/nodejs/node/issues/10646
PR-URL: https://github.com/nodejs/node/pull/10647
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
v6.x
cjihrig 8 years ago
committed by Myles Borins
parent
commit
f43a8765a2
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 22
      test/parallel/test-child-process-uid-gid.js

22
test/parallel/test-child-process-uid-gid.js

@ -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);
}

Loading…
Cancel
Save