kopia lustrzana https://gitlab.com/jaywink/federation
Extract ActivityPub ID from Diaspora paylaods
Extract ActivityPub ID from Diaspora payloads if found as the `activitypub_id` property.merge-requests/161/head
rodzic
e1af61794b
commit
a29ab19166
|
@ -27,6 +27,7 @@
|
|||
* Extract Diaspora guid from ActivityPub payloads implementing the Diaspora extension.
|
||||
* Add Diaspora extension and guid to outbound ActivityPub payloads, if available. For
|
||||
profiles, also add handle.
|
||||
* Extract ActivityPub ID from Diaspora payloads if found as the `activitypub_id` property.
|
||||
* Add ActivityPub ID to outbound Diaspora payloads of types comment, post and profile,
|
||||
if an URL given as `id`.
|
||||
|
||||
|
|
|
@ -176,6 +176,8 @@ def transform_attributes(attrs, cls):
|
|||
value = ""
|
||||
if key == "text":
|
||||
transformed["raw_content"] = value
|
||||
elif key == "activitypub_id":
|
||||
transformed["id"] = value
|
||||
elif key == "author":
|
||||
if cls == DiasporaProfile:
|
||||
# Diaspora Profile XML message contains no GUID. We need the guid. Fetch it.
|
||||
|
|
|
@ -18,7 +18,8 @@ from federation.tests.fixtures.payloads import (
|
|||
DIASPORA_POST_WITH_PHOTOS, DIASPORA_CONTACT,
|
||||
DIASPORA_PROFILE_EMPTY_TAGS, DIASPORA_RESHARE,
|
||||
DIASPORA_RESHARE_WITH_EXTRA_PROPERTIES, DIASPORA_POST_SIMPLE_WITH_MENTION,
|
||||
DIASPORA_PROFILE_FIRST_NAME_ONLY, DIASPORA_POST_COMMENT_NESTED)
|
||||
DIASPORA_PROFILE_FIRST_NAME_ONLY, DIASPORA_POST_COMMENT_NESTED, DIASPORA_POST_ACTIVITYPUB_ID,
|
||||
DIASPORA_POST_COMMENT_ACTIVITYPUB_ID, DIASPORA_PROFILE_ACTIVITYPUB_ID)
|
||||
from federation.types import UserType, ReceiverVariant
|
||||
|
||||
|
||||
|
@ -31,6 +32,16 @@ class TestDiasporaEntityMappersReceive:
|
|||
post = entities[0]
|
||||
assert post._mentions == {'jaywink@jasonrobinson.me'}
|
||||
|
||||
def test_message_to_objects_post__with_activitypub_id(self):
|
||||
entities = message_to_objects(DIASPORA_POST_ACTIVITYPUB_ID, "alice@alice.diaspora.example.org")
|
||||
assert len(entities) == 1
|
||||
post = entities[0]
|
||||
assert isinstance(post, DiasporaPost)
|
||||
assert isinstance(post, Post)
|
||||
assert post.guid == "((guidguidguidguidguidguidguid))"
|
||||
assert post.handle == "alice@alice.diaspora.example.org"
|
||||
assert post.id == "https://alice.diaspora.example.org/posts/1"
|
||||
|
||||
def test_message_to_objects_simple_post(self):
|
||||
entities = message_to_objects(DIASPORA_POST_SIMPLE, "alice@alice.diaspora.example.org")
|
||||
assert len(entities) == 1
|
||||
|
@ -80,6 +91,21 @@ class TestDiasporaEntityMappersReceive:
|
|||
]
|
||||
mock_validate.assert_called_once_with()
|
||||
|
||||
@patch("federation.entities.diaspora.mappers.DiasporaComment._validate_signatures")
|
||||
def test_message_to_objects_comment__activitypub_id(self, mock_validate):
|
||||
entities = message_to_objects(DIASPORA_POST_COMMENT_ACTIVITYPUB_ID, "alice@alice.diaspora.example.org",
|
||||
sender_key_fetcher=Mock())
|
||||
assert len(entities) == 1
|
||||
comment = entities[0]
|
||||
assert isinstance(comment, DiasporaComment)
|
||||
assert isinstance(comment, Comment)
|
||||
assert comment.target_guid == "((parent_guidparent_guidparent_guidparent_guid))"
|
||||
assert comment.root_target_guid == ""
|
||||
assert comment.guid == "((guidguidguidguidguidguid))"
|
||||
assert comment.handle == "alice@alice.diaspora.example.org"
|
||||
assert comment.id == "https://alice.diaspora.example.org/comments/1"
|
||||
mock_validate.assert_called_once_with()
|
||||
|
||||
@patch("federation.entities.diaspora.mappers.DiasporaComment._validate_signatures")
|
||||
def test_message_to_objects_nested_comment(self, mock_validate):
|
||||
entities = message_to_objects(DIASPORA_POST_COMMENT_NESTED, "alice@alice.diaspora.example.org",
|
||||
|
@ -141,6 +167,16 @@ class TestDiasporaEntityMappersReceive:
|
|||
assert profile.nsfw == False
|
||||
assert profile.tag_list == ["socialfederation", "federation"]
|
||||
|
||||
@patch("federation.entities.diaspora.mappers.retrieve_and_parse_profile", return_value=Mock(
|
||||
id="bob@example.com",
|
||||
))
|
||||
def test_message_to_objects_profile__activitypub_id(self, mock_parse):
|
||||
entities = message_to_objects(DIASPORA_PROFILE_ACTIVITYPUB_ID, "bob@example.com")
|
||||
assert len(entities) == 1
|
||||
profile = entities[0]
|
||||
assert profile.handle == "bob@example.com"
|
||||
assert profile.id == "https://example.com/bob"
|
||||
|
||||
@patch("federation.entities.diaspora.mappers.retrieve_and_parse_profile", return_value=Mock(
|
||||
id="bob@example.com",
|
||||
))
|
||||
|
|
|
@ -25,6 +25,18 @@ DIASPORA_ENCRYPTED_PAYLOAD = """{
|
|||
}
|
||||
"""
|
||||
|
||||
DIASPORA_POST_ACTIVITYPUB_ID = """
|
||||
<status_message>
|
||||
<text>((status message))</text>
|
||||
<guid>((guidguidguidguidguidguidguid))</guid>
|
||||
<author>alice@alice.diaspora.example.org</author>
|
||||
<public>false</public>
|
||||
<created_at>2011-07-20T01:36:07Z</created_at>
|
||||
<provider_display_name>Socialhome</provider_display_name>
|
||||
<activitypub_id>https://alice.diaspora.example.org/posts/1</activitypub_id>
|
||||
</status_message>
|
||||
"""
|
||||
|
||||
DIASPORA_POST_SIMPLE = """
|
||||
<status_message>
|
||||
<text>((status message))</text>
|
||||
|
@ -36,6 +48,7 @@ DIASPORA_POST_SIMPLE = """
|
|||
</status_message>
|
||||
"""
|
||||
|
||||
|
||||
DIASPORA_POST_SIMPLE_WITH_MENTION = """
|
||||
<status_message>
|
||||
<text>((status message)) @{Jason Robinson 🐍🍻; jaywink@jasonrobinson.me}</text>
|
||||
|
@ -91,6 +104,18 @@ DIASPORA_POST_COMMENT = """
|
|||
</comment>
|
||||
"""
|
||||
|
||||
DIASPORA_POST_COMMENT_ACTIVITYPUB_ID = """
|
||||
<comment>
|
||||
<guid>((guidguidguidguidguidguid))</guid>
|
||||
<parent_guid>((parent_guidparent_guidparent_guidparent_guid))</parent_guid>
|
||||
<author_signature>((base64-encoded data))</author_signature>
|
||||
<text>((text))</text>
|
||||
<author>alice@alice.diaspora.example.org</author>
|
||||
<author_signature>((signature))</author_signature>
|
||||
<activitypub_id>https://alice.diaspora.example.org/comments/1</activitypub_id>
|
||||
</comment>
|
||||
"""
|
||||
|
||||
DIASPORA_POST_COMMENT_NESTED = """
|
||||
<comment>
|
||||
<guid>((guidguidguidguidguidguid))</guid>
|
||||
|
@ -132,6 +157,24 @@ DIASPORA_PROFILE = """
|
|||
</profile>
|
||||
"""
|
||||
|
||||
DIASPORA_PROFILE_ACTIVITYPUB_ID = """
|
||||
<profile>
|
||||
<author>bob@example.com</author>
|
||||
<first_name>Bob</first_name>
|
||||
<last_name>Bobertson</last_name>
|
||||
<image_url>https://example.com/uploads/images/thumb_large_c833747578b5.jpg</image_url>
|
||||
<image_url_small>https://example.com/uploads/images/thumb_small_c8b147578b5.jpg</image_url_small>
|
||||
<image_url_medium>https://example.com/uploads/images/thumb_medium_c8b1aab04f3.jpg</image_url_medium>
|
||||
<gender></gender>
|
||||
<bio>A cool bio</bio>
|
||||
<location>Helsinki</location>
|
||||
<searchable>true</searchable>
|
||||
<nsfw>false</nsfw>
|
||||
<tag_string>#socialfederation #federation</tag_string>
|
||||
<activitypub_id>https://example.com/bob</activitypub_id>
|
||||
</profile>
|
||||
"""
|
||||
|
||||
DIASPORA_PROFILE_FIRST_NAME_ONLY = """
|
||||
<profile>
|
||||
<author>bob@example.com</author>
|
||||
|
|
Ładowanie…
Reference in New Issue