From 9e4b0dd0c31b34a0382aa40b8f56b5347538fe3a Mon Sep 17 00:00:00 2001 From: Divyanshu Singh Date: Mon, 2 Apr 2018 22:10:01 +0530 Subject: [PATCH 1/2] test: resolve process.setgid error for group 'nobody' 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. This 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. Refs: https://github.com/nodejs/node/issues/19594 --- test/parallel/test-process-uid-gid.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-process-uid-gid.js b/test/parallel/test-process-uid-gid.js index d3aac29decf0a6..83b2b7a638d7be 100644 --- a/test/parallel/test-process-uid-gid.js +++ b/test/parallel/test-process-uid-gid.js @@ -61,7 +61,15 @@ 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; + } else { + process.setgid('nogroup'); + } +} const newgid = process.getgid(); assert.notStrictEqual(newgid, oldgid); From 2129edfda275901f16295dcf1333d08a17f99a42 Mon Sep 17 00:00:00 2001 From: Divyanshu Singh Date: Tue, 10 Apr 2018 12:51:50 +0530 Subject: [PATCH 2/2] test: remove else block Else block removed as the `throw` in the preceding block makes it redundant Refs: https://github.com/nodejs/node/issues/19594 --- test/parallel/test-process-uid-gid.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/parallel/test-process-uid-gid.js b/test/parallel/test-process-uid-gid.js index 83b2b7a638d7be..d044c45a32783d 100644 --- a/test/parallel/test-process-uid-gid.js +++ b/test/parallel/test-process-uid-gid.js @@ -66,9 +66,8 @@ try { } catch (err) { if (err.message !== 'setgid group id does not exist') { throw err; - } else { - process.setgid('nogroup'); } + process.setgid('nogroup'); } const newgid = process.getgid(); assert.notStrictEqual(newgid, oldgid);