示例#1
0
def receive_task(payload, guid=None):
    """Process received payload."""
    profile = None
    if guid:
        try:
            profile = Profile.objects.get(guid=guid, user__isnull=False)
        except Profile.DoesNotExist:
            logger.warning("No local profile found with guid")
            return
    try:
        sender, protocol_name, entities = handle_receive(
            payload, user=profile, sender_key_fetcher=sender_key_fetcher)
        logger.debug("sender=%s, protocol_name=%s, entities=%s" %
                     (sender, protocol_name, entities))
    except NoSuitableProtocolFoundError:
        logger.warning("No suitable protocol found for payload")
        return
    except NoSenderKeyFoundError:
        logger.warning(
            "Could not find a public key for the sender - skipping payload")
        return
    except AssertionError:
        logger.warning("Signature validation failed - skipping payload")
        return
    if not entities:
        logger.warning("No entities in payload")
        return
    sender_profile = get_sender_profile(sender)
    if not sender_profile:
        return
    process_entities(entities, profile=sender_profile)
示例#2
0
def receive_task(request, uuid=None):
    # type: (RequestType, Optional[str]) -> None
    """Process received payload."""
    profile = None
    if uuid:
        try:
            profile = Profile.objects.get(uuid=uuid, user__isnull=False)
        except Profile.DoesNotExist:
            logger.warning("No local profile found with uuid")
            return
    try:
        sender, protocol_name, entities = handle_receive(
            request,
            user=profile.federable if profile else None,
            sender_key_fetcher=sender_key_fetcher,
        )
        logger.debug("sender=%s, protocol_name=%s, entities=%s" %
                     (sender, protocol_name, entities))
        preferences = global_preferences_registry.manager()
        if preferences["admin__log_all_receive_payloads"]:
            Payload.objects.create(
                body=request.body,
                direction="inbound",
                entities_found=len(entities),
                headers=request.headers,
                method=request.method,
                protocol=protocol_name or "",
                sender=sender or "",
                url=request.url,
            )
    except NoSuitableProtocolFoundError:
        logger.warning("No suitable protocol found for payload")
        return
    except NoSenderKeyFoundError:
        logger.warning(
            "Could not find a public key for the sender - skipping payload")
        return
    except SignatureVerificationError:
        logger.warning("Signature validation failed - skipping payload")
        return
    if not entities:
        logger.warning("No entities in payload")
        return
    process_entities(entities)
示例#3
0
 def test_process_entity_relationship_is_called(self, mock_sender,
                                                mock_process):
     process_entities([self.relationship])
     mock_process.assert_called_once_with(self.relationship, "profile")
示例#4
0
 def test_process_entity_comment_is_called(self, mock_sender, mock_process):
     process_entities([self.comment])
     mock_process.assert_called_once_with(self.comment, "profile")
示例#5
0
 def test_process_entity_retraction_is_called(self, mock_sender,
                                              mock_process):
     process_entities([self.retraction])
     mock_process.assert_called_once_with(self.retraction, "profile")
示例#6
0
 def test_logger_is_called_on_process_exception(self, mock_sender, mock_process, mock_logger):
     process_entities([self.post])
     self.assertEqual(mock_logger.called, 1)
示例#7
0
 def test_process_entity_post_is_called(self, mock_process):
     process_entities([self.post], profile=self.profile)
     mock_process.assert_called_once_with(self.post, self.profile)
示例#8
0
 def test_process_entity_share_is_called(self, mock_sender, mock_process):
     process_entities([self.share])
     mock_process.assert_called_once_with(self.share, "profile")
示例#9
0
 def test_process_entity_follow_is_called(self, mock_sender, mock_process):
     process_entities([self.follow])
     mock_process.assert_called_once_with(self.follow, "profile")
示例#10
0
 def test_process_entity_comment_is_called__with_receiving_profile(self, mock_sender, mock_process):
     process_entities([self.comment], receiving_profile=self.receiving_profile)
     mock_process.assert_called_once_with(self.comment, "profile", receiving_profile=self.receiving_profile)
示例#11
0
 def test_process_entity_retraction_is_called(self, mock_sender, mock_process):
     process_entities([self.retraction])
     mock_process.assert_called_once_with(self.retraction, "profile")
示例#12
0
 def test_process_entity_post_is_called(self, mock_sender, mock_process):
     process_entities([self.post])
     mock_process.assert_called_once_with(self.post, "profile", receiving_profile=None)
示例#13
0
 def test_process_entity_post_is_called__with_receiving_profile(
         self, mock_sender, mock_process):
     process_entities([self.post])
     mock_process.assert_called_once_with(self.post, "profile")
示例#14
0
 def test_process_entity_retraction_is_called(self, mock_process):
     process_entities([self.retraction], profile=self.profile)
     mock_process.assert_called_once_with(self.retraction, self.profile)
示例#15
0
 def test_process_entity_follow_is_called(self, mock_sender, mock_process):
     process_entities([self.follow])
     mock_process.assert_called_once_with(self.follow, "profile")
示例#16
0
 def test_process_entity_profile_is_called(self, mock_sender, mock_from):
     process_entities([self.profile])
     mock_from.assert_called_once_with(self.profile)
示例#17
0
 def test_process_entity_profile_is_called(self, mock_sender, mock_from):
     process_entities([self.profile])
     mock_from.assert_called_once_with(self.profile)
示例#18
0
 def test_process_entity_share_is_called(self, mock_sender, mock_process):
     process_entities([self.share])
     mock_process.assert_called_once_with(self.share, "profile")
示例#19
0
 def test_logger_is_called_on_process_exception(self, mock_sender,
                                                mock_process, mock_logger):
     process_entities([self.post])
     self.assertEqual(mock_logger.called, 1)
示例#20
0
 def test_process_entity_comment_is_called__with_receiving_profile(
         self, mock_sender, mock_process):
     process_entities([self.comment],
                      receiving_profile=self.receiving_profile)
     mock_process.assert_called_once_with(
         self.comment, "profile", receiving_profile=self.receiving_profile)