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 lpinca committed Apr 21, 2018
1 parent 2a88f02 commit cc8a33e
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

1 comment on commit cc8a33e

@gimyjendirx
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

``

Please sign in to comment.