Skip to content

Commit

Permalink
test: add get/set effective uid/gid tests
Browse files Browse the repository at this point in the history
3c92ca2 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: #14091
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Claudio Rodriguez <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
evanlucas authored and Fishrock123 committed Jul 19, 2017
1 parent ef3d622 commit 8887a57
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions test/parallel/test-process-geteuid-getegid.js
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 8887a57

Please sign in to comment.