Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add check for root user #19850

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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