diff options
author | Evan Lucas <evanlucas@me.com> | 2017-07-05 13:43:56 -0500 |
---|---|---|
committer | Jeremiah Senkpiel <fishrock123@rocketmail.com> | 2017-07-19 15:02:23 -0400 |
commit | 8887a5766d26e80a00167b936c3e7f82a7cb7667 (patch) | |
tree | 182eb8e155fec5a20a9f25bcdef62f81d00546e0 /test/parallel/test-process-geteuid-getegid.js | |
parent | ef3d6227a39b8d21b64a0d86c325270c8fdfb176 (diff) | |
download | node-new-8887a5766d26e80a00167b936c3e7f82a7cb7667.tar.gz |
test: add get/set effective uid/gid tests
3c92ca2b5c1aea283efebd50b27e2a256adf5f7f should have had tests
to go along with it. This adds tests for the following functions:
* `process.geteuid()`
* `process.seteuid()`
* `process.getegid()`
* `process.setegid()`
PR-URL: https://github.com/nodejs/node/pull/14091
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Claudio Rodriguez <cjrodr@yahoo.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-process-geteuid-getegid.js')
-rw-r--r-- | test/parallel/test-process-geteuid-getegid.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/parallel/test-process-geteuid-getegid.js b/test/parallel/test-process-geteuid-getegid.js new file mode 100644 index 0000000000..8dab52389b --- /dev/null +++ b/test/parallel/test-process-geteuid-getegid.js @@ -0,0 +1,49 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); + +if (common.isWindows) { + assert.strictEqual(process.geteuid, undefined); + assert.strictEqual(process.getegid, undefined); + assert.strictEqual(process.seteuid, undefined); + assert.strictEqual(process.setegid, undefined); + return; +} + +assert.throws(() => { + process.seteuid({}); +}, /^TypeError: seteuid argument must be a number or string$/); + +assert.throws(() => { + process.seteuid('fhqwhgadshgnsdhjsdbkhsdabkfabkveybvf'); +}, /^Error: seteuid user id does not exist$/); + +// If we're not running as super user... +if (process.getuid() !== 0) { + assert.doesNotThrow(() => { + process.getegid(); + process.geteuid(); + }); + + assert.throws(() => { + process.setegid('nobody'); + }, /^Error: (?:EPERM, .+|setegid group id does not exist)$/); + + assert.throws(() => { + process.seteuid('nobody'); + }, /^Error: (?:EPERM, .+|seteuid user id does not exist)$/); + + return; +} + +// If we are running as super user... +const oldgid = process.getegid(); +process.setegid('nobody'); +const newgid = process.getegid(); +assert.notStrictEqual(newgid, oldgid); + +const olduid = process.geteuid(); +process.seteuid('nobody'); +const newuid = process.geteuid(); +assert.notStrictEqual(newuid, olduid); |