Skip to content

Commit

Permalink
test: use common.canCreateSymLink() consistently
Browse files Browse the repository at this point in the history
This commit replaces two ad hoc symlink permission tests with
common.canCreateSymLink().

PR-URL: #20540
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
cjihrig authored and MylesBorins committed May 9, 2018
1 parent 2a1efa2 commit b2d3db4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 34 deletions.
21 changes: 2 additions & 19 deletions test/parallel/test-fs-realpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
17 changes: 2 additions & 15 deletions test/parallel/test-trace-events-fs-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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");' +
Expand Down

0 comments on commit b2d3db4

Please sign in to comment.