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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
42d8976dff
commit
398968297a
@ -3,18 +3,11 @@ const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const spawnSync = require('child_process').spawnSync;
|
||||
const signals = process.binding('constants').os.signals;
|
||||
const rootUser = common.isWindows ? false : process.getuid() === 0;
|
||||
|
||||
let invalidArgTypeError;
|
||||
let invalidArgTypeErrorCount = 62;
|
||||
|
||||
if (common.isWindows) {
|
||||
invalidArgTypeError =
|
||||
common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError }, 42);
|
||||
} else {
|
||||
invalidArgTypeError =
|
||||
common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError },
|
||||
invalidArgTypeErrorCount);
|
||||
}
|
||||
const invalidArgTypeError = common.expectsError(
|
||||
{ code: 'ERR_INVALID_ARG_TYPE', type: TypeError },
|
||||
common.isWindows || rootUser ? 42 : 62);
|
||||
|
||||
const invalidRangeError =
|
||||
common.expectsError({ code: 'ERR_OUT_OF_RANGE', type: RangeError }, 20);
|
||||
@ -64,7 +57,7 @@ function fail(option, value, message) {
|
||||
if (!common.isWindows) {
|
||||
{
|
||||
// Validate the uid option
|
||||
if (process.getuid() !== 0) {
|
||||
if (!rootUser) {
|
||||
pass('uid', undefined);
|
||||
pass('uid', null);
|
||||
pass('uid', process.getuid());
|
||||
@ -78,9 +71,6 @@ if (!common.isWindows) {
|
||||
fail('uid', Infinity, invalidArgTypeError);
|
||||
fail('uid', 3.1, invalidArgTypeError);
|
||||
fail('uid', -3.1, invalidArgTypeError);
|
||||
} else {
|
||||
// Decrement invalidArgTypeErrorCount if validation isn't possible
|
||||
invalidArgTypeErrorCount -= 10;
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,9 +90,6 @@ if (!common.isWindows) {
|
||||
fail('gid', Infinity, invalidArgTypeError);
|
||||
fail('gid', 3.1, invalidArgTypeError);
|
||||
fail('gid', -3.1, invalidArgTypeError);
|
||||
} else {
|
||||
// Decrement invalidArgTypeErrorCount if validation isn't possible
|
||||
invalidArgTypeErrorCount -= 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user