Kill the surviving glob and breach-directory mutants of item 370

This commit is contained in:
2026-11-13 22:43:09 +01:00
parent 3213971f98
commit 637a60a017
2 changed files with 10 additions and 4 deletions
+1 -4
View File
@@ -121,10 +121,7 @@ def globbed(glob: str, searched: str, path: pathlib.Path) -> bool:
return False
if UNMATCHED.search(glob):
return True
if glob.startswith("!"):
# It only excludes files.
return False
anchored = glob.lstrip("/") if "/" in glob else f"**/{glob}"
anchored = glob.removeprefix("/") if "/" in glob else f"**/{glob}"
# A `**` that is not a whole folder name matches as `*` in ripgrep; crossing folders there only refuses more.
translated = {"**/": "(?:.*/)?", "**": ".*", "*": "[^/]*", "?": "[^/]"}
pattern = "".join(translated.get(piece, re.escape(piece)) for piece in re.split(r"(\*\*/|\*\*|\*|\?)", anchored))
+9
View File
@@ -552,6 +552,15 @@ class EnvFileRead(unittest.TestCase):
with self.subTest(command):
self.assertEqual(self.breached("Bash", {"command": command}), expected)
def test_a_glob_matches_a_file_below_the_searched_folder_by_name_or_by_path(self):
for command, expected in (("rg -g '*.env' TOKEN ~", ["env-file-read"]), ("rg -g 'acme.en?' TOKEN ~/secrets", ["env-file-read"]), ("rg -g '/secrets/acme.env' TOKEN ~", ["env-file-read"]), ("rg -g 'acme.enx' TOKEN ~/secrets", [])):
with self.subTest(command):
self.assertEqual(self.breached("Bash", {"command": command}), expected)
def test_a_search_s_breach_is_logged_in_the_directory_the_command_runs_in(self):
found = breaches_of(Call("Bash", {"command": "grep -r TOKEN ~/secrets"}, "/r"), str(self.home), {})
self.assertEqual([breach.directory for breach in found[2] if breach.rule == "env-file-read"], ["/r"])
def test_a_file_several_configs_name_is_reported_once(self):
write_config(self.home, self.home / "code" / "other")
config = self.home / ".claude-projects" / "other" / "config.toml"