|  | 
|  | 1 | +'use strict'; | 
|  | 2 | + | 
|  | 3 | +const common = require('../common'); | 
|  | 4 | +const assert = require('assert'); | 
|  | 5 | + | 
|  | 6 | +if (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 | + | 
|  | 14 | +assert.throws(() => { | 
|  | 15 | +  process.seteuid({}); | 
|  | 16 | +}, /^TypeError: seteuid argument must be a number or string$/); | 
|  | 17 | + | 
|  | 18 | +assert.throws(() => { | 
|  | 19 | +  process.seteuid('fhqwhgadshgnsdhjsdbkhsdabkfabkveybvf'); | 
|  | 20 | +}, /^Error: seteuid user id does not exist$/); | 
|  | 21 | + | 
|  | 22 | +// If we're not running as super user... | 
|  | 23 | +if (process.getuid() !== 0) { | 
|  | 24 | +  assert.doesNotThrow(() => { | 
|  | 25 | +    process.getegid(); | 
|  | 26 | +    process.geteuid(); | 
|  | 27 | +  }); | 
|  | 28 | + | 
|  | 29 | +  assert.throws(() => { | 
|  | 30 | +    process.setegid('nobody'); | 
|  | 31 | +  }, /^Error: (?:EPERM, .+|setegid group id does not exist)$/); | 
|  | 32 | + | 
|  | 33 | +  assert.throws(() => { | 
|  | 34 | +    process.seteuid('nobody'); | 
|  | 35 | +  }, /^Error: (?:EPERM, .+|seteuid user id does not exist)$/); | 
|  | 36 | + | 
|  | 37 | +  return; | 
|  | 38 | +} | 
|  | 39 | + | 
|  | 40 | +// If we are running as super user... | 
|  | 41 | +const oldgid = process.getegid(); | 
|  | 42 | +process.setegid('nobody'); | 
|  | 43 | +const newgid = process.getegid(); | 
|  | 44 | +assert.notStrictEqual(newgid, oldgid); | 
|  | 45 | + | 
|  | 46 | +const olduid = process.geteuid(); | 
|  | 47 | +process.seteuid('nobody'); | 
|  | 48 | +const newuid = process.geteuid(); | 
|  | 49 | +assert.notStrictEqual(newuid, olduid); | 
0 commit comments