Esempio n. 1
0
 def test_master_dict(self):
     master = authparse.IpDict()
     for key in test_lines:
         ip = authparse.get_ip(test_lines[key])
         master.add_data(ip, authparse.LineInfo(test_lines[key]))
     keys = set([key for key in master.data])
     self.assertEqual(keys, ip_set)
Esempio n. 2
0
 def testIpDict_populate_from_sources(self):
     ip_dict = authparse.IpDict()
     no_ip_files = ip_dict.populate_from_source_files(self.logs_default)
     self.assertEqual(set(no_ip_files), set(self.logs_without_ips))
     if self.args["--output"]:
         with open(self.args["--output"], 'w') as f:
             f.write(ip_dict.show(self.args))
     else:
         print(ip_dict.show(self.args))
Esempio n. 3
0
 def setUp(self):
     self.args = {
         '--report': 1,
         '--demographics': False,
         '--frequency': False,
     }
     self.master = authparse.IpDict()
     for ip in w_ips:
         for k in test_lines.keys():
             line_info = authparse.LineInfo(test_lines['pub_key'])
             self.master.add_data(ip, line_info)
Esempio n. 4
0
 def test_0(self):
     master = authparse.IpDict()
     ip = '10.0.0.1'
     line_info = authparse.LineInfo(test_lines['pub_key'])
     master.add_data(ip, line_info)
     show = master.show(self.args)
     #       print('\n###\n{}\n###\n'.format(show))
     #       print('\n###\n{}\n###\n'
     #           .format(master.data[ip].show(self.args, ip)))
     self.assertEqual(
         show,
         'Remaining IP addresses (which are suspect:)\n10.0.0.1\n  Appearances: 1.'
     )
Esempio n. 5
0
 def test_add2ip_dict(self):
     ip_set = set()
     ip = "10.0.0.10"
     ip_set.add(ip)
     master = authparse.IpDict()
     master.add_data(ip, authparse.LineInfo(test_lines['invalid_user']))
     self.assertEqual(master.data[ip].data['invalid_user'], ['postgres'])
     master.add_data(ip, authparse.LineInfo(test_line1))
     self.assertEqual(master.data[ip].data['invalid_user'], [
         'postgres',
         'apache',
     ])
     master.add_data(ip, authparse.LineInfo(test_lines['no_id']))
     self.assertEqual(master.data[ip].data['no_id'], 1)
     ip = "10.1.0.10"
     ip_set.add(ip)
     master.add_data(ip, authparse.LineInfo(test_lines['no_id']))
     self.assertEqual(master.data[ip].data['no_id'], 1)
     self.assertEqual(set([key for key in master.data]), ip_set)
Esempio n. 6
0
 def setUp(self):
     cmd = CMD
     c_l_args = shlex.split(cmd)
     self.args = docopt(authparse.__doc__,
                        argv=c_l_args[1:],
                        help=True,
                        version=VERSION,
                        options_first=False)
     self.logs_default, self.whites, self.blacks = (
         authparse.collect_inputs(self.args))
     white_files_without_ips = []
     black_files_without_ips = []
     white_ips = authparse.get_ips(self.whites, white_files_without_ips)
     black_ips = authparse.get_ips(self.blacks, black_files_without_ips)
     masterIP_dict = authparse.IpDict()
     log_files_without_ips = (masterIP_dict.populate_from_source_files(
         self.logs_default))
     if not self.args["--quiet"]:
         self.name_list_tuples = (
             ('White:', white_files_without_ips),
             ('Black:', black_files_without_ips),
             ('Logs:', log_files_without_ips),
         )
         self.report = authparse.Report("Main Report Header")