Example #1
0
 def testMkReportObfuscSimple(self):
     argv = ["-o", "simple"]
     options = Carl.parse_cmdline(argv)[0]
     ret = Carl.mkreport(options, self.stats)
     for (key, value) in self.stats["ip2hname"].items():
         self.assertNotIn(key, ret)
         self.assertNotIn(value, ret)
Example #2
0
def testGarbage():
    mocked_sys_stderr = mock.MagicMock()
    mocked_sys_stderr.write = mock.MagicMock()
    saved_sys_exit = Carl.sys.exit
    saved_stderr = Carl.sys.stderr
    Carl.sys.stderr = mocked_sys_stderr
    Carl.parsedata("I have no log and I must scream.")
    Carl.sys.exit = saved_sys_exit
    # We don't really care about _what_ was written. Or anything at all.
    Carl.sys.stderr = saved_stderr
Example #3
0
 def testParseCmdlineVerboseWithStdin(self):
     argv = ["-o", "fancy", "-r"]
     (options, _, errmsgs) = Carl.parse_cmdline(argv)
     self.assertEqual(options.shortoutput, False)
     self.assertEqual(options.ostyle, "fancy")
     self.assertEqual(options.reverse, True)
     self.assertEqual(errmsgs, [])
Example #4
0
 def testParseCmdline(self):
     argv = ["-o", "fancy", "-r", "-s"]
     (options, msgs, errmsgs) = Carl.parse_cmdline(argv)
     self.assertEqual(options.shortoutput, True)
     self.assertEqual(options.ostyle, "fancy")
     self.assertEqual(options.reverse, True)
     self.assertEqual(msgs, [])
     self.assertEqual(errmsgs, [])
Example #5
0
 def testObFancy(self):
     golden = [
         ("eenie", "b7259125...fd872fa5"),
         ("meenie", "9d9b3703...5ae754db"),
         ("miney", "3751a98b...89aad47b"),
         ("moe", "1b9fd716...9196f82f"),
     ]
     for (inp, out) in golden:
         self.assertEqual(out, Carl.obfuscate(inp, "fancy"))
Example #6
0
    def testMkReport(self):
        argv = []
        options = Carl.parse_cmdline(argv)[0]
        ret = Carl.mkreport(options, self.stats)
        for (key, value) in self.stats["ip2hname"].items():
            self.assertIn(key, ret)
            self.assertIn(value, ret)

        self.assertIn("Total traffic: 72.00 GBytes", ret)
        self.assertIn("Total number of sessions: 1000", ret)
        self.assertIn(
            "Total number of unique IPs: %i" % len(self.stats["ip2hname"]),
            ret)
        self.assertIn("Log seems to span 86400.00 days.", ret)
        self.assertIn("account for 60 sessions", ret)
        self.assertIn(
            "1000000000 lines in 1.00 seconds, "
            "1000000000.00 lines per second", ret)
Example #7
0
 def testObNone(self):
     golden = [
         "127.0.0.1",
         "192.168.65.3",
         "172.19.22.4",
         "2001::a:b:c:d",
         "2001:db8:a:b:c::",
     ]
     for inp in golden:
         self.assertEqual(inp, Carl.obfuscate(inp, ""))
Example #8
0
 def testObSimple(self):
     golden = [
         ("127.0.0.1", "127.0..."),
         ("192.168.65.3", "192.168..."),
         ("172.19.22.4", "172.19..."),
         ("10.4.2.65", "10.4..."),
         ("2001::a:b:c:d", "2001:..."),
         ("2001:db8:a:b:c::", "2001:db8..."),
         ("::1", "::1"),
     ]
     for (inp, out) in golden:
         self.assertEqual(out, Carl.obfuscate(inp, "simple"))
Example #9
0
 def testCrunchSIDev(self):
     golden = [
         (1, (1, 0)),
         (1000, (1, 1)),
         (1001, (1.001, 1)),
         (4000, (4, 1)),
         (8000, (8, 1)),
         (10000, (10, 1)),
         (894352, (894.352, 1)),
         (3465298345823, (3.465298345823, 4)),
     ]
     for (inp, out) in golden:
         (res, mag) = Carl.crunch(inp, 1000)
         self.assertAlmostEqual(res, out[0])
         self.assertEqual(mag, out[1])
Example #10
0
 def testCrunchDefDiv(self):
     golden = [
         (1, (1, 0)),
         (512, (512, 0)),
         (1024, (1, 1)),
         (1025, (1.0009765625, 1)),
         (4096, (4, 1)),
         (8192, (8, 1)),
         (10240, (10, 1)),
         (894352, (873.390625, 1)),
         (3465298345823, (3.1516704855, 4)),
     ]
     for (inp, out) in golden:
         (res, mag) = Carl.crunch(inp)
         self.assertAlmostEqual(res, out[0])
         self.assertEqual(mag, out[1])
Example #11
0
def testNumbersWithCommas():
    inp = open("testdata/test_commas_in_numbers.log").read()
    Carl.parsedata(inp)
Example #12
0
def testSession():
    inp = open("testdata/test_snippet1.log").read()
    Carl.parsedata(inp)
Example #13
0
def testGarbageMulti():
    Carl.parsedata("Demogorgon")
Example #14
0
def testNoLines():
    Carl.parsedata("")