From 439a9e629fbdaf1941bbfd9c8624a4b8c61a4cb1 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Fri, 6 Apr 2018 12:22:03 +0200 Subject: [PATCH] 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 Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Richard Lau --- ...ild-process-spawnsync-validation-errors.js | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/test/parallel/test-child-process-spawnsync-validation-errors.js b/test/parallel/test-child-process-spawnsync-validation-errors.js index 0a1cc2ca577307..0b0df347e2630f 100644 --- a/test/parallel/test-child-process-spawnsync-validation-errors.js +++ b/test/parallel/test-child-process-spawnsync-validation-errors.js @@ -3,6 +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; + +const invalidArgTypeError = common.expectsError( + { code: 'ERR_INVALID_ARG_TYPE', type: TypeError }, + common.isWindows || rootUser ? 42 : 62); function pass(option, value) { // Run the command with the specified option. Since it's not a real command, @@ -53,43 +58,39 @@ function fail(option, value, message) { if (!common.isWindows) { { // Validate the uid option - if (process.getuid() !== 0) { - const err = /^TypeError: "uid" must be an integer$/; - + if (!rootUser) { pass('uid', undefined); pass('uid', null); pass('uid', process.getuid()); - fail('uid', __dirname, err); - fail('uid', true, err); - fail('uid', false, err); - fail('uid', [], err); - fail('uid', {}, err); - fail('uid', common.mustNotCall(), err); - fail('uid', NaN, err); - fail('uid', Infinity, err); - fail('uid', 3.1, err); - fail('uid', -3.1, err); + fail('uid', __dirname, invalidArgTypeError); + fail('uid', true, invalidArgTypeError); + fail('uid', false, invalidArgTypeError); + fail('uid', [], invalidArgTypeError); + fail('uid', {}, invalidArgTypeError); + fail('uid', common.mustNotCall(), invalidArgTypeError); + fail('uid', NaN, invalidArgTypeError); + fail('uid', Infinity, invalidArgTypeError); + fail('uid', 3.1, invalidArgTypeError); + fail('uid', -3.1, invalidArgTypeError); } } { // Validate the gid option if (process.getgid() !== 0) { - const err = /^TypeError: "gid" must be an integer$/; - pass('gid', undefined); pass('gid', null); pass('gid', process.getgid()); - fail('gid', __dirname, err); - fail('gid', true, err); - fail('gid', false, err); - fail('gid', [], err); - fail('gid', {}, err); - fail('gid', common.mustNotCall(), err); - fail('gid', NaN, err); - fail('gid', Infinity, err); - fail('gid', 3.1, err); - fail('gid', -3.1, err); + fail('gid', __dirname, invalidArgTypeError); + fail('gid', true, invalidArgTypeError); + fail('gid', false, invalidArgTypeError); + fail('gid', [], invalidArgTypeError); + fail('gid', {}, invalidArgTypeError); + fail('gid', common.mustNotCall(), invalidArgTypeError); + fail('gid', NaN, invalidArgTypeError); + fail('gid', Infinity, invalidArgTypeError); + fail('gid', 3.1, invalidArgTypeError); + fail('gid', -3.1, invalidArgTypeError); } } }