예제 #1
0
 def test_02_make_partitions_0(self):
     """Chain_Test: make partitions from no rules"""
     c = Chain("INPUT", "ACCEPT")
     self.assertEquals("INPUT", c.name)
     self.assertEquals("ACCEPT", c.policy)
     self.assertEquals(0, c.make_partitions())
     self.assertEquals([], c.partitions)
예제 #2
0
 def test_02_make_partitions_0(self):
     """Chain_Test: make partitions from no rules"""
     c = Chain("INPUT", "ACCEPT")
     self.assertEquals("INPUT", c.name)
     self.assertEquals("ACCEPT", c.policy)
     self.assertEquals(0, c.make_partitions())
     self.assertEquals([], c.partitions)
예제 #3
0
 def test_10_empty_opti_0(self):
     """Chain_Test: optimize an empty chainobject"""
     c = Chain("SECOND_CHAIN", "ACCEPT")
     self.assertEquals("SECOND_CHAIN", c.name)
     self.assertEquals("ACCEPT", c.policy)
     self.assertEquals([], c.liste)
     self.assertEquals([], c.cntrs)
     self.assertEquals([], c.bytes)
     self.assertEquals([], c.partitions)
     self.assertEquals((0, 0), c.opti())
예제 #4
0
 def test_06_make_partitions_1l(self):
     """Chain_Test: make partitions from one rule l"""
     c = Chain("INPUT", "ACCEPT")
     self.assertEquals("INPUT", c.name)
     self.assertEquals("ACCEPT", c.policy)
     # part 1: 1 - 1
     line = '[9:10] -A INPUT -p tcp -m tcp --dport 23 -j LOG'
     c.append(line.split(" "))
     self.assertEquals(1, c.make_partitions())
     self.assertEquals([[1, 1]], c.partitions)
예제 #5
0
 def test_10_empty_opti_0(self):
     """Chain_Test: optimize an empty chainobject"""
     c = Chain("SECOND_CHAIN", "ACCEPT")
     self.assertEquals("SECOND_CHAIN", c.name)
     self.assertEquals("ACCEPT", c.policy)
     self.assertEquals([], c.liste)
     self.assertEquals([], c.cntrs)
     self.assertEquals([], c.bytes)
     self.assertEquals([], c.partitions)
     self.assertEquals((0, 0), c.opti())
예제 #6
0
 def test_06_make_partitions_1l(self):
     """Chain_Test: make partitions from one rule l"""
     c = Chain("INPUT", "ACCEPT")
     self.assertEquals("INPUT", c.name)
     self.assertEquals("ACCEPT", c.policy)
     # part 1: 1 - 1
     line = '[9:10] -A INPUT -p tcp -m tcp --dport 23 -j LOG'
     c.append(line.split(" "))
     self.assertEquals(1, c.make_partitions())
     self.assertEquals([[1, 1]], c.partitions)
예제 #7
0
 def test_12_insert_three_aar(self):
     """Chain_Test: optimize three rules aar"""
     c = Chain("INPUT", "ACCEPT")
     self.assertEquals("INPUT", c.name)
     self.assertEquals("ACCEPT", c.policy)
     line = '[9:10] -A INPUT -p tcp -m tcp --dport 23 -j ACCEPT'
     c.append(line.split(" "))
     self.assertEquals([[
         '[9:10]', '-A', 'INPUT', '-p', 'tcp', '-m', 'tcp', '--dport', '23',
         '-j', 'ACCEPT'
     ]], c.liste)
     counters = line.split(" ")[0]
     (cnt, byt) = extract_pkt_cntr(counters)
     self.assertEquals(['9'], c.cntrs)
     self.assertEquals(['10'], c.bytes)
     line = '[18:20] -A INPUT -i sl0 -j ACCEPT'
     self.assertEquals(None, c.append(line.split(" ")))
     line = '[28:220] -A INPUT -i lo -j REJECT'
     self.assertEquals(None, c.append(line.split(" ")))
     result = [[
         '[9:10]', '-A', 'INPUT', '-p', 'tcp', '-m', 'tcp', '--dport', '23',
         '-j', 'ACCEPT'
     ], ['[18:20]', '-A', 'INPUT', '-i', 'sl0', '-j', 'ACCEPT'],
               ['[28:220]', '-A', 'INPUT', '-i', 'lo', '-j', 'REJECT']]
     self.assertEquals(result, c.liste)
     self.assertEquals(2, c.make_partitions())
     self.assertEquals([[1, 2], [3, 3]], c.partitions)
     self.assertEquals((3, 2), c.opti())
