MCPcopy Create free account
hub / github.com/blacklanternsecurity/bbot / test_python_api

Function test_python_api

bbot/test/test_step_1/test_python_api.py:5–61  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3
4@pytest.mark.asyncio
5async def test_python_api():
6 from bbot import Scanner
7
8 # make sure events are properly yielded
9 scan1 = Scanner("127.0.0.1")
10 events1 = []
11 async for event in scan1.async_start():
12 events1.append(event)
13 assert any(e.type == "IP_ADDRESS" and e.data == "127.0.0.1" for e in events1)
14 # make sure output files work
15 scan2 = Scanner("127.0.0.1", output_modules=["json"], scan_name="python_api_test")
16 await scan2.async_start_without_generator()
17 scan_home = scan2.helpers.scans_dir / "python_api_test"
18 out_file = scan_home / "output.json"
19 assert list(scan2.helpers.read_file(out_file))
20 scan_log = scan_home / "scan.log"
21 debug_log = scan_home / "debug.log"
22 assert scan_log.is_file()
23 assert "python_api_test" in open(scan_log).read()
24 assert debug_log.is_file()
25 assert "python_api_test" in open(debug_log).read()
26
27 scan3 = Scanner("127.0.0.1", output_modules=["json"], scan_name="scan_logging_test")
28 await scan3.async_start_without_generator()
29
30 assert "scan_logging_test" not in open(scan_log).read()
31 assert "scan_logging_test" not in open(debug_log).read()
32
33 scan_home = scan3.helpers.scans_dir / "scan_logging_test"
34 out_file = scan_home / "output.json"
35 assert list(scan3.helpers.read_file(out_file))
36 scan_log = scan_home / "scan.log"
37 debug_log = scan_home / "debug.log"
38 assert scan_log.is_file()
39 assert debug_log.is_file()
40 assert "scan_logging_test" in open(scan_log).read()
41 assert "scan_logging_test" in open(debug_log).read()
42
43 # make sure config loads properly
44 bbot_home = "/tmp/.bbot_python_api_test"
45 Scanner("127.0.0.1", config={"home": bbot_home})
46 assert os.environ["BBOT_TOOLS"] == str(Path(bbot_home) / "tools")
47
48 # output modules override
49 scan4 = Scanner()
50 assert set(scan4.preset.output_modules) == {"csv", "json", "python", "txt"}
51 scan5 = Scanner(output_modules=["json"])
52 assert set(scan5.preset.output_modules) == {"json"}
53
54 # custom target types
55 custom_target_scan = Scanner("ORG:evilcorp")
56 events = [e async for e in custom_target_scan.async_start()]
57 assert 1 == len([e for e in events if e.type == "ORG_STUB" and e.data == "evilcorp" and "target" in e.tags])
58
59 # presets
60 scan6 = Scanner("evilcorp.com", presets=["subdomain-enum"])
61 assert "sslcert" in scan6.preset.modules
62

Callers

nothing calls this directly

Calls 5

async_startMethod · 0.95
ScannerClass · 0.90
openFunction · 0.85
setFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…