def test_handle_receive_routes_to_identified_protocol(self):
     payload = UNENCRYPTED_DIASPORA_PAYLOAD
     with patch.object(
                 Protocol,
                 'receive',
                 return_value=("*****@*****.**", "<foobar></foobar>")) as mock_receive,\
             patch(
                 "federation.entities.diaspora.mappers.message_to_objects",
                 return_value=[]) as mock_message_to_objects:
         handle_receive(payload)
         assert mock_receive.called
示例#2
0
def process(payload):
    """Open payload and route it to any pods that might be interested in it."""
    try:
        sender, protocol_name, entities = handle_receive(payload, skip_author_verification=True)
        logging.debug("sender=%s, protocol_name=%s, entities=%s" % (sender, protocol_name, entities))
    except NoSuitableProtocolFoundError:
        logging.warning("No suitable protocol found for payload")
        return
    if protocol_name != "diaspora":
        logging.warning("Unsupported protocol: %s, sender: %s" % (protocol_name, sender))
        return
    if not entities:
        logging.warning("No entities in payload")
        return
    send_to_pods = pods_who_want_all()
    send_to_pods += config.ALWAYS_FORWARD_TO_HOSTS
    if sender.split("@")[1] in send_to_pods:
        # Don't send back to sender
        send_to_pods.remove(sender.split("@")[1])
    for entity in entities:
        logging.info("Entity: %s" % entity)
        # We only care about posts atm
        if isinstance(entity, Post):
            # Add pods who want this posts tags
            final_send_to_pods = send_to_pods[:] + pods_who_want_tags(entity.tags)
            # Send out
            for pod in final_send_to_pods:
                send_payload(pod, payload)
示例#3
0
def process(payload):
    """Open payload and route it to any pods that might be interested in it."""
    try:
        sender, protocol_name, entities = handle_receive(payload, skip_author_verification=True)
        logging.debug("sender=%s, protocol_name=%s, entities=%s" % (sender, protocol_name, entities))
    except NoSuitableProtocolFoundError:
        logging.warning("No suitable protocol found for payload")
        return
    if protocol_name != "diaspora":
        logging.warning("Unsupported protocol: %s, sender: %s" % (protocol_name, sender))
        return
    if not entities:
        logging.warning("No entities in payload")
        return
    sent_amount = 0
    sent_success = 0
    try:
        for entity in entities:
            logging.info("Entity: %s" % entity)
            # We only care about posts atm
            if isinstance(entity, SUPPORTED_ENTITIES):
                sent_to_nodes = []
                nodes = get_send_to_nodes(sender, entity)
                # Send out
                for node in nodes:
                    response = send_payload(node, payload)
                    if response["result"]:
                        sent_success += 1
                        sent_to_nodes.append(node)
                    sent_amount += 1
                    update_node(node, response)
                if sent_to_nodes and isinstance(entity, DiasporaPost):
                    save_post_metadata(entity=entity, protocol=protocol_name, hosts=sent_to_nodes)
    finally:
        log_worker_receive_statistics(
            protocol_name, len(entities), sent_amount, sent_success
        )
示例#4
0
def process(payload):
    """Open payload and route it to any pods that might be interested in it."""
    try:
        sender, protocol_name, entities = handle_receive(payload, skip_author_verification=True)
        logging.debug("sender=%s, protocol_name=%s, entities=%s" % (sender, protocol_name, entities))
    except NoSuitableProtocolFoundError:
        logging.warning("No suitable protocol found for payload")
        return
    if protocol_name != "diaspora":
        logging.warning("Unsupported protocol: %s, sender: %s" % (protocol_name, sender))
        return
    if not entities:
        logging.warning("No entities in payload")
        return
    sent_amount = 0
    sent_success = 0
    try:
        for entity in entities:
            logging.info("Entity: %s" % entity)
            # We only care about posts atm
            if isinstance(entity, SUPPORTED_ENTITIES):
                sent_to_nodes = []
                nodes = get_send_to_nodes(sender, entity)
                # Send out
                for node in nodes:
                    response = send_payload(node, payload)
                    if response["result"]:
                        sent_success += 1
                        sent_to_nodes.append(node)
                    sent_amount += 1
                    update_node(node, response)
                if sent_to_nodes and isinstance(entity, DiasporaPost):
                    save_post_metadata(entity=entity, protocol=protocol_name, hosts=sent_to_nodes)
    finally:
        log_worker_receive_statistics(
            protocol_name, len(entities), sent_amount, sent_success
        )
 def test_handle_receive_raises_on_unidentified_protocol(self):
     payload = "foobar"
     with pytest.raises(NoSuitableProtocolFoundError):
         handle_receive(payload)