2018-06-12 02:42:55 +09:00
|
|
|
'use strict';
|
2018-06-13 21:49:47 +09:00
|
|
|
const common = require('../common');
|
2018-06-12 02:42:55 +09:00
|
|
|
const assert = require('assert');
|
2025-01-22 14:19:38 -08:00
|
|
|
const { isMainThread } = require('worker_threads');
|
2018-06-12 02:42:55 +09:00
|
|
|
|
2019-01-15 14:12:57 -05:00
|
|
|
if (common.isWindows) {
|
2018-06-13 21:49:47 +09:00
|
|
|
assert.strictEqual(process.setgroups, undefined);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-01-22 14:19:38 -08:00
|
|
|
if (!isMainThread) {
|
2019-01-15 14:12:57 -05:00
|
|
|
return;
|
2025-01-22 14:19:38 -08:00
|
|
|
}
|
2019-01-15 14:12:57 -05:00
|
|
|
|
2018-06-12 02:42:55 +09:00
|
|
|
assert.throws(
|
|
|
|
() => {
|
|
|
|
process.setgroups();
|
|
|
|
},
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
2019-03-16 12:09:14 +01:00
|
|
|
name: 'TypeError',
|
2019-09-23 08:17:25 +02:00
|
|
|
message: 'The "groups" argument must be an instance of Array. ' +
|
|
|
|
'Received undefined'
|
2018-06-12 02:42:55 +09:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.throws(
|
|
|
|
() => {
|
|
|
|
process.setgroups([1, -1]);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
code: 'ERR_OUT_OF_RANGE',
|
2019-03-16 12:09:14 +01:00
|
|
|
name: 'RangeError',
|
2018-06-12 02:42:55 +09:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
[undefined, null, true, {}, [], () => {}].forEach((val) => {
|
|
|
|
assert.throws(
|
|
|
|
() => {
|
|
|
|
process.setgroups([val]);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
2019-03-16 12:09:14 +01:00
|
|
|
name: 'TypeError',
|
2018-06-12 02:42:55 +09:00
|
|
|
message: 'The "groups[0]" argument must be ' +
|
2019-09-23 08:17:25 +02:00
|
|
|
'one of type number or string.' +
|
|
|
|
common.invalidArgTypeHelper(val)
|
2018-06-12 02:42:55 +09:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2018-08-17 07:45:55 +09:00
|
|
|
|
|
|
|
assert.throws(() => {
|
|
|
|
process.setgroups([1, 'fhqwhgadshgnsdhjsdbkhsdabkfabkveyb']);
|
|
|
|
}, {
|
|
|
|
code: 'ERR_UNKNOWN_CREDENTIAL',
|
|
|
|
message: 'Group identifier does not exist: fhqwhgadshgnsdhjsdbkhsdabkfabkveyb'
|
|
|
|
});
|