Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add get/set effective uid/gid tests #14091

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);