示例#1
0
 def test_with_malformed_runlevel(self):
     try:
         list(read_tor_log(data_path('malformed_runlevel')))
         self.fail("Malformed content should've raised a ValueError")
     except ValueError as exc:
         self.assertTrue(
             'has an unrecognized runlevel: [unrecognized]' in str(exc))
示例#2
0
  def test_with_multiple_tor_instances(self):
    entries = list(read_tor_log(data_path('multiple_tor_instances')))
    self.assertEqual(12, len(entries))

    self.assertEqual('parse_dir_authority_line(): Trusted 100 dirserver at 128.31.0.39:9131 (9695)', entries[0].message)
    self.assertEqual('tor_lockfile_lock(): Locking "/home/atagar/.tor/lock"', entries[1].message)
    self.assertEqual('Tor 0.2.7.0-alpha-dev (git-4247ce99e5d9b7b2) opening log file.', entries[-1].message)
示例#3
0
 def test_with_malformed_line(self):
     try:
         list(read_tor_log(data_path('malformed_line')))
         self.fail("Malformed content should've raised a ValueError")
     except ValueError as exc:
         self.assertTrue(
             "has a line that doesn't match the format we expect: Apr 06 11:03:53.000"
             in str(exc))
示例#4
0
    def test_general_log(self):
        entries = list(read_tor_log(data_path('tor_log')))
        self.assertEqual(21, len(entries))

        self.assertEqual('Interrupt: exiting cleanly.', entries[0].message)
        self.assertEqual(
            'Tor 0.2.7.0-alpha-dev (git-4247ce99e5d9b7b2) opening new log file.',
            entries[-1].message)
示例#5
0
 def test_with_malformed_date(self):
     try:
         list(read_tor_log(data_path('malformed_date')))
         self.fail("Malformed content should've raised a ValueError")
     except ValueError as exc:
         self.assertTrue(
             "has a timestamp we don't recognize: Zed 06 11:03:52.000" in
             str(exc))
示例#6
0
  def test_deduplication_with_daybreaks(self):
    group = LogGroup(100, group_by_day = True)
    test_log_path = os.path.join(os.path.dirname(__file__), 'data', 'daybreak_deduplication')

    for entry in reversed(list(read_tor_log(test_log_path))):
      group.add(entry)

    # Entries should consist of two days of results...
    #
    # Day 1:
    # 10:24:27 [NOTICE] New control connection opened from 127.0.0.1.
    # 10:21:31 [NOTICE] New control connection opened from 127.0.0.1.
    # 10:19:24 [NOTICE] New control connection opened from 127.0.0.1.
    # 10:16:38 [NOTICE] New control connection opened from 127.0.0.1.
    # 10:16:38 [NOTICE] New control connection opened from 127.0.0.1.
    # 05:44:40 [NOTICE] Heartbeat: Tor's uptime is 18:00 hours, with 0 circuits open. I've sent 862 kB and received 9.05 MB.
    #
    # Day 2:
    # 23:44:40 [NOTICE] Heartbeat: Tor's uptime is 12:00 hours, with 1 circuits open. I've sent 794 kB and received 7.32 MB.
    # 19:02:44 [NOTICE] New control connection opened from 127.0.0.1.
    # 18:52:47 [NOTICE] New control connection opened from 127.0.0.1.
    # 18:11:56 [NOTICE] New control connection opened from 127.0.0.1.
    # 17:44:40 [NOTICE] Heartbeat: Tor's uptime is 6:00 hours, with 0 circuits open. I've sent 539 kB and received 4.25 MB.
    # 11:45:03 [NOTICE] New control connection opened from 127.0.0.1.
    # 11:44:49 [NOTICE] Bootstrapped 100%: Done
    # ... etc...

    group_items = list(group)

    # First day

    self.assertEqual('New control connection opened from 127.0.0.1.', group_items[0].message)
    self.assertEqual(5, len(group_items[0].duplicates))
    self.assertFalse(group_items[0].is_duplicate)

    for entry in group_items[1:5]:
      self.assertEqual('New control connection opened from 127.0.0.1.', entry.message)
      self.assertEqual(5, len(entry.duplicates))
      self.assertTrue(entry.is_duplicate)

    self.assertEqual("Heartbeat: Tor's uptime is 18:00 hours, with 0 circuits open. I've sent 862 kB and received 9.05 MB.", group_items[5].message)
    self.assertEqual(None, group_items[5].duplicates)
    self.assertFalse(group_items[5].is_duplicate)

    # Second day

    self.assertEqual("Heartbeat: Tor's uptime is 12:00 hours, with 1 circuits open. I've sent 794 kB and received 7.32 MB.", group_items[6].message)
    self.assertEqual(2, len(group_items[6].duplicates))
    self.assertFalse(group_items[6].is_duplicate)

    self.assertEqual('New control connection opened from 127.0.0.1.', group_items[8].message)
    self.assertEqual(4, len(group_items[8].duplicates))
    self.assertTrue(group_items[8].is_duplicate)

    self.assertEqual("Heartbeat: Tor's uptime is 6:00 hours, with 0 circuits open. I've sent 539 kB and received 4.25 MB.", group_items[10].message)
    self.assertEqual(2, len(group_items[10].duplicates))
    self.assertTrue(group_items[10].is_duplicate)
