The imports were sorted in May, which broke the monkeypatching in safe_lxml. I added two tests that the XML parsers are properly patched, but they didn't pass until I added the monkeypatching to the start of the test runs. Once that was done, some tests failed because they relied on specific details of how empty elements are represented. Those tests are now fixed.
21 lines
584 B
Python
21 lines
584 B
Python
"""Test that we have defused XML."""
|
|
|
|
import defusedxml
|
|
from lxml import etree
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.mark.parametrize("attr", ["XML", "fromstring", "parse"])
|
|
def test_etree_is_defused(attr):
|
|
func = getattr(etree, attr)
|
|
assert "defused" in func.__code__.co_filename
|
|
|
|
|
|
def test_entities_arent_resolved():
|
|
# Make sure we have disabled entity resolution.
|
|
xml = '<?xml version="1.0"?><!DOCTYPE mydoc [<!ENTITY hi "Hello">]> <root>&hi;</root>'
|
|
parser = etree.XMLParser()
|
|
with pytest.raises(defusedxml.EntitiesForbidden):
|
|
_ = etree.XML(xml, parser=parser)
|