예제 #8
0
 def test_12_insert_three_aar(self):
     """Chain_Test: optimize three rules aar"""
     c = Chain("INPUT", "ACCEPT")
     self.assertEquals("INPUT", c.name)
     self.assertEquals("ACCEPT", c.policy)
     line = '[9:10] -A INPUT -p tcp -m tcp --dport 23 -j ACCEPT'
     c.append(line.split(" "))
     self.assertEquals([['[9:10]', '-A', 'INPUT', '-p', 'tcp',
                     '-m', 'tcp',
                     '--dport', '23', '-j', 'ACCEPT']], c.liste)
     counters = line.split(" ")[0]
     (cnt, byt) = extract_pkt_cntr(counters)
     self.assertEquals(['9'], c.cntrs)
     self.assertEquals(['10'], c.bytes)
     line = '[18:20] -A INPUT -i sl0 -j ACCEPT'
     self.assertEquals(None, c.append(line.split(" ")))
     line = '[28:220] -A INPUT -i lo -j REJECT'
     self.assertEquals(None, c.append(line.split(" ")))
     result = [['[9:10]', '-A', 'INPUT', '-p', 'tcp', '-m', 'tcp',
                 '--dport', '23', '-j', 'ACCEPT'],
             ['[18:20]', '-A', 'INPUT', '-i', 'sl0', '-j', 'ACCEPT'],
             ['[28:220]', '-A', 'INPUT', '-i', 'lo', '-j', 'REJECT']]
     self.assertEquals(result, c.liste)
     self.assertEquals(2, c.make_partitions())
     self.assertEquals([[1, 2], [3, 3]], c.partitions)
     self.assertEquals((3, 2), c.opti())
예제 #9
0
 def test_01_create_a_chainobject(self):
     """Chain_Test: create a chainobject"""
     c = Chain("FIRST_CHAIN", "ACCEPT")
     self.assertEquals("FIRST_CHAIN", c.name)
     self.assertEquals("ACCEPT", c.policy)
     self.assertEquals([], c.liste)
     self.assertEquals([], c.cntrs)
     self.assertEquals([], c.bytes)
     self.assertEquals([], c.partitions)
예제 #10
0
 def test_07_make_partitions_2a(self):
     """Chain_Test: make partitions from two rules aa"""
     c = Chain("INPUT", "ACCEPT")
     self.assertEquals("INPUT", c.name)
     self.assertEquals("ACCEPT", c.policy)
     # part 1: 1 - 2
     line = '[9:10] -A INPUT -p tcp -m tcp --dport 23 -j ACCEPT'
     c.append(line.split(" "))
     line = '[18:23] -A INPUT -i sl0 -j ACCEPT'
     c.append(line.split(" "))
     self.assertEquals(1, c.make_partitions())
     self.assertEquals([[1, 2]], c.partitions)
예제 #11
0
 def test_08_make_partitions_2ad(self):
     """Chain_Test: make partitions from two rules ad"""
     c = Chain("INPUT", "ACCEPT")
     self.assertEquals("INPUT", c.name)
     self.assertEquals("ACCEPT", c.policy)
     # part 1: 1 - 1
     line = '[9:10] -A INPUT -p tcp -m tcp --dport 23 -j ACCEPT'
     c.append(line.split(" "))
     # part 2: 2 - 2
     line = '[18:23] -A INPUT -i sl2 -j DROP'
     c.append(line.split(" "))
     self.assertEquals(2, c.make_partitions())
     self.assertEquals([[1, 1], [2, 2]], c.partitions)
예제 #12
0
 def test_07_make_partitions_2a(self):
     """Chain_Test: make partitions from two rules aa"""
     c = Chain("INPUT", "ACCEPT")
     self.assertEquals("INPUT", c.name)
     self.assertEquals("ACCEPT", c.policy)
     # part 1: 1 - 2
     line = '[9:10] -A INPUT -p tcp -m tcp --dport 23 -j ACCEPT'
     c.append(line.split(" "))
     line = '[18:23] -A INPUT -i sl0 -j ACCEPT'
     c.append(line.split(" "))
     self.assertEquals(1, c.make_partitions())
     self.assertEquals([[1, 2]], c.partitions)
예제 #13
0
 def test_08_make_partitions_2ad(self):
     """Chain_Test: make partitions from two rules ad"""
     c = Chain("INPUT", "ACCEPT")
     self.assertEquals("INPUT", c.name)
     self.assertEquals("ACCEPT", c.policy)
     # part 1: 1 - 1
     line = '[9:10] -A INPUT -p tcp -m tcp --dport 23 -j ACCEPT'
     c.append(line.split(" "))
     # part 2: 2 - 2
     line = '[18:23] -A INPUT -i sl2 -j DROP'
     c.append(line.split(" "))
     self.assertEquals(2, c.make_partitions())
     self.assertEquals([[1, 1], [2, 2]], c.partitions)
예제 #14
0
 def test_09_make_partitions_5ada(self):
     """Chain_Test: make partitions from five rules adaaa"""
     c = Chain("INPUT", "ACCEPT")
     self.assertEquals("INPUT", c.name)
     self.assertEquals("ACCEPT", c.policy)
     # part 1: 1 - 1
     line = '[9:10] -A INPUT -p tcp -m tcp --dport 23 -j ACCEPT'
     self.assertEquals(None, c.append(line.split(" ")))
     # part 2: 2 - 2
     line = '[18:20] -A INPUT -i sl0 -j DROP'
     self.assertEquals(None, c.append(line.split(" ")))
     # part 3: 3 - 5
     line = '[18:20] -A INPUT -i sl1 -j ACCEPT'
     self.assertEquals(None, c.append(line.split(" ")))
     line = '[18:20] -A INPUT -i sl2 -j ACCEPT'
     self.assertEquals(None, c.append(line.split(" ")))
     line = '[28:220] -A INPUT -i lo -j ACCEPT'
     self.assertEquals(None, c.append(line.split(" ")))
     #   print "L:", c.liste
     self.assertEquals(3, c.make_partitions())
     self.assertEquals([[1, 1], [2, 2], [3, 5]], c.partitions)