示例#7
0
    def test_with_multiple_tor_instances(self):
        entries = list(read_tor_log(data_path('multiple_tor_instances')))
        self.assertEqual(12, len(entries))

        self.assertEqual(
            'parse_dir_authority_line(): Trusted 100 dirserver at 128.31.0.39:9131 (9695)',
            entries[0].message)
        self.assertEqual(
            'tor_lockfile_lock(): Locking "/home/atagar/.tor/lock"',
            entries[1].message)
        self.assertEqual(
            'Tor 0.2.7.0-alpha-dev (git-4247ce99e5d9b7b2) opening log file.',
            entries[-1].message)
示例#8
0
 def test_with_malformed_date(self):
   try:
     list(read_tor_log(data_path('malformed_date')))
     self.fail("Malformed content should've raised a ValueError")
   except ValueError as exc:
     self.assertTrue("has a timestamp we don't recognize: Zed 06 11:03:52.000" in str(exc))
示例#9
0
 def test_with_read_limit(self):
   entries = list(read_tor_log(data_path('tor_log'), 5))
   self.assertEqual(5, len(entries))
   self.assertEqual('Interrupt: exiting cleanly.', entries[0].message)
   self.assertEqual('Bootstrapped 90%: Establishing a Tor circuit', entries[-1].message)
示例#10
0
 def test_with_empty_file(self):
   entries = list(read_tor_log(data_path('empty_file')))
   self.assertEqual(0, len(entries))
示例#11
0
 def test_with_missing_path(self):
     self.assertRaises(IOError, list,
                       read_tor_log(data_path('no_such_path')))
示例#12
0
 def test_with_empty_file(self):
     entries = list(read_tor_log(data_path('empty_file')))
     self.assertEqual(0, len(entries))
示例#13
0
 def test_with_read_limit(self):
     entries = list(read_tor_log(data_path('tor_log'), 5))
     self.assertEqual(5, len(entries))
     self.assertEqual('Interrupt: exiting cleanly.', entries[0].message)
     self.assertEqual('Bootstrapped 90%: Establishing a Tor circuit',
                      entries[-1].message)
示例#14
0
 def test_with_missing_path(self):
   self.assertRaises(IOError, list, read_tor_log(data_path('no_such_path')))
示例#15
0
  def test_general_log(self):
    entries = list(read_tor_log(data_path('tor_log')))
    self.assertEqual(21, len(entries))

    self.assertEqual('Interrupt: exiting cleanly.', entries[0].message)
    self.assertEqual('Tor 0.2.7.0-alpha-dev (git-4247ce99e5d9b7b2) opening new log file.', entries[-1].message)
示例#16
0
 def test_with_malformed_runlevel(self):
   try:
     list(read_tor_log(data_path('malformed_runlevel')))
     self.fail("Malformed content should've raised a ValueError")
   except ValueError as exc:
     self.assertTrue('has an unrecognized runlevel: [unrecognized]' in str(exc))
示例#17
0
 def test_with_malformed_line(self):
   try:
     list(read_tor_log(data_path('malformed_line')))
     self.fail("Malformed content should've raised a ValueError")
   except ValueError as exc:
     self.assertTrue("has a line that doesn't match the format we expect: Apr 06 11:03:53.000" in str(exc))