From: Nutomic Date: Fri, 28 Jan 2022 21:47:34 +0000 (+0000) Subject: Add federation tests for Friendica, improve parsing of source field (fixes #2057... X-Git-Url: http://these/git/%7B%60/feeds/u/static/gitweb.js?a=commitdiff_plain;h=545fe8d0ddc412c218694731995b710d47074013;p=lemmy.git Add federation tests for Friendica, improve parsing of source field (fixes #2057) (#2070) --- diff --git a/crates/apub/assets/friendica/activities/create_note.json b/crates/apub/assets/friendica/activities/create_note.json new file mode 100644 index 00000000..2bfaaefe --- /dev/null +++ b/crates/apub/assets/friendica/activities/create_note.json @@ -0,0 +1,82 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "vcard": "http://www.w3.org/2006/vcard/ns#", + "dfrn": "http://purl.org/macgirvin/dfrn/1.0/", + "diaspora": "https://diasporafoundation.org/ns/", + "litepub": "http://litepub.social/ns#", + "toot": "http://joinmastodon.org/ns#", + "schema": "http://schema.org#", + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "sensitive": "as:sensitive", + "Hashtag": "as:Hashtag", + "directMessage": "litepub:directMessage", + "discoverable": "toot:discoverable", + "PropertyValue": "schema:PropertyValue", + "value": "schema:value" + } + ], + "id": "https://soc.schuerz.at/objects/4edd2508-4361-edb8-c4d8-b45181083984/Create", + "type": "Create", + "actor": "https://soc.schuerz.at/profile/jakob", + "published": "2022-01-23T20:21:24Z", + "instrument": { + "type": "Service", + "name": "Friendica 'Siberian Iris' 2021.12-rc-1448", + "url": "https://soc.schuerz.at" + }, + "to": [ + "https://lemmy.schuerz.at/u/jakob", + "https://www.w3.org/ns/activitystreams#Public", + "https://lemmy.schuerz.at/c/test" + ], + "cc": [ + "https://soc.schuerz.at/followers/jakob" + ], + "object": { + "id": "https://soc.schuerz.at/objects/4edd2508-4361-edb8-c4d8-b45181083984", + "type": "Note", + "summary": "", + "inReplyTo": "https://lemmy.schuerz.at/post/25360", + "diaspora:guid": "4edd2508-4361-edb8-c4d8-b45181083984", + "published": "2022-01-23T20:21:24Z", + "url": "https://soc.schuerz.at/display/4edd2508-4361-edb8-c4d8-b45181083984", + "attributedTo": "https://soc.schuerz.at/profile/jakob", + "sensitive": false, + "context": "https://lemmy.schuerz.at/post/25360#context", + "content": "@jakob test", + "contentMap": { + "de": "@jakob test" + }, + "source": { + "content": "@[url=https://lemmy.schuerz.at/u/jakob]Jakob[/url] test", + "mediaType": "text/bbcode" + }, + "diaspora:comment": "{\"author\":\"jakob@soc.schuerz.at\",\"guid\":\"4edd2508-4361-edb8-c4d8-b45181083984\",\"created_at\":\"2022-01-23T20:21:24Z\",\"edited_at\":\"2022-01-23T20:21:24Z\",\"parent_guid\":\"ea620d1e-742c8b4d15249a9b-18b5fca3\",\"text\":\"@{Jakob; jakob@lemmy.schuerz.at} test\",\"author_signature\":\"JNCqOui5Cg8\\/Uxw+f0NtGCRjRnhPOrqE6kGJnMkZvOOKhlCdZbCqvyPlNJzEYDa3Z30mOWQKTTNo5BVI+VVZtGrVEqFOdzNog7jOLQoY1dKU9iEQ9vc8USwUCkyJyv48w1iXpfea87KPwv+03DMlftmD6kC7jdUVwhc7+jm0g4fh06tpOcCMQJOZqTTV\\/80EjxIJQ+8eEk5evSw\\/S98ohD1ahcwSomJ9hJUV1H48ucDvMod1FCLcN5h4ALHqubCu4TZIYhGhw9zoCl52GeHhrD3\\/vL6OW4ftZ7UG4rEKQ4HowuXqmNwydrQldtprRtu2UrZBjLqVusPXEs\\/xERQqZnalNXHijyd1TwwCmfTV4YjKwH4BhX\\/p4hdWMqEP4yYXlfA4apalVeAaYZLrNR58kPJjBHad\\/yqH30ziBFheqZ5odFh\\/jnKB4OCFVST3u9b1OKE0jyTrbTepPTaONwc8giQH1sM8koj1gFdulwuJuOTRUKR\\/8ishgHi5SWwbp5YG5Z3YSINkF10IcLiFZAF300AvwgOCdf7ferim4i\\/7TR1D2CBpoNUZnKCKZRymZbE0GuKEE+A6Pk3lk\\/DCsDtmMXpnxlPZ8Nq8OZS\\/olXevAu1y57MNnxBDXtojr4F54MP2fO7E2JwBr7AlwoeSEvtZSAO\\/elzrKfW0eVWOUM2OnI=\"}", + "attachment": [], + "tag": [ + { + "type": "Mention", + "href": "https://lemmy.schuerz.at/u/jakob", + "name": "@jakob@lemmy.schuerz.at" + } + ], + "to": [ + "https://lemmy.schuerz.at/u/jakob", + "https://www.w3.org/ns/activitystreams#Public", + "https://lemmy.schuerz.at/c/test" + ], + "cc": [ + "https://soc.schuerz.at/followers/jakob" + ] + }, + "signature": { + "type": "RsaSignature2017", + "nonce": "fe42f1478453c9c5e92efdc8a1b00c7e2dd2ce89501f2437c4438b8add1c8ff7", + "creator": "https://soc.schuerz.at/profile/jakob#main-key", + "created": "2022-01-23T20:21:25Z", + "signatureValue": "iWeNKyfH/d5+f6FDmZIadF4hW7XBliL8w3PQ2QkeKQG7fheqx1MB6825JX+Eaq8C0aNESesTTiDJgy3Xdcw8tgKwAVdji2DNZh7rNbSy57AzXlXOPRDnGJUbXp8gAuW2PJNZx3TTsJ5yM7tKLmHk0PpwsnKbvjFabL5O+htyfRZNVjFAsB9bVym/dBvf4jiTZiLufGDprgsaDVygUi3QrzmwsE41NZtL/MIEtbiC5pROWQvdQBEzeLfMDsnjI4CR+3tnaSlvepipuFxeSFpwl5Ae5+YM6IYRvSDsssjr8kAg1t3XnHUyeBdBdys0A6ryR5t5QuY0ygAHFs+X633JsgHDuCxxHiqNYxFuTs1xO0gmHydFy1iKlEt2rbr9pcX05hSvEFg0bI8HEC5M9GuafpY7sOyLX0jobBUH9CxdHUu0qri4ntORlvvAYsGFNHj+folFlMRBNMkcZ+MbrAxdoXBdjhsAp+tD6nje+PeZy63yJJQmPLQi9E+fHGGe0DAobGrBE/XF8X1ABH+ywyKwVu0t6lkSxu+zdr9+JXKgnf7HaFSsknapumw9aQwC7N/Q0M5KO41fF0R4VL2GtoppyB9Ck9Dg1zwMWjL2KZN3ckbWABb+frWtmKIVQACzupRWzHiHSZjRRNJalK3uugVisHF2PFGkjYoUjHDCNegKHO0=" + } +} \ No newline at end of file diff --git a/crates/apub/assets/friendica/objects/note.json b/crates/apub/assets/friendica/objects/note.json new file mode 100644 index 00000000..4c23babe --- /dev/null +++ b/crates/apub/assets/friendica/objects/note.json @@ -0,0 +1,56 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "vcard": "http://www.w3.org/2006/vcard/ns#", + "dfrn": "http://purl.org/macgirvin/dfrn/1.0/", + "diaspora": "https://diasporafoundation.org/ns/", + "litepub": "http://litepub.social/ns#", + "toot": "http://joinmastodon.org/ns#", + "schema": "http://schema.org#", + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "sensitive": "as:sensitive", + "Hashtag": "as:Hashtag", + "directMessage": "litepub:directMessage", + "discoverable": "toot:discoverable", + "PropertyValue": "schema:PropertyValue", + "value": "schema:value" + } + ], + "id": "https://soc.schuerz.at/objects/4edd2508-4361-edb8-c4d8-b45181083984", + "type": "Note", + "summary": "", + "inReplyTo": "https://lemmy.schuerz.at/post/25360", + "diaspora:guid": "4edd2508-4361-edb8-c4d8-b45181083984", + "published": "2022-01-23T20:21:24Z", + "url": "https://soc.schuerz.at/display/4edd2508-4361-edb8-c4d8-b45181083984", + "attributedTo": "https://soc.schuerz.at/profile/jakob", + "sensitive": false, + "context": "https://lemmy.schuerz.at/post/25360#context", + "content": "@jakob test", + "contentMap": { + "de": "@jakob test" + }, + "source": { + "content": "@[url=https://lemmy.schuerz.at/u/jakob]Jakob[/url] test", + "mediaType": "text/bbcode" + }, + "diaspora:comment": "{\"author\":\"jakob@soc.schuerz.at\",\"guid\":\"4edd2508-4361-edb8-c4d8-b45181083984\",\"created_at\":\"2022-01-23T20:21:24Z\",\"edited_at\":\"2022-01-23T20:21:24Z\",\"parent_guid\":\"ea620d1e-742c8b4d15249a9b-18b5fca3\",\"text\":\"@{Jakob; jakob@lemmy.schuerz.at} test\",\"author_signature\":\"JNCqOui5Cg8\\/Uxw+f0NtGCRjRnhPOrqE6kGJnMkZvOOKhlCdZbCqvyPlNJzEYDa3Z30mOWQKTTNo5BVI+VVZtGrVEqFOdzNog7jOLQoY1dKU9iEQ9vc8USwUCkyJyv48w1iXpfea87KPwv+03DMlftmD6kC7jdUVwhc7+jm0g4fh06tpOcCMQJOZqTTV\\/80EjxIJQ+8eEk5evSw\\/S98ohD1ahcwSomJ9hJUV1H48ucDvMod1FCLcN5h4ALHqubCu4TZIYhGhw9zoCl52GeHhrD3\\/vL6OW4ftZ7UG4rEKQ4HowuXqmNwydrQldtprRtu2UrZBjLqVusPXEs\\/xERQqZnalNXHijyd1TwwCmfTV4YjKwH4BhX\\/p4hdWMqEP4yYXlfA4apalVeAaYZLrNR58kPJjBHad\\/yqH30ziBFheqZ5odFh\\/jnKB4OCFVST3u9b1OKE0jyTrbTepPTaONwc8giQH1sM8koj1gFdulwuJuOTRUKR\\/8ishgHi5SWwbp5YG5Z3YSINkF10IcLiFZAF300AvwgOCdf7ferim4i\\/7TR1D2CBpoNUZnKCKZRymZbE0GuKEE+A6Pk3lk\\/DCsDtmMXpnxlPZ8Nq8OZS\\/olXevAu1y57MNnxBDXtojr4F54MP2fO7E2JwBr7AlwoeSEvtZSAO\\/elzrKfW0eVWOUM2OnI=\"}", + "attachment": [], + "tag": [ + { + "type": "Mention", + "href": "https://lemmy.schuerz.at/u/jakob", + "name": "@jakob@lemmy.schuerz.at" + } + ], + "to": [ + "https://lemmy.schuerz.at/u/jakob", + "https://www.w3.org/ns/activitystreams#Public", + "https://lemmy.schuerz.at/c/test" + ], + "cc": [ + "https://soc.schuerz.at/followers/jakob" + ] +} \ No newline at end of file diff --git a/crates/apub/assets/friendica/objects/person.json b/crates/apub/assets/friendica/objects/person.json new file mode 100644 index 00000000..1b1895ef --- /dev/null +++ b/crates/apub/assets/friendica/objects/person.json @@ -0,0 +1,94 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "vcard": "http://www.w3.org/2006/vcard/ns#", + "dfrn": "http://purl.org/macgirvin/dfrn/1.0/", + "diaspora": "https://diasporafoundation.org/ns/", + "litepub": "http://litepub.social/ns#", + "toot": "http://joinmastodon.org/ns#", + "schema": "http://schema.org#", + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "sensitive": "as:sensitive", + "Hashtag": "as:Hashtag", + "directMessage": "litepub:directMessage", + "discoverable": "toot:discoverable", + "PropertyValue": "schema:PropertyValue", + "value": "schema:value" + } + ], + "id": "https://soc.schuerz.at/profile/jakob", + "diaspora:guid": "4edd2508-1661-30f6-ebcc-2da966353356", + "type": "Person", + "following": "https://soc.schuerz.at/following/jakob", + "followers": "https://soc.schuerz.at/followers/jakob", + "inbox": "https://soc.schuerz.at/inbox/jakob", + "outbox": "https://soc.schuerz.at/outbox/jakob", + "preferredUsername": "jakob", + "name": "Jakob :friendica:", + "vcard:hasAddress": { + "@type": "vcard:Home", + "vcard:country-name": "Austria", + "vcard:region": "Niederoesterreich", + "vcard:locality": "" + }, + "summary": "Linux, FOSS, Öffentlicher Verkehr, Eisenbahn, Radfahren, Fußgehen, Verkehrsplanung, Städtebau, Will das Schöne wieder in die Welt bringen,Nachhaltigkeit, Modellbahn, Java Entwickler (jun), Bash,

#FediverseOnlyAccount", + "vcard:hasInstantMessage": [ + "xmpp:jakob@schuerz.at", + "matrix:@jakob:schuerz.at" + ], + "url": "https://soc.schuerz.at/profile/jakob", + "manuallyApprovesFollowers": true, + "discoverable": true, + "publicKey": { + "id": "https://soc.schuerz.at/profile/jakob#main-key", + "owner": "https://soc.schuerz.at/profile/jakob", + "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA1RRoj3DpUmTiRBshv+kz\njO5tgfHs99aBJjvaoW8nbPcOs+HZm9Nj4ncJh99kwd+yONwac6ObMMIisYpVU4C1\neKpnlRrRu/8vQFwhHQT4RxpkibB+l+LvG1HJoMNIuYxvVCIaQZugdJclAdMJjDTF\nbDQNwG6xlcazKd4IbMbmgfoxTxSnQSomJQew1NUbdD3vDiCdJEtjCmeWm6eTCfyZ\njT0mjrAm8ccJ7+opN5SWJ0je0Rav5dohyaVFEtv1Dlv1UlqU4hKefvv71eoROHCA\nWQ3+kYGFGY4ApnbWxwLZyke7khzxr2BjDrfwUAeEsLJT4YOxa5fKJJ59+q5Iddaq\nPNT3QqP0Qzum5w6qDOWm3cNNw7ByqoqxKckZS5U2vm0sx83UEmBqysAkAS/8M9Qr\nBKkb9DQ9jgUa7GPpL+Oknr8hV+Vpk49Jjx+A1WJ/MlNja7fi4w4rBM+v3B8nRayM\nzX8XaKbbOib21mCawJiJIOAm0EP2rNqNM1GpUWPstHKG00o3Czz3P5Hm/q6RcNJE\nKRlSIPQZnUVsoC0bFsqWzipsgb3uDHnz3Ni2OjLNLWBVYkWD7RNfB3WV/XKl2QL3\nnnhmUDahGN7UCOrcBuLfWsTa+GZDFeHot1HXa9tNcxq+QxAUg3qv7oiAH1H+hoJg\nn/Ydg1IR5sLovKi3g7DRS7MCAwEAAQ==\n-----END PUBLIC KEY-----\n" + }, + "endpoints": { + "sharedInbox": "https://soc.schuerz.at/inbox" + }, + "icon": { + "type": "Image", + "url": "https://soc.schuerz.at/photo/profile/jakob.png?ts=1630598950", + "mediaType": "image/png" + }, + "attachment": [ + { + "type": "PropertyValue", + "name": "Mobilizon", + "value": "@jakob@events.schuerz.at
@jakob@events.tulln.social" + }, + { + "type": "PropertyValue", + "name": "Lemmy", + "value": "https://lemmy.schuerz.at/u/jakob" + }, + { + "type": "PropertyValue", + "name": "Funkwhale", + "value": "https://radio.schuerz.at/@jakob/" + }, + { + "type": "PropertyValue", + "name": "Peertube", + "value": "https://kino.schuerz.at/a/jakob" + }, + { + "type": "PropertyValue", + "name": "Pixelfed", + "value": "https://japix.schuerz.at/jakob" + }, + { + "type": "PropertyValue", + "name": "about:", + "value": "This is an OpenPGP proof that connects my OpenPGP key to this Peertube account. For details check out https://keyoxide.org/guides/openpgp-proofs

[Verifying my OpenPGP key: openpgp4fpr:FED82F1C73FF53FB1EE9926336615E0FD12833CF]" + } + ], + "generator": { + "type": "Service", + "name": "Friendica 'Siberian Iris' 2021.12-rc-1448", + "url": "https://soc.schuerz.at" + } +} \ No newline at end of file diff --git a/crates/apub/src/protocol/activities/create_or_update/mod.rs b/crates/apub/src/protocol/activities/create_or_update/mod.rs index 43576e44..2ce70333 100644 --- a/crates/apub/src/protocol/activities/create_or_update/mod.rs +++ b/crates/apub/src/protocol/activities/create_or_update/mod.rs @@ -41,5 +41,8 @@ mod tests { file_to_json_object::("assets/lotide/activities/create_page.json").unwrap(); file_to_json_object::("assets/lotide/activities/create_note_reply.json") .unwrap(); + + file_to_json_object::("assets/friendica/activities/create_note.json") + .unwrap(); } } diff --git a/crates/apub/src/protocol/objects/mod.rs b/crates/apub/src/protocol/objects/mod.rs index 139fe0fc..2367b686 100644 --- a/crates/apub/src/protocol/objects/mod.rs +++ b/crates/apub/src/protocol/objects/mod.rs @@ -70,4 +70,10 @@ mod tests { file_to_json_object::>("assets/lotide/objects/page.json").unwrap(); file_to_json_object::>("assets/lotide/objects/tombstone.json").unwrap(); } + + #[actix_rt::test] + async fn test_parse_object_friendica() { + file_to_json_object::>("assets/friendica/objects/person.json").unwrap(); + file_to_json_object::>("assets/friendica/objects/note.json").unwrap(); + } } diff --git a/crates/apub/src/protocol/objects/note.rs b/crates/apub/src/protocol/objects/note.rs index ff463926..73e4a130 100644 --- a/crates/apub/src/protocol/objects/note.rs +++ b/crates/apub/src/protocol/objects/note.rs @@ -12,6 +12,7 @@ use lemmy_db_schema::{newtypes::CommentId, source::post::Post, traits::Crud}; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; use serde::{Deserialize, Serialize}; +use serde_json::Value; use serde_with::skip_serializing_none; use std::ops::Deref; use url::Url; @@ -46,9 +47,9 @@ pub struct Note { #[serde(rename_all = "camelCase")] #[serde(untagged)] pub(crate) enum SourceCompat { - None, Lemmy(Source), - Pleroma(String), + Other(Value), + None, } impl Default for SourceCompat {