def test_handle_create_payload_calls_get_outbound_entity(self, mock_get_outbound_entity): mock_get_outbound_entity.return_value = DiasporaPost() from_user = Mock(private_key=RSA.generate(2048), handle="*****@*****.**") to_user = Mock(key=RSA.generate(2048).publickey()) entity = DiasporaPost() handle_create_payload(from_user, to_user, entity) assert mock_get_outbound_entity.called
def test_handle_create_payload_builds_an_xml(self, mock_protocol_class): mock_protocol = Mock() mock_protocol_class.return_value = mock_protocol from_user = Mock() entity = DiasporaPost() handle_create_payload(entity, from_user) mock_protocol.build_send.assert_called_once_with(entity=entity, from_user=from_user, to_user=None)
def send_content(content_id): """Handle sending a Content object out via the federation layer. Currently we only deliver public content. """ try: content = Content.objects.get(id=content_id) except Content.DoesNotExist: logger.warning("No content found with id %s", content_id) return if not content.visibility == Visibility.PUBLIC: return entity = make_federable_entity(content) if entity: if settings.DEBUG: # Don't send in development mode return # TODO: federation should provide one method to send, # which handles also payload creation and url calculation payload = handle_create_payload(entity, content.author) # Just dump to the relay system for now url = "https://%s/receive/public" % settings.SOCIALHOME_RELAY_DOMAIN send_document(url, payload) else: logger.warning("No entity for %s", content)
def send_follow_change(profile_id, followed_id, follow): """Handle sending of a local follow of a remote profile.""" try: profile = Profile.objects.get(id=profile_id, user__isnull=False) except Profile.DoesNotExist: logger.warning( "send_follow_change - No local profile %s found to send follow with", profile_id) return try: remote_profile = Profile.objects.get(id=followed_id, user__isnull=True) except Profile.DoesNotExist: logger.warning( "send_follow_change - No remote profile %s found to send follow for", followed_id) return if settings.DEBUG: # Don't send in development mode return entity = base.Follow(handle=profile.handle, target_handle=remote_profile.handle, following=follow) # TODO: add high level method support to federation for private payload delivery payload = handle_create_payload(entity, profile, to_user=remote_profile) url = "https://%s/receive/users/%s" % ( remote_profile.handle.split("@")[1], remote_profile.guid, ) send_document(url, payload) # Also trigger a profile send send_profile(profile_id, recipients=[(remote_profile.handle, None)])
def test_handle_create_payload_builds_an_xml(self): from_user = Mock(private_key=RSA.generate(2048), handle="*****@*****.**") to_user = Mock(key=RSA.generate(2048).publickey()) entity = DiasporaPost() data = handle_create_payload(from_user, to_user, entity) assert len(data) > 0 parts = data.split("=") assert len(parts) == 2 assert parts[0] == "xml" assert len(parts[1]) > 0
def send_content_retraction(content, author_id): """Handle sending of retractions. Currently only for public content. """ if not content.visibility == Visibility.PUBLIC: return author = Profile.objects.get(id=author_id) entity = make_federable_retraction(content, author) if entity: if settings.DEBUG: # Don't send in development mode return payload = handle_create_payload(entity, author) # Just dump to the relay system for now url = "https://%s/receive/public" % settings.SOCIALHOME_RELAY_DOMAIN send_document(url, payload) else: logger.warning("No retraction entity for %s", content)
def send_profile(profile_id, recipients=None): """Handle sending a Profile object out via the federation layer. :param profile_id: Profile.id of profile to send :param recipients: Optional list of recipient tuples, in form tuple(handle, network), for example ("*****@*****.**", "diaspora"). Network can be None. """ try: profile = Profile.objects.get(id=profile_id, user__isnull=False) except Profile.DoesNotExist: logger.warning("send_profile - No local profile found with id %s", profile_id) return entity = make_federable_profile(profile) if not entity: logger.warning("send_profile - No entity for %s", profile) return if settings.DEBUG: # Don't send in development mode return # From diaspora devs: "if the profile is private it needs to be encrypted, so to the private endpoint, # starting with 0.7.0.0 diaspora starts sending public profiles to the public endpoint only once per pod". # Let's just send everything to private endpoints as 0.7 isn't out yet. # TODO: once 0.7 is out for longer, start sending public profiles to public endpoints # TODO: add high level method support to federation for private payload delivery if not recipients: recipients = _get_remote_followers(profile) for handle, _network in recipients: try: remote_profile = Profile.objects.get(handle=handle) except Profile.DoesNotExist: continue payload = handle_create_payload(entity, profile, to_user=remote_profile) url = "https://%s/receive/users/%s" % (handle.split("@")[1], remote_profile.guid) send_document(url, payload)