def test_filter(self): instance = NetShow() instance.contents = INPUT method = instance.filter self.assertTrue(method([])) self.assertFalse(method(['nope', 'cant|match|this', 80])) self.assertTrue(method(['54101', '172.28.142.138', 'tcp|22'])) self.assertEqual(instance.results, [INPUT[1]])
def test_line_to_dict_udp6(self): instance = NetShow() instance.contents = INPUT method = instance.line_to_dict line = ' 16: 000080FE00000000FF565002BD69B1FE:007B 00000000000000000000000000000000:0000 07 00000000:00000000 00:00000000 00000000 0 0 9523 2 ffff880139b50400 0' i = INPUT[6].copy() i['pid'] = '' i['program'] = '' subject = method(line, 'udp6') subject['pid'] = '' subject['program'] = '' self.assertNotEqual(subject, INPUT[1]) self.assertEqual(subject, i)
def test_line_to_dict_tcp(self): instance = NetShow() instance.contents = INPUT method = instance.line_to_dict line = ' 0: 00000000:0016 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 9479 1 ffff880139ba5480 99 0 0 10 -1' i = INPUT[0].copy() i['pid'] = '' i['program'] = '' subject = method(line, 'tcp') subject['pid'] = '' subject['program'] = '' self.assertNotEqual(subject, INPUT[1]) self.assertEqual(subject, i)
def test_match_all_needles(self): instance = NetShow() method = instance.match_all_needles self.assertFalse(method(['4101', '972.28.142.138', 'udp|80'], INPUT[1])) self.assertTrue(method(['54101', '172.28.142.138', 'tcp|22'], INPUT[1]))
def test_convert_ip(self): instance = NetShow() method = instance._convert_ip self.assertEqual(method('00000000000000000000000000000000'), '::') self.assertEqual(method('000080FE00000000FF565002BD69B1FE'), 'fe80::250:56ff:feb1:69bd') self.assertEqual(method('00000000'), '0.0.0.0') self.assertEqual(method('8A8E1CAC'), '172.28.142.138')
def test_proc_to_dict(self): instance = NetShow() # instance.contents = INPUT method = instance.proc_to_dict self.assertTrue(isinstance(method('tcp'), list)) self.assertTrue(isinstance(method('udp'), list)) self.assertTrue(isinstance(method('tcp')[0], dict)) self.assertTrue(isinstance(method('udp')[0], dict))
def test_convert_ip_port(self): instance = NetShow() method = instance._convert_ip_port self.assertNotEqual(method('8A8E1CAC:007B'), ('fe80::250:56ff:feb1:69bd', '22')) self.assertNotEqual(method('000080FE00000000FF565002BD69B1FE:0016'), ('172.28.142.138', '123')) self.assertEqual(method('000080FE00000000FF565002BD69B1FE:0016'), ('fe80::250:56ff:feb1:69bd', '22')) self.assertEqual(method('8A8E1CAC:007B'), ('172.28.142.138', '123'))
def test_search_dict_values(self): instance = NetShow() method = instance.search_dict_values self.assertRaises(RegexError, method, '*', INPUT[0]) self.assertFalse(method('pattern', INPUT[0])) self.assertEqual(method('tcp', INPUT[0]), INPUT[0]) self.assertTrue(method('tcp', INPUT[0])) self.assertTrue(method('tcp|.*sshd$', INPUT[0])) self.assertTrue(method('0.0.0.0', INPUT[0])) self.assertTrue(method('1101', INPUT[0])) self.assertTrue(method('\*', INPUT[0])) self.assertTrue(method('LISTEN', INPUT[0])) self.assertTrue(method('.*', INPUT[0]))
def test_init(self): instance = NetShow() self.assertFalse(isinstance(instance, TestCase)) self.assertTrue(isinstance(instance, NetShow))
def test_remove_empty(self): instance = NetShow() method = instance._remove_empty self.assertNotEqual(method(['bob', ' ', 'pat', '']), ['bob', 'pat']) self.assertEqual(method(['bob', '', 'pat', '']), ['bob', 'pat'])
def test_hex2dec(self): instance = NetShow() method = instance._hex2dec self.assertEqual(method('00'), '0') self.assertEqual(method('007B'), '123') self.assertEqual(method('0016'), '22')
def test_filter_int(self): instance = NetShow() instance.contents = INPUT method = instance.filter self.assertFalse(method([80])) self.assertTrue(method([22]))
def test_usage(self): instance = NetShow() self.assertFalse('BROKEN = True' in instance.usage()) self.assertTrue('netshow.py, version 1.0' in instance.usage())
def test_default_attributes(self): instance = NetShow() self.assertFalse(instance.as_json) self.assertFalse(instance.as_dict) self.assertTrue(instance.use_header)