2023-08-23 19:16:06 +02:00
|
|
|
import Setting from '@joplin/lib/models/Setting';
|
2023-07-27 16:41:57 +02:00
|
|
|
import { processPastedHtml } from './resourceHandling';
|
|
|
|
|
|
|
|
describe('resourceHandling', () => {
|
|
|
|
it('should sanitize pasted HTML', async () => {
|
2023-08-23 19:16:06 +02:00
|
|
|
Setting.setConstant('resourceDir', '/home/.config/joplin/resources');
|
|
|
|
|
2023-07-27 16:41:57 +02:00
|
|
|
const testCases = [
|
|
|
|
['Test: <style onload="evil()"></style>', 'Test: <style></style>'],
|
|
|
|
['<a href="javascript: alert()">test</a>', '<a href="#">test</a>'],
|
2023-08-23 19:16:06 +02:00
|
|
|
['<a href="file:///home/.config/joplin/resources/test.pdf">test</a>', '<a href="file:///home/.config/joplin/resources/test.pdf">test</a>'],
|
|
|
|
['<a href="file:///etc/passwd">evil.pdf</a>', '<a href="#">evil.pdf</a>'],
|
2023-07-27 16:41:57 +02:00
|
|
|
['<script >evil()</script>', ''],
|
|
|
|
['<script>evil()</script>', ''],
|
|
|
|
[
|
|
|
|
'<img onload="document.body.innerHTML = evil;" src="data:image/svg+xml;base64,=="/>',
|
|
|
|
'<img src="data:image/svg+xml;base64,=="/>',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
for (const [html, expected] of testCases) {
|
|
|
|
expect(await processPastedHtml(html)).toBe(expected);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|