Skip to content

Commit 7b19f05

Browse files
cjihrigMylesBorins
authored andcommitted
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 <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 198b7b7 commit 7b19f05

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22
const common = require('../common');
33
const assert = require('assert');
44
const spawn = require('child_process').spawn;
5-
6-
if (!common.isWindows && process.getuid() === 0) {
7-
common.skip('as this test should not be run as `root`');
8-
return;
9-
}
10-
115
const expectedError = common.isWindows ? /\bENOTSUP\b/ : /\bEPERM\b/;
126

13-
assert.throws(() => {
14-
spawn('echo', ['fhqwhgads'], {uid: 0});
15-
}, expectedError);
7+
if (common.isWindows || process.getuid() !== 0) {
8+
assert.throws(() => {
9+
spawn('echo', ['fhqwhgads'], {uid: 0});
10+
}, expectedError);
11+
}
1612

17-
assert.throws(() => {
18-
spawn('echo', ['fhqwhgads'], {gid: 0});
19-
}, expectedError);
13+
if (common.isWindows || !process.getgroups().some((gid) => gid === 0)) {
14+
assert.throws(() => {
15+
spawn('echo', ['fhqwhgads'], {gid: 0});
16+
}, expectedError);
17+
}

0 commit comments

Comments
 (0)