Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorLeitwolf112026-11-16 14:52:55 +0300
committerLeitwolf112026-11-16 14:52:55 +0300
commit430cd475da04bf3dba74c96b273c4f12570d6577 (patch)
tree04422ae10e4cc73915b53278805b608c30935531 /tests
parent064a9ebb87c5afd55b0cd00b37ebaf849a9306b4 (diff)
downloadcatch3-430cd475da04bf3dba74c96b273c4f12570d6577.tar.gz
Parse the JUnit report with defusedxml
Bandit flags every parser of the standard xml package, fromstring too, as they expand entities. defusedxml refuses entity declarations and external references, so the hand-written DOCTYPE check goes. - Ubuntu and Fedora jobs that build the extra tests install the distribution package python3-defusedxml. - The macOS job installs requirements-tests.txt, pinned by hash, into the Python of actions/setup-python, and CMake uses that Python. - The contributing guide names the requirement. Claude-Session: https://claude.ai/code/session_01Ji7xZMYjc4zankoc7hGBE1
Diffstat (limited to 'tests')
-rw-r--r--tests/TestScripts/testBazelReporter.py13
1 files changed, 4 insertions, 9 deletions
diff --git a/tests/TestScripts/testBazelReporter.py b/tests/TestScripts/testBazelReporter.py
index f91e7b0f..a7c11eb5 100644
--- a/tests/TestScripts/testBazelReporter.py
+++ b/tests/TestScripts/testBazelReporter.py
@@ -10,7 +10,9 @@
import os
import re
import sys
-import xml.etree.ElementTree as ET
+# defusedxml refuses entity declarations and external references, which the
+# standard parsers would expand.
+import defusedxml.ElementTree as ET
import subprocess
"""
@@ -56,14 +58,7 @@ if ret.returncode != 42:
exit(1)
try:
- with open(xml_out_path, 'r', encoding='utf-8') as report:
- text = report.read()
- # A JUnit report has no document type, so it declares no entities: one
- # that does is rejected before parsing, and no entity is ever expanded.
- if '<!DOCTYPE' in text or '<!ENTITY' in text:
- print("The report declares a document type: '{}'".format(xml_out_path))
- exit(2)
- tree = ET.ElementTree(ET.fromstring(text))
+ tree = ET.parse(xml_out_path)
except ET.ParseError as ex:
print("Invalid XML: '{}'".format(ex))
raise