diff options
| author | stuppie | 2026-03-09 18:42:22 -0600 |
|---|---|---|
| committer | stuppie | 2026-03-09 18:42:22 -0600 |
| commit | a68a9eb9873c7502c2b7bddb55c4eb61689a48a2 (patch) | |
| tree | 6a4df8d399e94532dd3938f53f467913f412ce10 /tests/models | |
| parent | cf274a5814e02aefc0c9e25f96927b3163a4abaf (diff) | |
| download | generalresearch-a68a9eb9873c7502c2b7bddb55c4eb61689a48a2.tar.gz generalresearch-a68a9eb9873c7502c2b7bddb55c4eb61689a48a2.zip | |
add IPLabel, NmapRun, RDNSResult, ToolRun, model/managers/tests. nmap xml parser. + test. work in progress
Diffstat (limited to 'tests/models')
| -rw-r--r-- | tests/models/network/__init__.py | 0 | ||||
| -rw-r--r-- | tests/models/network/nmap.py | 32 | ||||
| -rw-r--r-- | tests/models/network/rdns.py | 23 | ||||
| -rw-r--r-- | tests/models/network/tool_run.py | 8 |
4 files changed, 63 insertions, 0 deletions
diff --git a/tests/models/network/__init__.py b/tests/models/network/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/models/network/__init__.py diff --git a/tests/models/network/nmap.py b/tests/models/network/nmap.py new file mode 100644 index 0000000..4fc7014 --- /dev/null +++ b/tests/models/network/nmap.py @@ -0,0 +1,32 @@ +import os + +import pytest + +from generalresearch.models.network.xml_parser import NmapXmlParser + + +@pytest.fixture +def nmap_xml_str(request) -> str: + fp = os.path.join(request.config.rootpath, "data/nmaprun1.xml") + with open(fp, "r") as f: + data = f.read() + return data + + +@pytest.fixture +def nmap_xml_str2(request) -> str: + fp = os.path.join(request.config.rootpath, "data/nmaprun2.xml") + with open(fp, "r") as f: + data = f.read() + return data + + +def test_nmap_xml_parser(nmap_xml_str, nmap_xml_str2): + p = NmapXmlParser() + n = p.parse_xml(nmap_xml_str) + assert n.tcp_open_ports == [61232] + assert len(n.trace.hops) == 18 + + n = p.parse_xml(nmap_xml_str2) + assert n.tcp_open_ports == [22, 80, 9929, 31337] + assert n.trace is None diff --git a/tests/models/network/rdns.py b/tests/models/network/rdns.py new file mode 100644 index 0000000..9167749 --- /dev/null +++ b/tests/models/network/rdns.py @@ -0,0 +1,23 @@ +from generalresearch.models.network.rdns import dig_rdns +import faker + +fake = faker.Faker() + + +def test_dig_rdns(): + # Actually runs dig -x. Idk how stable this is + ip = "45.33.32.156" + rdns_result = dig_rdns(ip) + assert rdns_result.primary_hostname == "scanme.nmap.org" + assert rdns_result.primary_org == "nmap" + + ip = "65.19.129.53" + rdns_result = dig_rdns(ip) + assert rdns_result.primary_hostname == "in1-smtp.grlengine.com" + assert rdns_result.primary_org == "grlengine" + + ip = fake.ipv6() + rdns_result = dig_rdns(ip) + assert rdns_result.primary_hostname is None + assert rdns_result.primary_org is None + print(rdns_result.model_dump_postgres()) diff --git a/tests/models/network/tool_run.py b/tests/models/network/tool_run.py new file mode 100644 index 0000000..c643503 --- /dev/null +++ b/tests/models/network/tool_run.py @@ -0,0 +1,8 @@ +from uuid import uuid4 + +from generalresearch.models.network.tool_run import new_tool_run_from_nmap + + +def test_new_tool_run_from_nmap(nmap_run): + scan_group_id = uuid4().hex + run, scan = new_tool_run_from_nmap(nmap_run, scan_group_id=scan_group_id) |
