Skip to content

Commit

Permalink
test: add check for root user
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
danbev authored and jasnell committed Apr 16, 2018
1 parent d6ce4ec commit 4162115
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions test/parallel/test-child-process-spawnsync-validation-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand All @@ -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;
}
}

Expand All @@ -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;
}
}
}
Expand Down

0 comments on commit 4162115

Please sign in to comment.