Skip to content

Commit

Permalink
test: resolve process.setgid() error on Ubuntu
Browse files Browse the repository at this point in the history
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: #19755
Refs: #19594
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
dsinecos authored and jasnell committed Apr 23, 2018
1 parent 18f41dd commit b4e86f1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion test/parallel/test-process-uid-gid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b4e86f1

Please sign in to comment.