GooDrive/backend/drive/test_word_preview.py
Louis Mazin a5fb4ad3fa nice
2026-10-14 18:47:43 +02:00

23 lines
1013 B
Python

import tempfile
from pathlib import Path
from zipfile import ZipFile
from django.test import SimpleTestCase
from .word_preview import render_word_preview
class WordPreviewTests(SimpleTestCase):
def test_docx_text_escaped_and_tables(self):
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / 'note.docx'
document = b'''<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body><w:p><w:r><w:t>&lt;script&gt;alert(1)&lt;/script&gt;</w:t></w:r></w:p>
<w:tbl><w:tr><w:tc><w:p><w:r><w:t>Tableau</w:t></w:r></w:p></w:tc></w:tr></w:tbl>
</w:body></w:document>'''
with ZipFile(path, 'w') as archive:
archive.writestr('word/document.xml', document)
html = render_word_preview(path)
self.assertIn('&lt;script&gt;', html)
self.assertNotIn('<script>', html)
self.assertIn('<table>', html)
self.assertIn('Tableau', html)