文件
mynode/packages/app-desktop/utils/isSafeToOpen.test.ts
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

33 行
1.1 KiB
TypeScript

import { remove, writeFile } from 'fs-extra';
import { createTempDir } from '@joplin/lib/testing/test-utils';
import { join } from 'path';
import isSafeToOpen from './isSafeToOpen';
describe('isSafeToOpen', () => {
test.each([
{ fileName: 'a.txt', expected: true },
{ fileName: 'a.json', expected: true },
{ fileName: 'a.JSON', expected: true },
{ fileName: 'a.tar.gz', expected: true },
{ fileName: 'a.exe', expected: false },
{ fileName: 'test.com', expected: false },
{ fileName: 'a.pyc', expected: false },
{ fileName: 'a.pyo', expected: false },
{ fileName: 'a.pyw', expected: false },
{ fileName: 'a.jar', expected: false },
{ fileName: 'a.bat', expected: false },
{ fileName: 'a.cmd', expected: false },
{ fileName: 'noExtension', expected: false },
])('should mark executable files as possibly unsafe to open (%j)', async ({ fileName, expected }) => {
const tempDir = await createTempDir();
try {
const fullPath = join(tempDir, fileName);
await writeFile(fullPath, 'test');
expect(await isSafeToOpen(fullPath)).toBe(expected);
} finally {
await remove(tempDir);
}
});
});