]> Untitled Git - lemmy.git/commitdiff
Add federation tests for Friendica, improve parsing of source field (fixes #2057...
authorNutomic <me@nutomic.com>
Fri, 28 Jan 2022 21:47:34 +0000 (21:47 +0000)
committerGitHub <noreply@github.com>
Fri, 28 Jan 2022 21:47:34 +0000 (16:47 -0500)
crates/apub/assets/friendica/activities/create_note.json [new file with mode: 0644]
crates/apub/assets/friendica/objects/note.json [new file with mode: 0644]
crates/apub/assets/friendica/objects/person.json [new file with mode: 0644]
crates/apub/src/protocol/activities/create_or_update/mod.rs
crates/apub/src/protocol/objects/mod.rs
crates/apub/src/protocol/objects/note.rs

diff --git a/crates/apub/assets/friendica/activities/create_note.json b/crates/apub/assets/friendica/activities/create_note.json
new file mode 100644 (file)
index 0000000..2bfaaef
--- /dev/null
@@ -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": "<span class=\"h-card\"><a href=\"https://lemmy.schuerz.at/u/jakob\" class=\"u-url mention\">@<span>jakob</span></a></span> test",
+    "contentMap": {
+      "de": "<bdi>@<a href=\"https://lemmy.schuerz.at/u/jakob\" class=\"userinfo mention\" title=\"jakob\">jakob</a></bdi> 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 (file)
index 0000000..4c23bab
--- /dev/null
@@ -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": "<span class=\"h-card\"><a href=\"https://lemmy.schuerz.at/u/jakob\" class=\"u-url mention\">@<span>jakob</span></a></span> test",
+  "contentMap": {
+    "de": "<bdi>@<a href=\"https://lemmy.schuerz.at/u/jakob\" class=\"userinfo mention\" title=\"jakob\">jakob</a></bdi> 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 (file)
index 0000000..1b1895e
--- /dev/null
@@ -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,<br><br>#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<br>@jakob@events.tulln.social"
+    },
+    {
+      "type": "PropertyValue",
+      "name": "Lemmy",
+      "value": "<a href=\"https://lemmy.schuerz.at/u/jakob\" target=\"_blank\" rel=\"noopener noreferrer\">https://lemmy.schuerz.at/u/jakob</a>"
+    },
+    {
+      "type": "PropertyValue",
+      "name": "Funkwhale",
+      "value": "<a href=\"https://radio.schuerz.at/@jakob/\" target=\"_blank\" rel=\"noopener noreferrer\">https://radio.schuerz.at/@jakob/</a>"
+    },
+    {
+      "type": "PropertyValue",
+      "name": "Peertube",
+      "value": "<a href=\"https://kino.schuerz.at/a/jakob\" target=\"_blank\" rel=\"noopener noreferrer\">https://kino.schuerz.at/a/jakob</a>"
+    },
+    {
+      "type": "PropertyValue",
+      "name": "Pixelfed",
+      "value": "<a href=\"https://japix.schuerz.at/jakob\" target=\"_blank\" rel=\"noopener noreferrer\">https://japix.schuerz.at/jakob</a>"
+    },
+    {
+      "type": "PropertyValue",
+      "name": "about:",
+      "value": "This is an OpenPGP proof that connects my OpenPGP key to this Peertube account. For details check out <a href=\"https://keyoxide.org/guides/openpgp-proofs\" target=\"_blank\" rel=\"noopener noreferrer\">https://keyoxide.org/guides/openpgp-proofs</a><br><br>[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
index 43576e446a51421b17b5c4dcf604fe724934e8a8..2ce70333a569612199435e4aa556edb42ed9dbe6 100644 (file)
@@ -41,5 +41,8 @@ mod tests {
     file_to_json_object::<CreateOrUpdatePost>("assets/lotide/activities/create_page.json").unwrap();
     file_to_json_object::<CreateOrUpdateComment>("assets/lotide/activities/create_note_reply.json")
       .unwrap();
+
+    file_to_json_object::<CreateOrUpdateComment>("assets/friendica/activities/create_note.json")
+      .unwrap();
   }
 }
index 139fe0fcee8368d29fbbab89df23a4bb55b273de..2367b686339e1dfb382d04715a6e83df6cd4722b 100644 (file)
@@ -70,4 +70,10 @@ mod tests {
     file_to_json_object::<WithContext<Page>>("assets/lotide/objects/page.json").unwrap();
     file_to_json_object::<WithContext<Tombstone>>("assets/lotide/objects/tombstone.json").unwrap();
   }
+
+  #[actix_rt::test]
+  async fn test_parse_object_friendica() {
+    file_to_json_object::<WithContext<Person>>("assets/friendica/objects/person.json").unwrap();
+    file_to_json_object::<WithContext<Note>>("assets/friendica/objects/note.json").unwrap();
+  }
 }
index ff463926d428fa53af32481feea50a1329445fb9..73e4a1304157f30a09007d622fec9817308de706 100644 (file)
@@ -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 {