Kill the surviving glob and breach-directory mutants of item 370
This commit is contained in:
@@ -121,10 +121,7 @@ def globbed(glob: str, searched: str, path: pathlib.Path) -> bool:
|
|||||||
return False
|
return False
|
||||||
if UNMATCHED.search(glob):
|
if UNMATCHED.search(glob):
|
||||||
return True
|
return True
|
||||||
if glob.startswith("!"):
|
anchored = glob.removeprefix("/") if "/" in glob else f"**/{glob}"
|
||||||
# It only excludes files.
|
|
||||||
return False
|
|
||||||
anchored = glob.lstrip("/") if "/" in glob else f"**/{glob}"
|
|
||||||
# A `**` that is not a whole folder name matches as `*` in ripgrep; crossing folders there only refuses more.
|
# A `**` that is not a whole folder name matches as `*` in ripgrep; crossing folders there only refuses more.
|
||||||
translated = {"**/": "(?:.*/)?", "**": ".*", "*": "[^/]*", "?": "[^/]"}
|
translated = {"**/": "(?:.*/)?", "**": ".*", "*": "[^/]*", "?": "[^/]"}
|
||||||
pattern = "".join(translated.get(piece, re.escape(piece)) for piece in re.split(r"(\*\*/|\*\*|\*|\?)", anchored))
|
pattern = "".join(translated.get(piece, re.escape(piece)) for piece in re.split(r"(\*\*/|\*\*|\*|\?)", anchored))
|
||||||
|
|||||||
@@ -552,6 +552,15 @@ class EnvFileRead(unittest.TestCase):
|
|||||||
with self.subTest(command):
|
with self.subTest(command):
|
||||||
self.assertEqual(self.breached("Bash", {"command": command}), expected)
|
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):
|
def test_a_file_several_configs_name_is_reported_once(self):
|
||||||
write_config(self.home, self.home / "code" / "other")
|
write_config(self.home, self.home / "code" / "other")
|
||||||
config = self.home / ".claude-projects" / "other" / "config.toml"
|
config = self.home / ".claude-projects" / "other" / "config.toml"
|
||||||
|
|||||||
Reference in New Issue
Block a user