0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

test: resolve process.setegid error on Ubuntu

When the tests are run as root in Ubuntu, process.setegid is called with
'nobody' as an argument. This throws an error in Ubuntu. This is because
in Ubuntu the equivalent of 'nobody' group is named as 'nogroup'.

This commit sets egid to 'nobody' first and if it throws a `group id
does not exist` error, it attempts to set egid to 'nogroup'. If it still
causes an error, the error is thrown.

PR-URL: https://github.com/nodejs/node/pull/19757
Refs: https://github.com/nodejs/node/issues/19594
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Divyanshu Singh 2018-04-02 22:55:31 +05:30 committed by Anna Henningsen
parent f8b3774d85
commit 3dc5404105

View File

@ -38,7 +38,15 @@ if (process.getuid() !== 0) {
// If we are running as super user...
const oldgid = process.getegid();
process.setegid('nobody');
try {
process.setegid('nobody');
} catch (err) {
if (err.message !== 'setegid group id does not exist') {
throw err;
} else {
process.setegid('nogroup');
}
}
const newgid = process.getegid();
assert.notStrictEqual(newgid, oldgid);