test: Errors when running tests as root `sudo make test`

  • Version: master
  • Platform: 16.04.1, Ubuntu
  • Subsystem: test

When running tests as root, sudo make test I get the following errors

Error 1 -

=== release test-child-process-spawnsync-validation-errors ===                 
Path: parallel/test-child-process-spawnsync-validation-errors
Mismatched innerFn function calls. Expected exactly 62, actual 42.
    at Object.exports.mustCall (/home/divyanshu/programming/node/test/common/index.js:427:10)
    at Object.expectsError (/home/divyanshu/programming/node/test/common/index.js:717:18)
    at Object.<anonymous> (/home/divyanshu/programming/node/test/parallel/test-child-process-spawnsync-validation-errors.js:14:12)
    at Module._compile (internal/modules/cjs/loader.js:677:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:688:10)
    at Module.load (internal/modules/cjs/loader.js:588:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:527:12)
    at Function.Module._load (internal/modules/cjs/loader.js:519:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:718:10)
Command: out/Release/node /home/divyanshu/programming/node/test/parallel/test-child-process-spawnsync-validation-errors.js

Error 2

=== release test-fs-access ===                                                 
Path: parallel/test-fs-access
fs.js:110
    throw err;
    ^

Error: EACCES: permission denied, access '/home/divyanshu/programming/node/test/parallel/test-fs-access.js'
    at Object.fs.accessSync (fs.js:200:3)
    at Object.<anonymous> (/home/divyanshu/programming/node/test/parallel/test-fs-access.js:116:4)
    at Module._compile (internal/modules/cjs/loader.js:677:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:688:10)
    at Module.load (internal/modules/cjs/loader.js:588:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:527:12)
    at Function.Module._load (internal/modules/cjs/loader.js:519:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:718:10)
    at startup (internal/bootstrap/node.js:225:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
Command: out/Release/node /home/divyanshu/programming/node/test/parallel/test-fs-access.js

Error 3

=== release test-process-geteuid-getegid ===                                   
Path: parallel/test-process-geteuid-getegid
/home/divyanshu/programming/node/test/parallel/test-process-geteuid-getegid.js:41
process.setegid('nobody');
        ^

Error: setegid group id does not exist
    at Object.<anonymous> (/home/divyanshu/programming/node/test/parallel/test-process-geteuid-getegid.js:41:9)
    at Module._compile (internal/modules/cjs/loader.js:677:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:688:10)
    at Module.load (internal/modules/cjs/loader.js:588:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:527:12)
    at Function.Module._load (internal/modules/cjs/loader.js:519:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:718:10)
    at startup (internal/bootstrap/node.js:225:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
Command: out/Release/node /home/divyanshu/programming/node/test/parallel/test-process-geteuid-getegid.js

Error 4

=== release test-process-setuid-setgid ===                                     
Path: parallel/test-process-setuid-setgid
/home/divyanshu/programming/node/test/parallel/test-process-setuid-setgid.js:60
process.setgid('nobody');
        ^

Error: setgid group id does not exist
    at Object.<anonymous> (/home/divyanshu/programming/node/test/parallel/test-process-setuid-setgid.js:60:9)
    at Module._compile (internal/modules/cjs/loader.js:677:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:688:10)
    at Module.load (internal/modules/cjs/loader.js:588:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:527:12)
    at Function.Module._load (internal/modules/cjs/loader.js:519:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:718:10)
    at startup (internal/bootstrap/node.js:225:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
Command: out/Release/node /home/divyanshu/programming/node/test/parallel/test-process-setuid-setgid.js

Error 1 is covered in Issue 19371

Error 3 and Error 4

The lines that throw these errors in the respective files

On reading further, I figured that this is because the standard nobody group in UNIX systems is named nogroup in Ubuntu.

When I changed the lines which were throwing errors to the following - which checks if nobody group does not exist on the UNIX system it tries to set the group to nogroup before throwing an error

try {
  process.setegid('nobody');
} catch (err) {
  if (err.message !== 'setegid group id does not exist') {
    throw err;
  } else {
    process.setegid('nogroup');
  }
}

and

try {
  process.setgid('nobody');
} catch (err) {
  if (err.message !== 'setgid group id does not exist') {
    throw err;
  } else {
    process.setgid('nogroup');
  }
}

respectively in the two files, Errors 3 and 4 were resolved

I'd like to work on Errors 3 and 4 and if the changes I have made make sense I'd like to submit a PR for it