def test_nmap_parser_extract_hosts_ip_add(): parser = NmapReportParser() with open(nmap_full_filename, 'r') as f: hosts = list(parser.load_hosts(f)) assert hosts[0].ipv4.exploded == "192.168.1.1" assert hosts[1].ipv4.exploded == "192.168.1.2"
def test_nmap_parser_extract_software_when_available(): parser = NmapReportParser() with open(nmap_full_filename, 'r') as f: hosts = list(parser.load_hosts(f)) ports = list(hosts[1].ports) assert ports[0].software == "OpenSSH" assert ports[0].version == "7.3"
def test_nmap_parser_extract_cpe_when_available(): parser = NmapReportParser() with open(nmap_full_filename, 'r') as f: hosts = list(parser.load_hosts(f)) ports = list(hosts[1].ports) assert ports[0].cpe == "cpe:/a:openbsd:openssh:7.3" assert ports[1].cpe is None
def test_nmap_parser_doesnt_crash_if_port_number_is_null_or_zero(): parser = NmapReportParser() with open(nmap_malformed_filename, 'r') as f: hosts = list(parser.load_hosts(f)) assert len(hosts) == 2 assert len(hosts[0].ports) == 1 assert len(hosts[1].ports) == 0
def test_nmap_parser_extract_port_lists(): parser = NmapReportParser() with open(nmap_full_filename, 'r') as f: hosts = list(parser.load_hosts(f)) ports = list(hosts[0].ports) assert ports[0].port == 80 assert ports[0].protocol == "tcp" assert ports[0].state == "open" assert ports[0].service == 'http'
def test_nmap_parser_extract_os_information(): parser = NmapReportParser() with open(nmap_full_filename, 'r') as f: hosts = list(parser.load_hosts(f)) assert hosts[0].os_info['vendor'] == "Hackerbox" assert hosts[0].os_info['family'] == "Hackerbox Linux" assert hosts[0].os_info['type'] == "general purpose" assert hosts[0].os_info['name'] == 'Linux 3.16 - 4.6' assert hosts[0].os_info['accuracy'] == 100
def test_nmap_parser_extract_info_from_simple_report(): parser = NmapReportParser() with open(nmap_base_filename, 'r') as f: hosts = list(parser.load_hosts(f)) host = hosts[0] ports = list(host.ports) assert len(ports) == 11 assert ports[0].port == 22 assert ports[0].software is None assert not host.os_info
def test_nmap_parser_extract_hostname(): parser = NmapReportParser() with open(nmap_full_filename, 'r') as f: hosts = list(parser.load_hosts(f)) assert hosts[0].hostname == "test1.organization.org"
def test_nmap_parser_generates_list_of_hosts(): parser = NmapReportParser() with open(nmap_full_filename, 'r') as f: hosts = list(parser.load_hosts(f)) assert len(hosts) == 2