mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
Tests and increase consistency for isFileDangerous calls
This commit is contained in:
parent
8edfbdcee5
commit
bc0ec92ad2
2 changed files with 36 additions and 2 deletions
|
@ -505,7 +505,7 @@ export class Message extends React.Component<Props, State> {
|
|||
} else {
|
||||
const { fileName, fileSize, contentType } = attachment;
|
||||
const extension = getExtension({ contentType, fileName });
|
||||
const isDangerous = isFileDangerous(fileName);
|
||||
const isDangerous = isFileDangerous(fileName || '');
|
||||
|
||||
return (
|
||||
<div
|
||||
|
@ -738,7 +738,7 @@ export class Message extends React.Component<Props, State> {
|
|||
return null;
|
||||
}
|
||||
|
||||
const fileName = attachment && attachment.fileName;
|
||||
const fileName = attachment ? attachment.fileName : null;
|
||||
const isDangerous = isFileDangerous(fileName || '');
|
||||
|
||||
const downloadButton = attachment ? (
|
||||
|
|
34
ts/test/util/isFileDangerous_test.ts
Normal file
34
ts/test/util/isFileDangerous_test.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import { assert } from 'chai';
|
||||
|
||||
import { isFileDangerous } from '../../util/isFileDangerous';
|
||||
|
||||
describe('isFileDangerous', () => {
|
||||
it('returns false for images', () => {
|
||||
assert.strictEqual(isFileDangerous('dog.gif'), false);
|
||||
assert.strictEqual(isFileDangerous('cat.jpg'), false);
|
||||
});
|
||||
|
||||
it('returns false for documents', () => {
|
||||
assert.strictEqual(isFileDangerous('resume.docx'), false);
|
||||
assert.strictEqual(isFileDangerous('price_list.pdf'), false);
|
||||
});
|
||||
|
||||
it('returns true for executable files', () => {
|
||||
assert.strictEqual(isFileDangerous('run.exe'), true);
|
||||
assert.strictEqual(isFileDangerous('install.pif'), true);
|
||||
});
|
||||
|
||||
it('returns false for empty filename', () => {
|
||||
assert.strictEqual(isFileDangerous(''), false);
|
||||
});
|
||||
|
||||
it('returns false for exe at various parts of filename', () => {
|
||||
assert.strictEqual(isFileDangerous('.exemanifesto.txt'), false);
|
||||
assert.strictEqual(isFileDangerous('runexe'), false);
|
||||
assert.strictEqual(isFileDangerous('run_exe'), false);
|
||||
});
|
||||
|
||||
it('returns true for upper-case EXE', () => {
|
||||
assert.strictEqual(isFileDangerous('run.EXE'), true);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue