0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-process-euid-egid.js
Xu Meng 262c66a851
test: skip the unsupported test cases for IBM i
This is a following PR of #30714.

PR-URL: https://github.com/nodejs/node/pull/30819
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2019-12-25 23:11:02 +01:00

71 lines
1.7 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;
}
if (!common.isMainThread)
return;
assert.throws(() => {
process.seteuid({});
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "id" argument must be one of type number or string. ' +
'Received an instance of Object'
});
assert.throws(() => {
process.seteuid('fhqwhgadshgnsdhjsdbkhsdabkfabkveyb');
}, {
code: 'ERR_UNKNOWN_CREDENTIAL',
message: 'User identifier does not exist: fhqwhgadshgnsdhjsdbkhsdabkfabkveyb'
});
// IBMi does not support below operations.
if (common.isIBMi)
return;
// If we're not running as super user...
if (process.getuid() !== 0) {
// Should not throw.
process.getegid();
process.geteuid();
assert.throws(() => {
process.setegid('nobody');
}, /(?:EPERM, .+|Group identifier does not exist: nobody)$/);
assert.throws(() => {
process.seteuid('nobody');
}, /^Error: (?:EPERM, .+|User identifier does not exist: nobody)$/);
return;
}
// If we are running as super user...
const oldgid = process.getegid();
try {
process.setegid('nobody');
} catch (err) {
if (err.message !== 'Group identifier does not exist: nobody') {
throw err;
} else {
process.setegid('nogroup');
}
}
const newgid = process.getegid();
assert.notStrictEqual(newgid, oldgid);
const olduid = process.geteuid();
process.seteuid('nobody');
const newuid = process.geteuid();
assert.notStrictEqual(newuid, olduid);