def test_handle_create_payload_calls_get_outbound_entity_with_author_user(
         self, mock_get_outbound_entity):
     mock_get_outbound_entity.return_value = DiasporaPost()
     author_user = Mock(private_key=RSA.generate(2048),
                        handle="*****@*****.**")
     entity = DiasporaPost()
     handle_create_payload(entity, author_user)
     mock_get_outbound_entity.assert_called_once_with(
         entity, author_user.private_key)
 def test_get_send_to_nodes_with_like_returns_nodes_for_post(self):
     Node.create(host="sub.example.com")
     save_post_metadata(DiasporaPost(guid="12345"), "diaspora",
                        ["sub.example.com"])
     nodes = get_send_to_nodes("*****@*****.**",
                               DiasporaLike(target_guid="12345"))
     assert nodes == ["sub.example.com"]
 def test_handle_create_payload___diaspora__calls_magic_envelope_render(
         self, mock_me):
     mock_render = Mock()
     mock_me.return_value = Mock(render=mock_render)
     author_user = Mock()
     entity = DiasporaPost()
     handle_create_payload(entity, author_user, "diaspora")
     mock_render.assert_called_once_with()
class TestReceiveWorkerProcessCallsSendPayload(object):
    @patch("workers.receive.handle_receive",
           return_value=("*****@*****.**", "diaspora",
                         [DiasporaPost(raw_content="Awesome #post")]))
    @patch("workers.receive.send_document", return_value=(200, None))
    def test_send_payload_called(self, mock_handle_receive, mock_send_document,
                                 mock_pod_preferences):
        process(Mock())
        assert mock_send_document.call_count == 1
 def test_handle_create_payload_builds_an_xml(self, mock_protocol_class):
     mock_protocol = Mock()
     mock_protocol_class.return_value = mock_protocol
     author_user = Mock()
     entity = DiasporaPost()
     handle_create_payload(entity, author_user)
     mock_protocol.build_send.assert_called_once_with(entity=entity,
                                                      from_user=author_user,
                                                      to_user_key=None)
Exemple #6
0
def diasporapost_activitypub_id():
    return DiasporaPost(
        raw_content="raw_content",
        public=True,
        provider_display_name="Socialhome",
        id="https://domain.tld/id",
        guid="guid",
        actor_id="*****@*****.**",
        handle="*****@*****.**",
    )
Exemple #7
0
def diasporapost():
    return DiasporaPost(
        raw_content="raw_content",
        public=True,
        provider_display_name="Socialhome",
        id="guid",
        guid="guid",
        actor_id="*****@*****.**",
        handle="*****@*****.**",
    )
 def test_already_fine_entities_are_returned_as_is(self):
     entity = DiasporaPost()
     assert get_outbound_entity(entity) == entity
     entity = DiasporaLike()
     assert get_outbound_entity(entity) == entity
     entity = DiasporaComment()
     assert get_outbound_entity(entity) == entity
     entity = DiasporaRequest()
     assert get_outbound_entity(entity) == entity
     entity = DiasporaProfile()
     assert get_outbound_entity(entity) == entity
 def test_already_fine_entities_are_returned_as_is(self, private_key):
     entity = DiasporaPost()
     assert get_outbound_entity(entity, private_key) == entity
     entity = DiasporaLike()
     assert get_outbound_entity(entity, private_key) == entity
     entity = DiasporaComment()
     assert get_outbound_entity(entity, private_key) == entity
     entity = DiasporaProfile(handle="*****@*****.**", guid="1234")
     assert get_outbound_entity(entity, private_key) == entity
     entity = DiasporaContact()
     assert get_outbound_entity(entity, private_key) == entity
     entity = DiasporaReshare()
     assert get_outbound_entity(entity, private_key) == entity
 def test_post_to_xml(self):
     entity = DiasporaPost(
         raw_content="raw_content", guid="guid", handle="handle", public=True,
         provider_display_name="Socialhome"
     )
     result = entity.to_xml()
     assert result.tag == "status_message"
     assert len(result.find("created_at").text) > 0
     result.find("created_at").text = ""  # timestamp makes testing painful
     converted = b"<status_message><raw_message>raw_content</raw_message><guid>guid</guid>" \
                 b"<diaspora_handle>handle</diaspora_handle><public>true</public><created_at>" \
                 b"</created_at><provider_display_name>Socialhome</provider_display_name></status_message>"
     assert etree.tostring(result) == converted
