net-kingdom/tests/test_security_tools_index.py

35 lines
1.3 KiB
Python
Raw Normal View History

"""The security tools index stays complete and points at things that exist."""
import json
import pathlib
import re
ROOT = pathlib.Path(__file__).resolve().parents[1]
INDEX = json.loads((ROOT / "tools/security-tools.json").read_text())
MAKEFILE = (ROOT / "Makefile").read_text()
TARGETS = set(re.findall(r"^([a-z0-9-]+):", MAKEFILE, re.M))
def test_every_tool_directory_is_indexed_or_explicitly_excluded():
dirs = {p.name for p in (ROOT / "tools").iterdir() if p.is_dir() and not p.name.startswith(("_", "."))}
listed = {t["id"] for t in INDEX["tools"]} | set(INDEX["not_security_tools"])
assert dirs - listed == set(), f"add to tools/security-tools.json: {sorted(dirs - listed)}"
def test_paths_and_standards_exist():
for tool in INDEX["tools"]:
assert (ROOT / tool["path"]).is_dir(), tool["id"]
assert (ROOT / tool["standard"]).is_file(), (tool["id"], tool["standard"])
def test_make_targets_named_in_the_index_exist():
for tool in INDEX["tools"]:
for field in ("run", "test"):
command = tool[field]
if command.startswith("make "):
assert command.split()[1] in TARGETS, (tool["id"], command)
def test_agent_permission_is_always_stated():
allowed = set(INDEX["agent_may_run_values"])
assert all(tool["agent_may_run"] in allowed for tool in INDEX["tools"])