aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorstuppie2026-03-11 18:17:09 -0600
committerstuppie2026-03-11 18:17:09 -0600
commitb0306293ef52816998a463fbfe4c5b97d00b9b65 (patch)
treeb166bf6026885d0abf455a2a915f9ad665c52748 /tests
parent36837ab6255b923c819650a3c0db9db7d0c5ba57 (diff)
downloadgeneralresearch-b0306293ef52816998a463fbfe4c5b97d00b9b65.tar.gz
generalresearch-b0306293ef52816998a463fbfe4c5b97d00b9b65.zip
network: completely rename and reorganize everything with consistent naming
Diffstat (limited to 'tests')
-rw-r--r--tests/managers/network/tool_run.py90
-rw-r--r--tests/models/network/nmap.py32
-rw-r--r--tests/models/network/nmap_parser.py22
-rw-r--r--tests/models/network/rdns.py64
-rw-r--r--tests/models/network/tool_run.py8
5 files changed, 78 insertions, 138 deletions
diff --git a/tests/managers/network/tool_run.py b/tests/managers/network/tool_run.py
index 0f9388f..c05af92 100644
--- a/tests/managers/network/tool_run.py
+++ b/tests/managers/network/tool_run.py
@@ -6,102 +6,38 @@ import faker
import pytest
from generalresearch.models.network.definitions import IPProtocol
-from generalresearch.models.network.mtr import (
- get_mtr_version,
- parse_raw_output,
- MTRReport,
- get_mtr_command,
-)
+
from generalresearch.models.network.tool_run import (
- new_tool_run_from_nmap,
- run_dig,
- MtrRun,
ToolName,
ToolClass,
Status,
)
-from generalresearch.models.network.tool_utils import ToolRunCommand
fake = faker.Faker()
-def test_create_tool_run_from_nmap(nmap_run, toolrun_manager):
- scan_group_id = uuid4().hex
- run = new_tool_run_from_nmap(nmap_run, scan_group_id=scan_group_id)
-
- toolrun_manager.create_portscan_run(run)
-
- run_out = toolrun_manager.get_portscan_run(run.id)
-
- assert run == run_out
-
-
-def test_create_tool_run_from_dig_fixture(reverse_dns_run, toolrun_manager):
-
- toolrun_manager.create_rdns_run(reverse_dns_run)
-
- run_out = toolrun_manager.get_rdns_run(reverse_dns_run.id)
-
- assert reverse_dns_run == run_out
-
-
-def test_run_dig(toolrun_manager):
- reverse_dns_run = run_dig(ip="65.19.129.53")
-
- toolrun_manager.create_rdns_run(reverse_dns_run)
-
- run_out = toolrun_manager.get_rdns_run(reverse_dns_run.id)
-
- assert reverse_dns_run == run_out
-
-
-def test_run_dig_empty(toolrun_manager):
- reverse_dns_run = run_dig(ip=fake.ipv6())
+def test_create_tool_run_from_nmap_run(nmap_run, toolrun_manager):
- toolrun_manager.create_rdns_run(reverse_dns_run)
+ toolrun_manager.create_nmap_run(nmap_run)
- run_out = toolrun_manager.get_rdns_run(reverse_dns_run.id)
+ run_out = toolrun_manager.get_nmap_run(nmap_run.id)
- assert reverse_dns_run == run_out
+ assert nmap_run == run_out
-@pytest.fixture(scope="session")
-def mtr_report(request) -> MTRReport:
- fp = os.path.join(request.config.rootpath, "data/mtr_fatbeam.json")
- with open(fp, "r") as f:
- s = f.read()
- data = parse_raw_output(s)
- data["port"] = 443
- data["protocol"] = IPProtocol.TCP
- return MTRReport.model_validate(data)
+def test_create_tool_run_from_rdns_run(rdns_run, toolrun_manager):
+ toolrun_manager.create_rdns_run(rdns_run)
-def test_create_tool_run_from_mtr(toolrun_manager, mtr_report):
- started_at = datetime.now(tz=timezone.utc)
- tool_version = get_mtr_version()
+ run_out = toolrun_manager.get_rdns_run(rdns_run.id)
- ip = mtr_report.destination
+ assert rdns_run == run_out
- finished_at = datetime.now(tz=timezone.utc)
- raw_command = " ".join(get_mtr_command(ip))
- run = MtrRun(
- tool_name=ToolName.MTR,
- tool_class=ToolClass.TRACEROUTE,
- tool_version=tool_version,
- status=Status.SUCCESS,
- ip=ip,
- started_at=started_at,
- finished_at=finished_at,
- raw_command=raw_command,
- scan_group_id=uuid4().hex,
- config=ToolRunCommand.from_raw_command(raw_command),
- parsed=mtr_report,
- source_ip="1.1.1.1"
- )
+def test_create_tool_run_from_mtr_run(mtr_run, toolrun_manager):
- toolrun_manager.create_mtr_run(run)
+ toolrun_manager.create_mtr_run(mtr_run)
- run_out = toolrun_manager.get_mtr_run(run.id)
+ run_out = toolrun_manager.get_mtr_run(mtr_run.id)
- assert run == run_out
+ assert mtr_run == run_out
diff --git a/tests/models/network/nmap.py b/tests/models/network/nmap.py
deleted file mode 100644
index 4fc7014..0000000
--- a/tests/models/network/nmap.py
+++ /dev/null
@@ -1,32 +0,0 @@
-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/nmap_parser.py b/tests/models/network/nmap_parser.py
new file mode 100644
index 0000000..96d7b37
--- /dev/null
+++ b/tests/models/network/nmap_parser.py
@@ -0,0 +1,22 @@
+import os
+
+import pytest
+
+from generalresearch.models.network.nmap.parser import parse_nmap_xml
+
+@pytest.fixture
+def nmap_raw_output_2(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_raw_output, nmap_raw_output_2):
+ n = parse_nmap_xml(nmap_raw_output)
+ assert n.tcp_open_ports == [61232]
+ assert len(n.trace.hops) == 18
+
+ n = parse_nmap_xml(nmap_raw_output_2)
+ 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
index 9167749..64e8351 100644
--- a/tests/models/network/rdns.py
+++ b/tests/models/network/rdns.py
@@ -1,23 +1,45 @@
-from generalresearch.models.network.rdns import dig_rdns
-import faker
+# from generalresearch.models.network.rdns import run_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 = run_rdns(ip)
+# assert rdns_result.primary_hostname == "scanme.nmap.org"
+# assert rdns_result.primary_org == "nmap"
+#
+# ip = "65.19.129.53"
+# rdns_result = run_rdns(ip)
+# assert rdns_result.primary_hostname == "in1-smtp.grlengine.com"
+# assert rdns_result.primary_org == "grlengine"
+#
+# ip = fake.ipv6()
+# rdns_result = run_rdns(ip)
+# assert rdns_result.primary_hostname is None
+# assert rdns_result.primary_org is None
+# print(rdns_result.model_dump_postgres())
-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())
+#
+#
+# def test_run_dig(toolrun_manager):
+# reverse_dns_run = run_dig(ip="65.19.129.53")
+#
+# toolrun_manager.create_rdns_run(reverse_dns_run)
+#
+# run_out = toolrun_manager.get_rdns_run(reverse_dns_run.id)
+#
+# assert reverse_dns_run == run_out
+#
+#
+# def test_run_dig_empty(toolrun_manager):
+# reverse_dns_run = run_dig(ip=fake.ipv6())
+#
+# toolrun_manager.create_rdns_run(reverse_dns_run)
+#
+# run_out = toolrun_manager.get_rdns_run(reverse_dns_run.id)
+#
+# assert reverse_dns_run == run_out \ No newline at end of file
diff --git a/tests/models/network/tool_run.py b/tests/models/network/tool_run.py
deleted file mode 100644
index c643503..0000000
--- a/tests/models/network/tool_run.py
+++ /dev/null
@@ -1,8 +0,0 @@
-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)