def test_check_port(self): """ Test check_port. """ check1 = utils.check_port(-1) check2 = utils.check_port(0) check3 = utils.check_port(40) check4 = utils.check_port(70000) self.assertEqual(check1, False) self.assertEqual(check2, True) self.assertEqual(check3, True) self.assertEqual(check4, False)
def parse_dest_portRule(self): """ Parse the destination port rules passed and generate destination ports list. Args: None Raises: None Returns: temp_dports (list): Parsed list of destination ports action (int): 0 or 1 """ try: temp_dports = [] action = int(self.cred['dest_portRule']['action']) if len(self.cred['dest_portRule']['dports']): dports = str(self.cred['dest_portRule']['dports']) dports = dports.split(',') for port in dports: if '-' in port: for new_port in utils.generate_ports(port): if (new_port not in temp_dports and utils.check_port(new_port)): temp_dports.append(str(new_port).strip()) elif utils.check_port(port): if port not in temp_dports: temp_dports.append(str(port).strip()) return temp_dports, action except Exception as e: self.logger.log("Error: " + str(e), logtype="error") # Return empty list and block action return [], 0