예제 #1
0
	def testDiffClassSameIp(self):
		"""For multiple connections from the same IP address with different classes, we should count correctly."""
		self._start(1)
		conntrack.up(2, '127.0.0.1', ('ALL', 'foo'))
		self.assertEqual(conntrack.classcount('ALL'), 2)
		self.assertEqual(conntrack.classcount('foo'), 1)
		conntrack.down(1)
		self.assertEqual(conntrack.classcount('ALL'), 1)
		self.assertEqual(conntrack.classcount('foo'), 1)
예제 #2
0
	def testManyClasses(self):
		"""We should correctly add to each class for multi-class connections."""
		conntrack._clearmaps()
		conntrack.up(1, '127.0.0.1', ('foo', 'bar'))
		self.assertEqual(conntrack.classcount('foo'), 1)
		self.assertEqual(conntrack.classcount('bar'), 1)
		conntrack.down(1)
		self.assertEqual(conntrack.classcount('foo'), 0)
		self.assertEqual(conntrack.classcount('bar'), 0)
		self.assertEqual(len(conntrack.activeclasses()), 0)
예제 #3
0
	def testMultiClassConnects(self):
		"""We should correctly count how many times a given class is active, even with differnet IPs."""
		self._start(1)
		conntrack.up(2, '127.0.0.2', ('ALL',))
		self.assertEqual(conntrack.classcount('ALL'), 2)
		conntrack.up(3, '127.0.0.3', ('ALL',))
		self.assertEqual(conntrack.classcount('ALL'), 3)
		conntrack.down(1)
		self.assertEqual(conntrack.classcount('ALL'), 2)
		conntrack.down(3)
		self.assertEqual(conntrack.classcount('ALL'), 1)
예제 #4
0
	def doesfail(self, hi, what, cls = None):
		if what not in self.dirs:
			return False
		if not cls:
			cls = self
		val = self.dirs[what]
		if what == "reject":
			return True
		elif what == "ipmax":
			return conntrack.ipcount(hi.getip()) >= val
		else:
			return conntrack.classcount(cls.name) >= val
예제 #5
0
	def testInsertRemove(self):
		"""If we insert then remove, the result should be null."""
		self._start(1)
		conntrack.down(1)
		self.assertEqual(conntrack.ipcount('127.0.0.1'), 0)
		self.assertEqual(conntrack.classcount('ALL'), 0)
예제 #6
0
	def testInsert(self):
		"""If we insert, we should get expected results."""
		self._start(1)
		self.assertEqual(conntrack.ipcount('127.0.0.1'), 1)
		self.assertEqual(conntrack.classcount('ALL'), 1)
예제 #7
0
	def testEmptyCount(self):
		"Test that we can get a zero count for values not in the system"
		conntrack._clearmaps()
		self.assertEqual(conntrack.ipcount("127.100.100.0"), 0)
		self.assertEqual(conntrack.classcount("FOOBAR"), 0)