mirror of
https://github.com/lopes/netbox-scanner.git
synced 2025-07-23 22:04:50 +02:00
implemented basic tests
This commit is contained in:
parent
cb29536a4c
commit
7c88cbf295
@ -5,12 +5,8 @@ from pynetbox import api
|
|||||||
|
|
||||||
class NetBoxScanner(object):
|
class NetBoxScanner(object):
|
||||||
|
|
||||||
def __init__(self, netbox, hosts, tag, cleanup):
|
def __init__(self, address, token, tls_verify, hosts, tag, cleanup):
|
||||||
self.netbox = api(
|
self.netbox = api(address, token, ssl_verify=tls_verify)
|
||||||
netbox['address'],
|
|
||||||
netbox['token'],
|
|
||||||
ssl_verify=netbox.getboolean('tls_verify')
|
|
||||||
)
|
|
||||||
self.hosts = hosts
|
self.hosts = hosts
|
||||||
self.tag = tag
|
self.tag = tag
|
||||||
self.cleanup = cleanup
|
self.cleanup = cleanup
|
||||||
|
@ -53,7 +53,9 @@ def cmd_nmap(): # nmap handler
|
|||||||
h = Nmap(nmap['path'], nmap['unknown'])
|
h = Nmap(nmap['path'], nmap['unknown'])
|
||||||
h.run()
|
h.run()
|
||||||
scan = NetBoxScanner(
|
scan = NetBoxScanner(
|
||||||
netbox,
|
netbox['address'],
|
||||||
|
netbox['token'],
|
||||||
|
netbox.getboolean('tls_verify'),
|
||||||
h.hosts,
|
h.hosts,
|
||||||
nmap['tag'],
|
nmap['tag'],
|
||||||
nmap.getboolean('cleanup')
|
nmap.getboolean('cleanup')
|
||||||
|
72
samples/nmap-1.xml
Normal file
72
samples/nmap-1.xml
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<?xml-stylesheet href="file:///usr/local/bin/../share/nmap/nmap.xsl" type="text/xsl"?>
|
||||||
|
<!-- Nmap 5.59BETA3 scan initiated Fri Sep 9 18:33:41 2011 as:
|
||||||
|
nmap -T4 -A -p 1-1000 -oX - scanme.nmap.org -->
|
||||||
|
<nmaprun scanner="nmap" args="nmap -T4 -A -p 1-1000 -oX - scanme.nmap.org" start="1315618421"
|
||||||
|
startstr="Fri Sep 9 18:33:41 2011" version="5.59BETA3" xmloutputversion="1.03">
|
||||||
|
<scaninfo type="syn" protocol="tcp" numservices="1000" services="1-1000"/>
|
||||||
|
<verbose level="0"/>
|
||||||
|
<debugging level="0"/>
|
||||||
|
<host starttime="1315618421" endtime="1315618434">
|
||||||
|
<status state="up" reason="echo-reply"/>
|
||||||
|
<address addr="74.207.244.221" addrtype="ipv4"/>
|
||||||
|
<hostnames>
|
||||||
|
<hostname name="scanme.nmap.org" type="user"/>
|
||||||
|
<hostname name="li86-221.members.linode.com" type="PTR"/>
|
||||||
|
</hostnames>
|
||||||
|
<ports>
|
||||||
|
<extraports state="closed" count="997">
|
||||||
|
<extrareasons reason="resets" count="997"/>
|
||||||
|
</extraports>
|
||||||
|
<port protocol="tcp" portid="22">
|
||||||
|
<state state="open" reason="syn-ack" reason_ttl="53"/>
|
||||||
|
<service name="ssh" product="OpenSSH" version="5.3p1 Debian 3ubuntu7"
|
||||||
|
extrainfo="protocol 2.0" ostype="Linux" method="probed" conf="10">
|
||||||
|
<cpe>cpe:/a:openbsd:openssh:5.3p1</cpe>
|
||||||
|
<cpe>cpe:/o:linux:kernel</cpe>
|
||||||
|
</service>
|
||||||
|
<script id="ssh-hostkey"
|
||||||
|
output="1024 8d:60:f1:7c:ca:b7:3d:0a:d6:67:54:9d:69:d9:b9:dd (DSA)

|
||||||
|
2048 79:f8:09:ac:d4:e2:32:42:10:49:d3:bd:20:82:85:ec (RSA)"/>
|
||||||
|
</port>
|
||||||
|
<port protocol="tcp" portid="80">
|
||||||
|
<state state="open" reason="syn-ack" reason_ttl="53"/>
|
||||||
|
<service name="http" product="Apache httpd" version="2.2.14"
|
||||||
|
extrainfo="(Ubuntu)" method="probed" conf="10">
|
||||||
|
<cpe>cpe:/a:apache:http_server:2.2.14</cpe>
|
||||||
|
</service>
|
||||||
|
<script id="http-title" output="Go ahead and ScanMe!"/>
|
||||||
|
</port>
|
||||||
|
</ports>
|
||||||
|
<os>
|
||||||
|
<portused state="open" proto="tcp" portid="22"/>
|
||||||
|
<portused state="closed" proto="tcp" portid="1"/>
|
||||||
|
<portused state="closed" proto="udp" portid="31289"/>
|
||||||
|
<osclass type="general purpose" vendor="Linux" osfamily="Linux"
|
||||||
|
osgen="2.6.X" accuracy="100">
|
||||||
|
<cpe>cpe:/o:linux:linux_kernel:2.6.39</cpe>
|
||||||
|
</osclass>
|
||||||
|
<osmatch name="Linux 2.6.39" accuracy="100" line="39278"/>
|
||||||
|
</os>
|
||||||
|
<uptime seconds="23450" lastboot="Fri Sep 9 12:03:04 2011"/>
|
||||||
|
<distance value="11"/>
|
||||||
|
<tcpsequence index="199" difficulty="Good luck!"
|
||||||
|
values="49018209,48C3EBED,495A2E7F,493EF30C,48ED43B3,495A9B0C"/>
|
||||||
|
<ipidsequence class="All zeros" values="0,0,0,0,0,0"/>
|
||||||
|
<tcptssequence class="1000HZ"
|
||||||
|
values="165CC09,165CC6E,165CCD2,165CD36,165CD9A,165CE48"/>
|
||||||
|
<trace port="256" proto="tcp">
|
||||||
|
<!-- Several hop elements removed for brevity -->
|
||||||
|
<hop ttl="9" ipaddr="72.52.92.109" rtt="15.69" host="10gigabitethernet1-1.core1.fmt1.he.net"/>
|
||||||
|
<hop ttl="10" ipaddr="64.62.250.6" rtt="12.06" host="linode-llc.10gigabitethernet2-3.core1.fmt1.he.net"/>
|
||||||
|
<hop ttl="11" ipaddr="74.207.244.221" rtt="16.55" host="li86-221.members.linode.com"/>
|
||||||
|
</trace>
|
||||||
|
<times srtt="26517" rttvar="19989" to="106473"/>
|
||||||
|
</host>
|
||||||
|
<runstats>
|
||||||
|
<finished time="1315618434" timestr="Fri Sep 9 18:33:54 2011" elapsed="13.66"
|
||||||
|
summary="Nmap done at Fri Sep 9 18:33:54 2011; 1 IP address (1 host up)
|
||||||
|
scanned in 13.66 seconds" exit="success"/>
|
||||||
|
<hosts up="1" down="0" total="1"/>
|
||||||
|
</runstats>
|
||||||
|
</nmaprun>
|
480
samples/nmap-2.xml
Normal file
480
samples/nmap-2.xml
Normal file
File diff suppressed because one or more lines are too long
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
12
tests/run_tests.sh
Normal file
12
tests/run_tests.sh
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Before running these tests, you must define some
|
||||||
|
# environment variables, such as:
|
||||||
|
#
|
||||||
|
# $ export NETBOX_ADDRESS="https..."
|
||||||
|
# $ export NETBOX_TOKEN="..."
|
||||||
|
# $ export NMAP_PATH="..."
|
||||||
|
##
|
||||||
|
|
||||||
|
python -m unittest tests.test_netbox
|
||||||
|
python -m unittest tests.test_nmap
|
17
tests/test_netbox.py
Normal file
17
tests/test_netbox.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import unittest
|
||||||
|
from os import environ
|
||||||
|
from nbs import NetBoxScanner
|
||||||
|
|
||||||
|
|
||||||
|
class TestRequest(unittest.TestCase):
|
||||||
|
def test_api(self):
|
||||||
|
address = environ.get('NETBOX_ADDRESS')
|
||||||
|
token = environ.get('NETBOX_TOKEN')
|
||||||
|
|
||||||
|
netbox = NetBoxScanner(address, token, False, [], 'test', False)
|
||||||
|
self.assertIsInstance(netbox, NetBoxScanner)
|
||||||
|
self.assertEqual(netbox.sync(), True)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
17
tests/test_nmap.py
Normal file
17
tests/test_nmap.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import unittest
|
||||||
|
from os import environ
|
||||||
|
from nbs.nmap import Nmap
|
||||||
|
|
||||||
|
|
||||||
|
class TestRequest(unittest.TestCase):
|
||||||
|
def test_api(self):
|
||||||
|
path = environ.get('NMAP_PATH')
|
||||||
|
|
||||||
|
nmap = Nmap(path, 'test')
|
||||||
|
self.assertIsInstance(nmap, Nmap)
|
||||||
|
nmap.run()
|
||||||
|
self.assertIsInstance(nmap.hosts, list)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user