test: use common.canCreateSymLink() consistently

This commit replaces two ad hoc symlink permission tests with
common.canCreateSymLink().

PR-URL: https://github.com/nodejs/node/pull/20540
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
cjihrig authored and Myles Borins committed 2018-05-08 18:26:16 -07:00
1 parent 2a1efa26a7
commit b2d3db433d
2 files changed
+4 -34

No files matched your search

+2 -19
View File
@@ -27,11 +27,10 @@ const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const exec = require('child_process').exec;
let async_completed = 0;
let async_expected = 0;
const unlink = [];
let skipSymlinks = false;
const skipSymlinks = !common.canCreateSymLink();
const tmpDir = tmpdir.path;
tmpdir.refresh();
@@ -45,25 +44,9 @@ if (common.isWindows) {
assert
.strictEqual(path_left.toLowerCase(), path_right.toLowerCase(), message);
};
// On Windows, creating symlinks requires admin privileges.
// We'll only try to run symlink test if we have enough privileges.
try {
exec('whoami /priv', function(err, o) {
if (err || !o.includes('SeCreateSymbolicLinkPrivilege')) {
skipSymlinks = true;
}
runTest();
});
} catch (er) {
// better safe than sorry
skipSymlinks = true;
process.nextTick(runTest);
}
} else {
process.nextTick(runTest);
}
process.nextTick(runTest);
function tmp(p) {
return path.join(tmpDir, p);
+2 -15
View File
@@ -9,21 +9,8 @@ const traceFile = 'node_trace.1.log';
let gid = 1;
let uid = 1;
let skipSymlinks = false;
// On Windows, creating symlinks requires admin privileges.
// We'll check if we have enough privileges.
if (common.isWindows) {
try {
const o = cp.execSync('whoami /priv');
if (!o.includes('SeCreateSymbolicLinkPrivilege')) {
skipSymlinks = true;
}
} catch (er) {
// better safe than sorry
skipSymlinks = true;
}
} else {
if (!common.isWindows) {
gid = process.getgid();
uid = process.getuid();
}
@@ -111,7 +98,7 @@ tests['fs.sync.write'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
// On windows, we need permissions to test symlink and readlink.
// We'll only try to run these tests if we have enough privileges.
if (!skipSymlinks) {
if (common.canCreateSymLink()) {
tests['fs.sync.symlink'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
'fs.symlinkSync("fs.txt", "linkx");' +
'fs.unlinkSync("linkx");' +