def test_from_name(self): protocol_long = "PROTO_HTTPS" protocol_short = "https" from_long = Protocol.from_name(protocol_long) from_short = Protocol.from_pretty_name(protocol_short) self.assertEqual(from_long.value, from_short.value) self.assertEqual(from_long.value, zsearch_definitions.protocols.HTTPS.value)
def _make_prune_cmd(self, min_scan_ids): cmd = rpc_pb2.Command() for (host_port, pretty_protocol, pretty_subprotocol), min_scan_id in \ min_scan_ids.iteritems(): network_port = socket.htons(host_port) protocol = Protocol.from_pretty_name(pretty_protocol) subprotocol = Subprotocol.from_pretty_name(pretty_subprotocol) ak = hoststore_pb2.AnonymousKey( port=network_port, protocol=protocol.value, subprotocol=subprotocol.value, ) min_id_obj = cmd.min_scan_ids.add() min_id_obj.key.CopyFrom(ak) min_id_obj.min_scan_id = min_scan_id return cmd
def test_generic_subprotocols_exposed_as_attributes(self): proto_http = Protocol.from_pretty_name("http") self.assertTrue(hasattr(proto_http, "GET"))
def test_subprotocols_with_bonus_underscores(self): modbus = Protocol.from_pretty_name("modbus") self.assertTrue(hasattr(modbus, "DEVICE_ID")) self.assertFalse(hasattr(modbus, "MEI")) self.assertFalse(hasattr(modbus, "DEVICE"))