diff options
Diffstat (limited to 'test/common.js')
-rw-r--r-- | test/common.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/common.js b/test/common.js index 694660d17e..cbd1c3a8e1 100644 --- a/test/common.js +++ b/test/common.js @@ -9,6 +9,7 @@ const stream = require('stream'); const buffer = require('buffer'); const util = require('util'); const Timer = process.binding('timer_wrap').Timer; +const execSync = require('child_process').execSync; const testRoot = process.env.NODE_TEST_DIR ? path.resolve(process.env.NODE_TEST_DIR) : __dirname; @@ -460,6 +461,34 @@ exports.fileExists = function(pathname) { } }; +exports.canCreateSymLink = function() { + // On Windows, creating symlinks requires admin privileges. + // We'll only try to run symlink test if we have enough privileges. + // On other platforms, creating symlinks shouldn't need admin privileges + if (exports.isWindows) { + // whoami.exe needs to be the one from System32 + // If unix tools are in the path, they can shadow the one we want, + // so use the full path while executing whoami + const whoamiPath = path.join(process.env['SystemRoot'], + 'System32', 'whoami.exe'); + + let err = false; + let output = ''; + + try { + output = execSync(whoamiPath + ' /priv', { timout: 1000 }); + } catch (e) { + err = true; + } finally { + if (err || !output.includes('SeCreateSymbolicLinkPrivilege')) { + return false; + } + } + } + + return true; +}; + function fail(msg) { assert.fail(null, null, msg); } |