import unittest from pathlib import Path from unittest.mock import patch from librenet_scanner.network import target_ipv4_hosts from librenet_scanner.privileged_helper import command_for ROOT = Path(__file__).resolve().parents[1] class StandardPipeline0420Tests(unittest.TestCase): def test_standard_uses_adaptive_baseline(self): source = (ROOT / "src/librenet_scanner/scanner.py").read_text(encoding="utf-8") start = source.index("def _standard_scan") end = source.index("def _nmap_optional", start) block = source[start:end] self.assertIn("self._standard_baseline", block) self.assertNotIn("target_ipv4_hosts", block) def test_run_standard_branch_only_enters_standard_pipeline(self): source = (ROOT / "src/librenet_scanner/scanner.py").read_text(encoding="utf-8") branch = source[source.index('elif profile == "Standard"'):source.index('elif profile == "Approfondi"')] self.assertIn("self._standard_scan()", branch) self.assertNotIn("_discover_hosts", branch) def test_user_naabu_is_connect_stream_and_skips_host_prefilter(self): source = (ROOT / "src/librenet_scanner/scanner.py").read_text(encoding="utf-8") start = source.index("def _naabu_ports") end = source.index("def _nmap_standard_ports", start) block = source[start:end] self.assertIn('"-scan-type", "c"', block) self.assertIn('"-Pn"', block) self.assertIn('"-stream"', block) self.assertNotIn('"-verify"', block) self.assertNotIn('"-retries"', block) def test_admin_naabu_is_syn_stream_and_bounded(self): with patch("librenet_scanner.privileged_helper._trusted_binary", return_value="/usr/local/bin/naabu"): cmd = command_for("naabu-standard", ["192.168.10.10", "192.168.10.11"]) self.assertEqual(cmd[cmd.index("-scan-type") + 1], "s") self.assertIn("-Pn", cmd) self.assertIn("-stream", cmd) self.assertNotIn("-verify", cmd) self.assertNotIn("-retries", cmd) self.assertEqual(cmd[cmd.index("-timeout") + 1], "800ms") def test_target_range_is_expanded(self): self.assertEqual( target_ipv4_hosts("192.168.10.10-12"), ["192.168.10.10", "192.168.10.11", "192.168.10.12"], ) def test_target_cidr_is_expanded_to_hosts(self): self.assertEqual( target_ipv4_hosts("192.168.10.0/30"), ["192.168.10.1", "192.168.10.2"], ) if __name__ == "__main__": unittest.main()