test: resolve process.setgid() error on Ubuntu

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

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

PR-URL: https://github.com/nodejs/node/pull/19755
Refs: https://github.com/nodejs/node/issues/19594
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Divyanshu Singh authored and James M Snell committed 2018-04-23 07:08:53 -07:00
1 parent 18f41dda90
commit b4e86f12f8
1 file changed
+8 -1
+8 -1
View File
@@ -61,7 +61,14 @@ if (process.getuid() !== 0) {
// If we are running as super user...
const oldgid = process.getgid();
process.setgid('nobody');
try {
process.setgid('nobody');
} catch (err) {
if (err.message !== 'setgid group id does not exist') {
throw err;
}
process.setgid('nogroup');
}
const newgid = process.getgid();
assert.notStrictEqual(newgid, oldgid);