Vortex-Flux / tests /test_document_validator.py
jaimalklyde's picture
Claude Sonnet 5
fix: consolide get_credential, log silences critiques, securise MIME/SPARQL/Mapbox
2fe4365
Raw History Blame Contribute Delete
1.33 kB
"""Tests de _signature_correspond_extension (Algorithms/document_validator.py) :
verifie le contenu reel d'un fichier televerse plutot que sa seule extension."""
import pytest
from Algorithms.document_validator import _signature_correspond_extension
def test_pdf_valide():
assert _signature_correspond_extension(b"%PDF-1.7\n...", ".pdf") is True
def test_png_valide():
assert _signature_correspond_extension(b"\x89PNG\r\n\x1a\n...", ".png") is True
def test_jpeg_valide():
assert _signature_correspond_extension(b"\xff\xd8\xff\xe0...", ".jpg") is True
assert _signature_correspond_extension(b"\xff\xd8\xff\xe0...", ".jpeg") is True
def test_fichier_renomme_rejete():
"""Un .exe renomme en .pdf ne doit pas passer la verification."""
assert _signature_correspond_extension(b"MZ\x90\x00...", ".pdf") is False
def test_texte_brut_renomme_en_png_rejete():
assert _signature_correspond_extension(b"ceci n'est pas une image", ".png") is False
def test_extension_non_surveillee_toujours_acceptee():
"""Pas de blocage sur un type non couvert par la liste (evite les faux negatifs)."""
assert _signature_correspond_extension(b"peu importe le contenu", ".docx") is True
def test_fichier_vide_rejete_pour_type_surveille():
assert _signature_correspond_extension(b"", ".pdf") is False