Skip to content

Commit 3ccf7a9

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

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/api-spec.js

+27
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,28 @@ 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+
console.log(output.toString());
34+
return output.includes('SeCreateSymbolicLinkPrivilege');
35+
} catch {
36+
return false;
37+
}
38+
}
39+
// On non-Windows platforms, this always returns `true`
40+
return true;
41+
}
42+
2043
describe('api', function () {
2144
beforeEach(() => {
2245
rimraf.sync(path.join(__dirname, '..', 'tmp'), fs);
@@ -108,6 +131,8 @@ describe('api', function () {
108131
return compDirs('tmp/extractthis-unpack-dir-api/', 'test/expected/extractthis');
109132
});
110133
it('should extract an archive with symlink', async () => {
134+
assert.strictEqual(canCreateSymLink(), true);
135+
111136
await asar.createPackageWithOptions(
112137
'test/input/packthis-with-symlink/',
113138
'tmp/packthis-with-symlink.asar',
@@ -120,6 +145,8 @@ describe('api', function () {
120145
);
121146
});
122147
it('should extract an archive with symlink having the same prefix', async () => {
148+
assert.strictEqual(canCreateSymLink(), true);
149+
123150
await asar.createPackageWithOptions(
124151
'test/input/packthis-with-symlink-same-prefix/',
125152
'tmp/packthis-with-symlink-same-prefix.asar',

0 commit comments

Comments
 (0)