1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-18 09:35:20 +02:00
joplin/packages/app-desktop/utils/isSafeToOpen.test.ts

33 lines
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);
}
});
});