Skip to content

Commit 4162115

Browse files
danbevjasnell
authored andcommitted
test: add check for root user
Currently this test fails if run as the root user: Mismatched innerFn function calls. Expected exactly 62, actual 42. The motivation for this is that when building node in a docker container it is convenient to be able to build as root. PR-URL: #19850 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent d6ce4ec commit 4162115

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

test/parallel/test-child-process-spawnsync-validation-errors.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,11 @@ const common = require('../common');
33
const assert = require('assert');
44
const spawnSync = require('child_process').spawnSync;
55
const signals = process.binding('constants').os.signals;
6+
const rootUser = common.isWindows ? false : process.getuid() === 0;
67

7-
let invalidArgTypeError;
8-
let invalidArgTypeErrorCount = 62;
9-
10-
if (common.isWindows) {
11-
invalidArgTypeError =
12-
common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError }, 42);
13-
} else {
14-
invalidArgTypeError =
15-
common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError },
16-
invalidArgTypeErrorCount);
17-
}
8+
const invalidArgTypeError = common.expectsError(
9+
{ code: 'ERR_INVALID_ARG_TYPE', type: TypeError },
10+
common.isWindows || rootUser ? 42 : 62);
1811

1912
const invalidRangeError =
2013
common.expectsError({ code: 'ERR_OUT_OF_RANGE', type: RangeError }, 20);
@@ -64,7 +57,7 @@ function fail(option, value, message) {
6457
if (!common.isWindows) {
6558
{
6659
// Validate the uid option
67-
if (process.getuid() !== 0) {
60+
if (!rootUser) {
6861
pass('uid', undefined);
6962
pass('uid', null);
7063
pass('uid', process.getuid());
@@ -78,9 +71,6 @@ if (!common.isWindows) {
7871
fail('uid', Infinity, invalidArgTypeError);
7972
fail('uid', 3.1, invalidArgTypeError);
8073
fail('uid', -3.1, invalidArgTypeError);
81-
} else {
82-
// Decrement invalidArgTypeErrorCount if validation isn't possible
83-
invalidArgTypeErrorCount -= 10;
8474
}
8575
}
8676

@@ -100,9 +90,6 @@ if (!common.isWindows) {
10090
fail('gid', Infinity, invalidArgTypeError);
10191
fail('gid', 3.1, invalidArgTypeError);
10292
fail('gid', -3.1, invalidArgTypeError);
103-
} else {
104-
// Decrement invalidArgTypeErrorCount if validation isn't possible
105-
invalidArgTypeErrorCount -= 10;
10693
}
10794
}
10895
}

0 commit comments

Comments
 (0)