mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 16:22:29 +00:00

3c92ca2b5c
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>
50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
'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);
|