예제 #15
0
 def test_09_make_partitions_5ada(self):
     """Chain_Test: make partitions from five rules adaaa"""
     c = Chain("INPUT", "ACCEPT")
     self.assertEquals("INPUT", c.name)
     self.assertEquals("ACCEPT", c.policy)
     # part 1: 1 - 1
     line = '[9:10] -A INPUT -p tcp -m tcp --dport 23 -j ACCEPT'
     self.assertEquals(None, c.append(line.split(" ")))
     # part 2: 2 - 2
     line = '[18:20] -A INPUT -i sl0 -j DROP'
     self.assertEquals(None, c.append(line.split(" ")))
     # part 3: 3 - 5
     line = '[18:20] -A INPUT -i sl1 -j ACCEPT'
     self.assertEquals(None, c.append(line.split(" ")))
     line = '[18:20] -A INPUT -i sl2 -j ACCEPT'
     self.assertEquals(None, c.append(line.split(" ")))
     line = '[28:220] -A INPUT -i lo -j ACCEPT'
     self.assertEquals(None, c.append(line.split(" ")))
     #   print "L:", c.liste
     self.assertEquals(3, c.make_partitions())
     self.assertEquals([[1, 1], [2, 2], [3, 5]], c.partitions)
예제 #16
0
 def test_14_insert_five_rules_with_logdrop(self):
     """Chain_Test: optimize five rules aalaa"""
     c = Chain("INPUT", "DROP")
     self.assertEquals("INPUT", c.name)
     self.assertEquals("DROP", c.policy)
     line = '[9:10] -A INPUT -p tcp -m tcp --dport 23 -j ACCEPT'
     c.append(line.split(" "))
     line = '[18:20] -A INPUT -i sl0 -j ACCEPT'
     c.append(line.split(" "))
     line = '[83:436] -A INPUT -j logdrop'
     c.append(line.split(" "))
     line = '[28:220] -A INPUT -i lo -j ACCEPT'
     c.append(line.split(" "))
     line = '[18:20] -A INPUT -i sl1 -j ACCEPT'
     c.append(line.split(" "))
     result = [[
         '[9:10]', '-A', 'INPUT', '-p', 'tcp', '-m', 'tcp', '--dport', '23',
         '-j', 'ACCEPT'
     ], ['[18:20]', '-A', 'INPUT', '-i', 'sl0', '-j', 'ACCEPT'],
               ['[83:436]', '-A', 'INPUT', '-j', 'logdrop'],
               ['[28:220]', '-A', 'INPUT', '-i', 'lo', '-j', 'ACCEPT'],
               ['[18:20]', '-A', 'INPUT', '-i', 'sl1', '-j', 'ACCEPT']]
     self.assertEquals(result, c.liste)
     self.assertEquals(3, c.make_partitions())
     expect = [[1, 2], [3, 3], [4, 5]]
     #print "P:", c.partitions
     #print "W:", expect, " ... or something like that"
     self.assertEquals(expect, c.partitions)
예제 #17
0
 def test_14_insert_five_rules_with_logdrop(self):
     """Chain_Test: optimize five rules aalaa"""
     c = Chain("INPUT", "DROP")
     self.assertEquals("INPUT", c.name)
     self.assertEquals("DROP", c.policy)
     line = '[9:10] -A INPUT -p tcp -m tcp --dport 23 -j ACCEPT'
     c.append(line.split(" "))
     line = '[18:20] -A INPUT -i sl0 -j ACCEPT'
     c.append(line.split(" "))
     line = '[83:436] -A INPUT -j logdrop'
     c.append(line.split(" "))
     line = '[28:220] -A INPUT -i lo -j ACCEPT'
     c.append(line.split(" "))
     line = '[18:20] -A INPUT -i sl1 -j ACCEPT'
     c.append(line.split(" "))
     result = [['[9:10]', '-A', 'INPUT', '-p', 'tcp', '-m', 'tcp',
                 '--dport', '23', '-j', 'ACCEPT'],
                 ['[18:20]', '-A', 'INPUT', '-i', 'sl0', '-j', 'ACCEPT'],
                 ['[83:436]', '-A', 'INPUT', '-j', 'logdrop'],
                 ['[28:220]', '-A', 'INPUT', '-i', 'lo', '-j', 'ACCEPT'],
                 ['[18:20]', '-A', 'INPUT', '-i', 'sl1', '-j', 'ACCEPT']]
     self.assertEquals(result, c.liste)
     self.assertEquals(3, c.make_partitions())
     expect = [[1, 2], [3, 3], [4, 5]]
     #print "P:", c.partitions
     #print "W:", expect, " ... or something like that"
     self.assertEquals(expect, c.partitions)