forked from savon-noir/python-libnmap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_report_diff.py
More file actions
64 lines (55 loc) · 2.88 KB
/
test_report_diff.py
File metadata and controls
64 lines (55 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
import os
from libnmap.parser import NmapParser
class TestNmapReportDiff(unittest.TestCase):
def setUp(self):
fdir = os.path.dirname(os.path.realpath(__file__))
self.flist_full = [{'file': "%s/%s" % (fdir, 'files/2_hosts.xml'),
'hosts': 2},
{'file': "%s/%s" % (fdir, 'files/1_hosts.xml'),
'hosts': 1}]
self.flist = self.flist_full
def test_diff_host_list(self):
fdir = os.path.dirname(os.path.realpath(__file__))
r1 = NmapParser.parse_fromfile("%s/%s" % (fdir, 'files/1_hosts.xml'))
r2 = NmapParser.parse_fromfile("%s/%s" % (fdir, 'files/2_hosts.xml'))
r3 = NmapParser.parse_fromfile("%s/%s" % (fdir, 'files/1_hosts.xml'))
r4 = NmapParser.parse_fromfile("%s/%s" % (fdir,
'files/2_hosts_achange.xml'))
d1 = r1.diff(r2)
self.assertEqual(d1.changed(), set(['hosts_total', 'commandline',
'hosts_up', 'scan_type',
'elapsed']))
self.assertEqual(d1.unchanged(), set(['hosts_down', 'version',
'NmapHost::127.0.0.1']))
self.assertEqual(d1.removed(), set(['NmapHost::74.207.244.221']))
d2 = r1.diff(r3)
self.assertEqual(d2.changed(), set([]))
self.assertEqual(d2.unchanged(), set(['hosts_total',
'commandline',
'hosts_up',
'NmapHost::127.0.0.1',
'elapsed',
'version',
'scan_type',
'hosts_down']))
self.assertEqual(d2.added(), set([]))
self.assertEqual(d2.removed(), set([]))
d3 = r2.diff(r4)
self.assertEqual(d3.changed(), set(['NmapHost::127.0.0.1']))
self.assertEqual(d3.unchanged(), set(['hosts_total',
'commandline',
'hosts_up',
'NmapHost::74.207.244.221',
'version',
'elapsed',
'scan_type',
'hosts_down']))
self.assertEqual(d3.added(), set([]))
self.assertEqual(d3.removed(), set([]))
if __name__ == '__main__':
test_suite = ['test_diff_host_list']
suite = unittest.TestSuite(map(TestNmapReportDiff, test_suite))
test_result = unittest.TextTestRunner(verbosity=2).run(suite)