Skip to content

Commit c83b650

Browse files
James HerringtonBridgeAR
James Herrington
authored andcommitted
test: add tests for process.initgroups
- test argument validation - test function throws if provided group is invalid PR-URL: #24154 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 0c9d86f commit c83b650

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
5+
if (common.isWindows || !common.isMainThread) {
6+
assert.strictEqual(process.initgroups, undefined);
7+
return;
8+
}
9+
10+
[undefined, null, true, {}, [], () => {}].forEach((val) => {
11+
assert.throws(
12+
() => {
13+
process.initgroups(val);
14+
},
15+
{
16+
code: 'ERR_INVALID_ARG_TYPE',
17+
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
18+
message:
19+
'The "user" argument must be ' +
20+
'one of type number or string. ' +
21+
`Received type ${typeof val}`
22+
}
23+
);
24+
});
25+
26+
[undefined, null, true, {}, [], () => {}].forEach((val) => {
27+
assert.throws(
28+
() => {
29+
process.initgroups('foo', val);
30+
},
31+
{
32+
code: 'ERR_INVALID_ARG_TYPE',
33+
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
34+
message:
35+
'The "extraGroup" argument must be ' +
36+
'one of type number or string. ' +
37+
`Received type ${typeof val}`
38+
}
39+
);
40+
});
41+
42+
assert.throws(
43+
() => {
44+
process.initgroups(
45+
'fhqwhgadshgnsdhjsdbkhsdabkfabkveyb',
46+
'fhqwhgadshgnsdhjsdbkhsdabkfabkveyb'
47+
);
48+
},
49+
{
50+
code: 'ERR_UNKNOWN_CREDENTIAL',
51+
message:
52+
'Group identifier does not exist: fhqwhgadshgnsdhjsdbkhsdabkfabkveyb'
53+
}
54+
);

0 commit comments

Comments
 (0)