Skip to content

Commit 8c2e34c

Browse files
committed
test: enhance OWASP mapping fixtures validation with duplicate and fallback section ID checks
1 parent 4826d25 commit 8c2e34c

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

application/tests/owasp_mapping_fixtures_test.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ def test_fixtures_have_expected_mapping_shape(self) -> None:
3030
self.assertIsInstance(payload, list)
3131
self.assertGreater(len(payload), 0)
3232

33+
known_section_ids = {
34+
entry["section_id"]
35+
for entry in payload
36+
if "section_id" in entry and isinstance(entry["section_id"], str)
37+
}
38+
seen_section_ids: set[str] = set()
39+
3340
for entry in payload:
3441
self.assertIsInstance(entry, dict)
3542
self.assertIsInstance(entry.get("section"), str)
@@ -43,6 +50,27 @@ def test_fixtures_have_expected_mapping_shape(self) -> None:
4350
if "section_id" in entry:
4451
self.assertIsInstance(entry["section_id"], str)
4552
self.assertTrue(entry["section_id"].strip())
53+
self.assertNotIn(
54+
entry["section_id"],
55+
seen_section_ids,
56+
msg=f"Duplicate section_id {entry['section_id']} in {path.name}",
57+
)
58+
seen_section_ids.add(entry["section_id"])
59+
60+
if "fallback_section_ids" in entry:
61+
self.assertIsInstance(entry["fallback_section_ids"], list)
62+
self.assertGreater(len(entry["fallback_section_ids"]), 0)
63+
for fallback_section_id in entry["fallback_section_ids"]:
64+
self.assertIsInstance(fallback_section_id, str)
65+
self.assertTrue(fallback_section_id.strip())
66+
self.assertIn(
67+
fallback_section_id,
68+
known_section_ids,
69+
msg=(
70+
f"Fallback section id {fallback_section_id} "
71+
f"in {path.name} is not a known section_id"
72+
),
73+
)
4674

4775
for cre_id in entry["cre_ids"]:
4876
self.assertIsInstance(cre_id, str)

0 commit comments

Comments
 (0)