Skip to content

Commit 7e46be1

Browse files
committed
test: enable setuid/setgid test
Refactor test for situations where it was expected to fail. Move from disabled directory to parallel.
1 parent ea44b8b commit 7e46be1

File tree

1 file changed

+40
-16
lines changed

1 file changed

+40
-16
lines changed

test/disabled/test-setuidgid.js renamed to test/parallel/test-process-setuid-setgid.js

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,49 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
// Requires special privileges
2423
const common = require('../common');
24+
2525
const assert = require('assert');
2626

27-
var oldgid = process.getgid();
28-
process.setgid('nobody');
29-
var newgid = process.getgid();
30-
assert.notStrictEqual(newgid, oldgid, 'gids expected to be different');
27+
if (common.isWindows) {
28+
// uid/gid functions are POSIX only
29+
assert.strictEqual(process.getuid, undefined);
30+
assert.strictEqual(process.setuid, undefined);
31+
assert.strictEqual(process.getgid, undefined);
32+
assert.strictEqual(process.setgid, undefined);
33+
return;
34+
}
3135

32-
var olduid = process.getuid();
33-
process.setuid('nobody');
34-
var newuid = process.getuid();
35-
assert.notStrictEqual(newuid, olduid, 'uids expected to be different');
36-
37-
try {
38-
process.setuid('nobody1234');
39-
} catch (e) {
40-
assert.strictEqual(e.message,
41-
'failed to resolve group',
42-
'unexpected error message'
36+
assert.throws(() => {
37+
process.setuid('fhqwhgadshgnsdhjsdbkhsdabkfabkveybvf');
38+
}, /^Error: setuid user id does not exist$/);
39+
40+
// If we're not running as super user...
41+
if (process.getuid() !== 0) {
42+
assert.doesNotThrow(() => {
43+
process.getgid();
44+
process.getuid();
45+
});
46+
47+
assert.throws(
48+
() => { process.setgid('nobody'); },
49+
/^Error: (EPERM, .+|setgid group id does not exist)$/
4350
);
51+
52+
assert.throws(
53+
() => { process.setuid('nobody'); },
54+
/^Error: EPERM, /
55+
);
56+
return;
4457
}
58+
59+
// If we are running as super user...
60+
const oldgid = process.getgid();
61+
process.setgid('nobody');
62+
const newgid = process.getgid();
63+
assert.notStrictEqual(newgid, oldgid);
64+
65+
const olduid = process.getuid();
66+
process.setuid('nobody');
67+
const newuid = process.getuid();
68+
assert.notStrictEqual(newuid, olduid);

0 commit comments

Comments
 (0)