Skip to content

Commit ed341b0

Browse files
committed
test: check for symlink permission on Windows
1 parent b553351 commit ed341b0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/api-spec.js

+26
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const fs = require('../lib/wrapped-fs').default;
55
const os = require('os');
66
const path = require('path');
77
const rimraf = require('rimraf');
8+
const { execSync } = require('child_process');
89

910
const asar = require('..');
1011
const compDirs = require('./util/compareDirectories');
@@ -17,6 +18,27 @@ async function assertPackageListEquals(actualList, expectedFilename) {
1718
return compFileLists(actualList.join('\n'), expected);
1819
}
1920

21+
function canCreateSymLink() {
22+
// On Windows, creating symlinks requires admin privileges.
23+
// We'll only try to run symlink test if we have enough privileges.
24+
// On other platforms, creating symlinks shouldn't need admin privileges
25+
if (process.platform === 'win32') {
26+
// whoami.exe needs to be the one from System32
27+
// If unix tools are in the path, they can shadow the one we want,
28+
// so use the full path while executing whoami
29+
const whoamiPath = path.join(process.env.SystemRoot, 'System32', 'whoami.exe');
30+
31+
try {
32+
const output = execSync(`${whoamiPath} /priv`, { timeout: 1000 });
33+
return output.includes('SeCreateSymbolicLinkPrivilege');
34+
} catch {
35+
return false;
36+
}
37+
}
38+
// On non-Windows platforms, this always returns `true`
39+
return true;
40+
}
41+
2042
describe('api', function () {
2143
beforeEach(() => {
2244
rimraf.sync(path.join(__dirname, '..', 'tmp'), fs);
@@ -108,6 +130,8 @@ describe('api', function () {
108130
return compDirs('tmp/extractthis-unpack-dir-api/', 'test/expected/extractthis');
109131
});
110132
it('should extract an archive with symlink', async () => {
133+
assert.strictEqual(canCreateSymLink(), true);
134+
111135
await asar.createPackageWithOptions(
112136
'test/input/packthis-with-symlink/',
113137
'tmp/packthis-with-symlink.asar',
@@ -120,6 +144,8 @@ describe('api', function () {
120144
);
121145
});
122146
it('should extract an archive with symlink having the same prefix', async () => {
147+
assert.strictEqual(canCreateSymLink(), true);
148+
123149
await asar.createPackageWithOptions(
124150
'test/input/packthis-with-symlink-same-prefix/',
125151
'tmp/packthis-with-symlink-same-prefix.asar',

0 commit comments

Comments
 (0)