def test_generate_ports(self): """ Test generate_ports. """ dummy_list = [60, 61, 62] result = [] for port in utils.generate_ports('60-62'): result.append(port) self.assertEqual(dummy_list, result)
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