Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var info = pwd.getpwnam('nobody');
if (info === null) {
console.log('SKIP: there is no "nobody" user');
os.exit(0);
}
var p;
var r;
try {
p = proc.spawn(['ls', '-l'],
{cwd: '/', uid: info.uid, gid: info.gid});
} catch (e) {
assert.equal(e.errno, errno.EPERM);
console.log('SKIP: no permission to downgrade to user "nobody"');
os.exit(0);
}
r = p.wait();
assert.equal(r.exit_status, 0);
assert.equal(r.term_signal, 0);