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

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLeitwolf112026-11-16 14:52:55 +0300
committerLeitwolf112026-11-16 14:52:55 +0300
commit430cd475da04bf3dba74c96b273c4f12570d6577 (patch)
tree04422ae10e4cc73915b53278805b608c30935531
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
-rw-r--r--.github/workflows/linux-builds.yml8
-rw-r--r--.github/workflows/mac-builds.yml10
-rw-r--r--docs/contributing.md4
-rw-r--r--requirements-tests.txt7
-rw-r--r--tests/TestScripts/testBazelReporter.py13
5 files changed, 27 insertions, 15 deletions
diff --git a/.github/workflows/linux-builds.yml b/.github/workflows/linux-builds.yml
index 02ee8d67..dd36df79 100644
--- a/.github/workflows/linux-builds.yml
+++ b/.github/workflows/linux-builds.yml
@@ -32,10 +32,10 @@ jobs:
with:
persist-credentials: false
- - name: Install Clang, LLVM's coverage tools, CMake and Ninja
+ - name: Install Clang, LLVM's coverage tools, CMake, Ninja and defusedxml
run: |
sudo apt-get update
- sudo apt-get install -y clang llvm cmake ninja-build python3
+ sudo apt-get install -y clang llvm cmake ninja-build python3 python3-defusedxml
- name: Configure
run: |
@@ -113,8 +113,8 @@ jobs:
steps:
# Git comes first: without it the checkout falls back to an archive of
# the repository, which is not a checkout the tests can ask questions of.
- - name: Install Git, Clang, LLVM's coverage tools, CMake and Ninja
- run: dnf install -y git clang llvm gcc-c++ cmake ninja-build python3
+ - name: Install Git, Clang, LLVM's coverage tools, CMake, Ninja and defusedxml
+ run: dnf install -y git clang llvm gcc-c++ cmake ninja-build python3 python3-defusedxml
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
diff --git a/.github/workflows/mac-builds.yml b/.github/workflows/mac-builds.yml
index 8e10fadc..4275cbc7 100644
--- a/.github/workflows/mac-builds.yml
+++ b/.github/workflows/mac-builds.yml
@@ -28,6 +28,13 @@ jobs:
with:
persist-credentials: false
+ - uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
+ with:
+ python-version: '3.14'
+
+ - name: Install what the extra tests import
+ run: python -m pip install --require-hashes --requirement requirements-tests.txt
+
- name: Configure with the sanitizers
env:
CXXFLAGS: -fsanitize=address,undefined
@@ -37,7 +44,8 @@ jobs:
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD=17 \
-DCATCH3_BUILD_EXAMPLES=ON \
- -DCATCH3_BUILD_EXTRA_TESTS=ON
+ -DCATCH3_BUILD_EXTRA_TESTS=ON \
+ -DPython3_EXECUTABLE="$(command -v python)"
- name: Build
run: cmake --build build
diff --git a/docs/contributing.md b/docs/contributing.md
index ae61a9d5..047d79f1 100644
--- a/docs/contributing.md
+++ b/docs/contributing.md
@@ -34,7 +34,9 @@ On Windows, point Bazel at Git's bash first:
`BAZEL_SH="C:\Program Files\Git\usr\bin\bash.exe"`.
CMake builds every test, including the extra tests that check compile-time
-configurations:
+configurations. Their scripts need Python 3 with
+[defusedxml](https://pypi.org/project/defusedxml/) (`python3-defusedxml` on
+Debian, Ubuntu and Fedora, or `requirements-tests.txt`):
```
cmake --preset basic-tests -GNinja -DCATCH3_BUILD_EXTRA_TESTS=ON -DCATCH3_BUILD_EXAMPLES=ON
diff --git a/requirements-tests.txt b/requirements-tests.txt
new file mode 100644
index 00000000..413f26c9
--- /dev/null
+++ b/requirements-tests.txt
@@ -0,0 +1,7 @@
+# SPDX-FileCopyrightText: 2026 Progmasoft <support@progmasoft.com>
+# SPDX-License-Identifier: LGPL-3.0-or-later
+
+# What the scripts of the extra tests import (tests/TestScripts).
+defusedxml==0.7.1 \
+ --hash=sha256:a352e7e428770286cc899e2542b6cdaedb2b4953ff269a210103ec58f6198a61 \
+ --hash=sha256:1bb3032db185915b62d7c6209c5a8792be6a32ab2fedacc84e01b52c51aa3e69
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