Files
librenet-scanner/tests/test_v0410.py
T
2026-08-23 09:52:32 +02:00

46 lines
1.9 KiB
Python

import unittest
from unittest.mock import patch
from librenet_scanner.models import Host
from librenet_scanner.parsers import parse_nmap_xml
from librenet_scanner.privileged_helper import command_for
class OsFingerprint0410Tests(unittest.TestCase):
def test_deep_hosts_forces_guess_and_does_not_limit_os_scan(self):
with patch("librenet_scanner.privileged_helper._trusted_binary", return_value="/usr/bin/nmap"):
cmd = command_for("nmap-deep-hosts", ["192.168.10.254"])
self.assertIn("-O", cmd)
self.assertIn("--osscan-guess", cmd)
self.assertNotIn("--osscan-limit", cmd)
self.assertIn("--top-ports", cmd)
self.assertIn("1000", cmd)
self.assertNotIn("-p-", cmd)
def test_detailed_host_forces_guess_without_full_port_scan(self):
with patch("librenet_scanner.privileged_helper._trusted_binary", return_value="/usr/bin/nmap"):
cmd = command_for("nmap-host", ["192.168.10.254"])
self.assertIn("--osscan-guess", cmd)
self.assertNotIn("--osscan-limit", cmd)
self.assertNotIn("-p-", cmd)
def test_parser_keeps_best_os_guess(self):
xml = """<nmaprun><host><status state='up'/><address addr='192.168.10.254' addrtype='ipv4'/>
<os>
<osmatch name='FreeBSD 12.X' accuracy='87'/>
<osmatch name='FreeBSD 11.2-RELEASE' accuracy='93'/>
<osmatch name='Linux 5.X' accuracy='78'/>
</os></host></nmaprun>"""
host = parse_nmap_xml(xml)[0]
self.assertEqual(host.os_name, "FreeBSD 11.2-RELEASE")
self.assertEqual(host.os_accuracy, 93)
self.assertTrue(host.os_is_estimated)
def test_100_percent_os_match_is_not_marked_estimated(self):
host = Host(ip="192.168.1.1", os_name="Linux 6.x", os_accuracy=100)
self.assertFalse(host.os_is_estimated)
if __name__ == "__main__":
unittest.main()