summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_scan.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/test_scan.py b/tests/test_scan.py
new file mode 100644
index 0000000..19354fa
--- /dev/null
+++ b/tests/test_scan.py
@@ -0,0 +1,37 @@
+import os
+import subprocess
+import tempfile
+import unittest
+from pathlib import Path
+
+REPO = Path(__file__).resolve().parents[1]
+SCAN = REPO / "scripts" / "scan.sh"
+
+
+def scan(path):
+ return subprocess.run(["bash", str(SCAN), str(path)], capture_output=True, text=True)
+
+
+class TestScan(unittest.TestCase):
+ def test_clean_tree_passes(self):
+ r = scan(REPO)
+ self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
+
+ def _planted(self, text):
+ with tempfile.TemporaryDirectory() as d:
+ (Path(d) / "leak.py").write_text(text)
+ return scan(d)
+
+ def test_planted_token_fails(self):
+ r = self._planted("TOKEN = 'hf_" + "a" * 34 + "'\n")
+ self.assertEqual(r.returncode, 1)
+ self.assertIn("leak.py", r.stdout)
+
+ def test_planted_home_path_fails(self):
+ r = self._planted("sys.path.insert(0, '/ho" + "me/someone/x')\n")
+ self.assertEqual(r.returncode, 1)
+ self.assertIn("leak.py", r.stdout)
+
+
+if __name__ == "__main__":
+ unittest.main()