Skip to content

Commit 4b2e886

Browse files
cjihrigMylesBorins
authored andcommitted
test: use common.canCreateSymLink() consistently
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>
1 parent b6168bb commit 4b2e886

2 files changed

Lines changed: 4 additions & 34 deletions

File tree

‎test/parallel/test-fs-realpath.js‎

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ const tmpdir = require('../common/tmpdir');
2727
constassert=require('assert');
2828
constfs=require('fs');
2929
constpath=require('path');
30-
constexec=require('child_process').exec;
3130
letasync_completed=0;
3231
letasync_expected=0;
3332
constunlink=[];
34-
letskipSymlinks=false;
33+
constskipSymlinks=!common.canCreateSymLink();
3534
consttmpDir=tmpdir.path;
3635

3736
tmpdir.refresh();
@@ -45,25 +44,9 @@ if (common.isWindows) {
4544
assert
4645
.strictEqual(path_left.toLowerCase(),path_right.toLowerCase(),message);
4746
};
48-
49-
// On Windows, creating symlinks requires admin privileges.
50-
// We'll only try to run symlink test if we have enough privileges.
51-
try{
52-
exec('whoami /priv',function(err,o){
53-
if(err||!o.includes('SeCreateSymbolicLinkPrivilege')){
54-
skipSymlinks=true;
55-
}
56-
runTest();
57-
});
58-
}catch(er){
59-
// better safe than sorry
60-
skipSymlinks=true;
61-
process.nextTick(runTest);
62-
}
63-
}else{
64-
process.nextTick(runTest);
6547
}
6648

49+
process.nextTick(runTest);
6750

6851
functiontmp(p){
6952
returnpath.join(tmpDir,p);

‎test/parallel/test-trace-events-fs-sync.js‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,8 @@ const traceFile = 'node_trace.1.log';
99

1010
letgid=1;
1111
letuid=1;
12-
letskipSymlinks=false;
1312

14-
// On Windows, creating symlinks requires admin privileges.
15-
// We'll check if we have enough privileges.
16-
if(common.isWindows){
17-
try{
18-
consto=cp.execSync('whoami /priv');
19-
if(!o.includes('SeCreateSymbolicLinkPrivilege')){
20-
skipSymlinks=true;
21-
}
22-
}catch(er){
23-
// better safe than sorry
24-
skipSymlinks=true;
25-
}
26-
}else{
13+
if(!common.isWindows){
2714
gid=process.getgid();
2815
uid=process.getuid();
2916
}
@@ -111,7 +98,7 @@ tests['fs.sync.write'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
11198

11299
// On windows, we need permissions to test symlink and readlink.
113100
// We'll only try to run these tests if we have enough privileges.
114-
if(!skipSymlinks){
101+
if(common.canCreateSymLink()){
115102
tests['fs.sync.symlink']='fs.writeFileSync("fs.txt", "123", "utf8");'+
116103
'fs.symlinkSync("fs.txt", "linkx");'+
117104
'fs.unlinkSync("linkx");'+

0 commit comments

Comments
 (0)