1'use strict'; 2 3const common = require('../common'); 4const assert = require('assert'); 5 6if (common.isWindows) { 7 assert.strictEqual(process.geteuid, undefined); 8 assert.strictEqual(process.getegid, undefined); 9 assert.strictEqual(process.seteuid, undefined); 10 assert.strictEqual(process.setegid, undefined); 11 return; 12} 13 14if (!common.isMainThread) 15 return; 16 17assert.throws(() => { 18 process.seteuid({}); 19}, { 20 code: 'ERR_INVALID_ARG_TYPE', 21 message: 'The "id" argument must be one of type number or string. ' + 22 'Received an instance of Object' 23}); 24 25assert.throws(() => { 26 process.seteuid('fhqwhgadshgnsdhjsdbkhsdabkfabkveyb'); 27}, { 28 code: 'ERR_UNKNOWN_CREDENTIAL', 29 message: 'User identifier does not exist: fhqwhgadshgnsdhjsdbkhsdabkfabkveyb' 30}); 31 32// IBMi does not support below operations. 33if (common.isIBMi) 34 return; 35 36// If we're not running as super user... 37if (process.getuid() !== 0) { 38 // Should not throw. 39 process.getegid(); 40 process.geteuid(); 41 42 assert.throws(() => { 43 process.setegid('nobody'); 44 }, /(?:EPERM, .+|Group identifier does not exist: nobody)$/); 45 46 assert.throws(() => { 47 process.seteuid('nobody'); 48 }, /^Error: (?:EPERM, .+|User identifier does not exist: nobody)$/); 49 50 return; 51} 52 53// If we are running as super user... 54const oldgid = process.getegid(); 55try { 56 process.setegid('nobody'); 57} catch (err) { 58 if (err.message !== 'Group identifier does not exist: nobody') { 59 throw err; 60 } else { 61 process.setegid('nogroup'); 62 } 63} 64const newgid = process.getegid(); 65assert.notStrictEqual(newgid, oldgid); 66 67const olduid = process.geteuid(); 68process.seteuid('nobody'); 69const newuid = process.geteuid(); 70assert.notStrictEqual(newuid, olduid); 71