mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
Instead of exposing internals of async_hooks & async_wrap throughout the code base, create necessary helper methods within the internal async_hooks that allows easy usage by Node.js internals. This stops every single internal user of async_hooks from importing a ton of functions, constants and internal Aliased Buffers from C++ async_wrap. Adds functions initHooksExist, afterHooksExist, and destroyHooksExist to determine whether the related emit methods need to be triggered. Adds clearDefaultTriggerAsyncId and clearAsyncIdStack on the JS side as an alternative to always calling C++. Moves async_id_symbol and trigger_async_id_symbol to internal async_hooks as they are never used in C++. Renames newUid to newAsyncId for added clarity of its purpose. Adjusts usage throughout the codebase, as well as in a couple of tests. PR-URL: https://github.com/nodejs/node/pull/18720 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
49 lines
1.2 KiB
JavaScript
49 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) {
|
|
// Should not throw.
|
|
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 newAsyncId = process.geteuid();
|
|
assert.notStrictEqual(newAsyncId, olduid);
|