Skip to content

Commit 697ea62

Browse files
evanlucasaddaleax
authored andcommitted
test: add get/set effective uid/gid tests
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]>
1 parent 575dcdc commit 697ea62

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
constassert=require('assert');
5+
6+
if(common.isWindows){
7+
assert.strictEqual(process.geteuid,undefined);
8+
assert.strictEqual(process.getegid,undefined);
9+
assert.strictEqual(process.seteuid,undefined);
10+
assert.strictEqual(process.setegid,undefined);
11+
return;
12+
}
13+
14+
assert.throws(()=>{
15+
process.seteuid({});
16+
},/^TypeError:seteuidargumentmustbeanumberorstring$/);
17+
18+
assert.throws(()=>{
19+
process.seteuid('fhqwhgadshgnsdhjsdbkhsdabkfabkveybvf');
20+
},/^Error:seteuiduseriddoesnotexist$/);
21+
22+
// If we're not running as super user...
23+
if(process.getuid()!==0){
24+
assert.doesNotThrow(()=>{
25+
process.getegid();
26+
process.geteuid();
27+
});
28+
29+
assert.throws(()=>{
30+
process.setegid('nobody');
31+
},/^Error:(?:EPERM,.+|setegidgroupiddoesnotexist)$/);
32+
33+
assert.throws(()=>{
34+
process.seteuid('nobody');
35+
},/^Error:(?:EPERM,.+|seteuiduseriddoesnotexist)$/);
36+
37+
return;
38+
}
39+
40+
// If we are running as super user...
41+
constoldgid=process.getegid();
42+
process.setegid('nobody');
43+
constnewgid=process.getegid();
44+
assert.notStrictEqual(newgid,oldgid);
45+
46+
constolduid=process.geteuid();
47+
process.seteuid('nobody');
48+
constnewuid=process.geteuid();
49+
assert.notStrictEqual(newuid,olduid);

0 commit comments

Comments
(0)