From 88ad186575c27a3b6764828d21f2076a7099e8f5 Mon Sep 17 00:00:00 2001 From: Divyanshu Singh Date: Mon, 2 Apr 2018 22:55:31 +0530 Subject: [PATCH] test: resolve process.setegid error for nobody 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. Refs: https://github.com/nodejs/node/issues/19594 --- test/parallel/test-process-geteuid-getegid.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-process-geteuid-getegid.js b/test/parallel/test-process-geteuid-getegid.js index 41e37874a41b59..adae58abebdfb7 100644 --- a/test/parallel/test-process-geteuid-getegid.js +++ b/test/parallel/test-process-geteuid-getegid.js @@ -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);