mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
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:
1 parent
2a1efa26a7
commit
b2d3db433d
2 files changed
+4
-34
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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");' +
|
||||
|
||||
Reference in new issue
Block a user