Exemple #11
0
class TestReceiveWorkerProcessCallsSendPayload:
    @patch("social_relay.utils.data.get_pod_preferences", return_value={})
    @patch("workers.receive.handle_receive",
           return_value=("*****@*****.**", "diaspora",
                         [DiasporaPost(raw_content="Awesome #post")]))
    @patch("workers.receive.send_document", return_value=(200, None))
    def test_send_payload_called(self, mock_send_document, mock_handle_receive,
                                 mock_pod_preferences):
        process("payload")
        assert mock_send_document.call_count == 1
        mock_send_document.assert_called_once_with(
            url="https://sub.example.com/receive/public",
            data="payload",
            headers=HEADERS,
        )
 def test_build_send_does_right_calls(self, mock_me):
     mock_render = Mock(return_value="rendered")
     mock_me_instance = Mock(render=mock_render)
     mock_me.return_value = mock_me_instance
     protocol = Protocol()
     entity = DiasporaPost()
     private_key = get_dummy_private_key()
     outbound_entity = get_outbound_entity(entity, private_key)
     data = protocol.build_send(outbound_entity, from_user=Mock(
         private_key=private_key, handle="johnny@localhost",
     ))
     mock_me.assert_called_once_with(
         etree.tostring(entity.to_xml()), private_key=private_key, author_handle="johnny@localhost",
     )
     mock_render.assert_called_once_with()
     assert data == "rendered"
Exemple #13
0
 def test_build_send_does_right_calls__private_payload(self, mock_encrypt, mock_me):
     mock_render = Mock(return_value="rendered")
     mock_me_instance = Mock(render=mock_render)
     mock_me.return_value = mock_me_instance
     protocol = Protocol()
     entity = DiasporaPost()
     entity.validate = Mock()
     private_key = get_dummy_private_key()
     outbound_entity = get_outbound_entity(entity, private_key)
     data = protocol.build_send(outbound_entity, to_user_key="public key", from_user=UserType(
         private_key=private_key, id="johnny@localhost",
         handle="johnny@localhost",
     ))
     mock_me.assert_called_once_with(
         etree.tostring(entity.to_xml()), private_key=private_key, author_handle="johnny@localhost",
     )
     mock_render.assert_called_once_with()
     mock_encrypt.assert_called_once_with(
         "rendered", "public key",
     )
     assert data == "encrypted"
Exemple #14
0
def diasporapost():
    return DiasporaPost(
        raw_content="raw_content", guid="guid", handle="handle", public=True,
        provider_display_name="Socialhome"
    )
 def test_get_send_to_nodes_with_post_returns_nodes(
         self, mock_nodes_who_want_all):
     nodes = get_send_to_nodes("*****@*****.**", DiasporaPost())
     assert nodes == ["sub.example.com"]
@patch("social_relay.utils.data.get_pod_preferences", return_value={})
class TestReceiveWorkerProcessCallsSendPayload(object):
    @patch("workers.receive.handle_receive",
           return_value=("*****@*****.**", "diaspora",
                         [DiasporaPost(raw_content="Awesome #post")]))
    @patch("workers.receive.send_document", return_value=(200, None))
    def test_send_payload_called(self, mock_handle_receive, mock_send_document,
                                 mock_pod_preferences):
        process(Mock())
        assert mock_send_document.call_count == 1


@pytest.mark.usefixtures('config')
@patch("workers.receive.handle_receive",
       return_value=("*****@*****.**", "diaspora", [
           DiasporaPost(raw_content="Awesome #post", guid="foobar")
       ]))
@patch("workers.receive.send_document", return_value=(200, None))
@patch("social_relay.utils.data.get_pod_preferences", return_value={})
class TestReceiveWorkerStoresNodeAndPostMetadata(object):
    def test_send_payload_stores_unknown_node_into_db(self,
                                                      mock_handle_receive,
                                                      mock_send_document,
                                                      mock_pod_preferences):
        process(Mock())
        assert Node.select().count() == 1
        node = Node.get(Node.host == "sub.example.com")
        assert node
        assert node.https

    def test_send_payload_updates_existing_node_in_db(self,
 def test_get_send_to_nodes_with_post_returns_nodes_with_tags(
         self, mock_nodes_who_want_tags, mock_nodes_who_want_all):
     nodes = get_send_to_nodes("*****@*****.**", DiasporaPost())
     assert set(nodes) == {"sub.example.com", "tags.example.com"}