From b4e86f12f8a78356f0f1f94187bd6a3b2e2ea10b Mon Sep 17 00:00:00 2001 From: Divyanshu Singh Date: Mon, 2 Apr 2018 22:10:01 +0530 Subject: [PATCH] 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 Reviewed-By: Gireesh Punathil Reviewed-By: Luigi Pinca --- test/parallel/test-process-uid-gid.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-process-uid-gid.js b/test/parallel/test-process-uid-gid.js index d3aac29decf0a6..d044c45a32783d 100644 --- a/test/parallel/test-process-uid-gid.js +++ b/test/parallel/test-process-uid-gid.js @@ -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);