blob: 19354fa0d97b0c1ee12e8e905cde38f2219653e8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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()
|