]> Untitled Git - lemmy.git/commitdiff
Add federation test cases for Smithereen and Mastodon
authorFelix Ableitner <me@nutomic.com>
Tue, 9 Nov 2021 12:25:19 +0000 (13:25 +0100)
committerFelix Ableitner <me@nutomic.com>
Tue, 9 Nov 2021 16:16:58 +0000 (17:16 +0100)
crates/apub/assets/mastodon/activities/create_note.json [new file with mode: 0644]
crates/apub/assets/mastodon/objects/note.json [new file with mode: 0644]
crates/apub/assets/mastodon/objects/person.json [new file with mode: 0644]
crates/apub/assets/smithereen/activities/create_note.json [new file with mode: 0644]
crates/apub/assets/smithereen/objects/note.json [new file with mode: 0644]
crates/apub/assets/smithereen/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/mastodon/activities/create_note.json b/crates/apub/assets/mastodon/activities/create_note.json
new file mode 100644 (file)
index 0000000..8b836fb
--- /dev/null
@@ -0,0 +1,55 @@
+{
+  "id": "https://mastodon.madrid/users/felix/statuses/107224289116410645/activity",
+  "type": "Create",
+  "actor": "https://mastodon.madrid/users/felix",
+  "published": "2021-11-05T11:46:50Z",
+  "to": [
+    "https://mastodon.madrid/users/felix/followers"
+  ],
+  "cc": [
+    "https://www.w3.org/ns/activitystreams#Public",
+    "https://mamot.fr/users/retiolus"
+  ],
+  "object": {
+    "id": "https://mastodon.madrid/users/felix/statuses/107224289116410645",
+    "type": "Note",
+    "summary": null,
+    "inReplyTo": "https://mamot.fr/users/retiolus/statuses/107224244380204526",
+    "published": "2021-11-05T11:46:50Z",
+    "url": "https://mastodon.madrid/@felix/107224289116410645",
+    "attributedTo": "https://mastodon.madrid/users/felix",
+    "to": [
+      "https://mastodon.madrid/users/felix/followers"
+    ],
+    "cc": [
+      "https://www.w3.org/ns/activitystreams#Public",
+      "https://mamot.fr/users/retiolus"
+    ],
+    "sensitive": false,
+    "atomUri": "https://mastodon.madrid/users/felix/statuses/107224289116410645",
+    "inReplyToAtomUri": "https://mamot.fr/users/retiolus/statuses/107224244380204526",
+    "conversation": "tag:mamot.fr,2021-11-05:objectId=64635960:objectType=Conversation",
+    "content": "<p><span class=\"h-card\"><a href=\"https://mamot.fr/@retiolus\" class=\"u-url mention\">@<span>retiolus</span></a></span> i have never been disappointed by a thinkpad. if you want to save money, get a model from a few years ago, there isnt a huge difference anyway.</p>",
+    "contentMap": {
+      "en": "<p><span class=\"h-card\"><a href=\"https://mamot.fr/@retiolus\" class=\"u-url mention\">@<span>retiolus</span></a></span> i have neverbeendisappointed by a thinkpad. if you want to save money, get a model from a few years ago, there isnt a huge difference anyway.</p>"
+    },
+    "attachment": [],
+    "tag": [
+      {
+        "type": "Mention",
+        "href": "https://mamot.fr/users/retiolus",
+        "name": "@retiolus@mamot.fr"
+      }
+    ],
+    "replies": {
+      "id": "https://mastodon.madrid/users/felix/statuses/107224289116410645/replies",
+      "type": "Collection",
+      "first": {
+        "type": "CollectionPage",
+        "next": "https://mastodon.madrid/users/felix/statuses/107224289116410645/replies?only_other_accounts=true&page=true",
+        "partOf": "https://mastodon.madrid/users/felix/statuses/107224289116410645/replies",
+        "items": []
+      }
+    }
+  }
+}
\ No newline at end of file
diff --git a/crates/apub/assets/mastodon/objects/note.json b/crates/apub/assets/mastodon/objects/note.json
new file mode 100644 (file)
index 0000000..cf0d9fe
--- /dev/null
@@ -0,0 +1,42 @@
+{
+  "id": "https://mastodon.madrid/users/felix/statuses/107224289116410645",
+  "type": "Note",
+  "summary": null,
+  "inReplyTo": "https://mamot.fr/users/retiolus/statuses/107224244380204526",
+  "published": "2021-11-05T11:46:50Z",
+  "url": "https://mastodon.madrid/@felix/107224289116410645",
+  "attributedTo": "https://mastodon.madrid/users/felix",
+  "to": [
+    "https://mastodon.madrid/users/felix/followers"
+  ],
+  "cc": [
+    "https://www.w3.org/ns/activitystreams#Public",
+    "https://mamot.fr/users/retiolus"
+  ],
+  "sensitive": false,
+  "atomUri": "https://mastodon.madrid/users/felix/statuses/107224289116410645",
+  "inReplyToAtomUri": "https://mamot.fr/users/retiolus/statuses/107224244380204526",
+  "conversation": "tag:mamot.fr,2021-11-05:objectId=64635960:objectType=Conversation",
+  "content": "<p><span class=\"h-card\"><a href=\"https://mamot.fr/@retiolus\" class=\"u-url mention\">@<span>retiolus</span></a></span> i have never been disappointed by a thinkpad. if you want to save money, get a model from a few years ago, there isnt a huge difference anyway.</p>",
+  "contentMap": {
+    "en": "<p><span class=\"h-card\"><a href=\"https://mamot.fr/@retiolus\" class=\"u-url mention\">@<span>retiolus</span></a></span> i have neverbeendisappointed by a thinkpad. if you want to save money, get a model from a few years ago, there isnt a huge difference anyway.</p>"
+  },
+  "attachment": [],
+  "tag": [
+    {
+      "type": "Mention",
+      "href": "https://mamot.fr/users/retiolus",
+      "name": "@retiolus@mamot.fr"
+    }
+  ],
+  "replies": {
+    "id": "https://mastodon.madrid/users/felix/statuses/107224289116410645/replies",
+    "type": "Collection",
+    "first": {
+      "type": "CollectionPage",
+      "next": "https://mastodon.madrid/users/felix/statuses/107224289116410645/replies?only_other_accounts=true&page=true",
+      "partOf": "https://mastodon.madrid/users/felix/statuses/107224289116410645/replies",
+      "items": []
+    }
+  }
+}
\ No newline at end of file
diff --git a/crates/apub/assets/mastodon/objects/person.json b/crates/apub/assets/mastodon/objects/person.json
new file mode 100644 (file)
index 0000000..0ae4e7f
--- /dev/null
@@ -0,0 +1,93 @@
+{
+  "@context": [
+    "https://www.w3.org/ns/activitystreams",
+    "https://w3id.org/security/v1",
+    {
+      "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
+      "toot": "http://joinmastodon.org/ns#",
+      "featured": {
+        "@id": "toot:featured",
+        "@type": "@id"
+      },
+      "alsoKnownAs": {
+        "@id": "as:alsoKnownAs",
+        "@type": "@id"
+      },
+      "movedTo": {
+        "@id": "as:movedTo",
+        "@type": "@id"
+      },
+      "schema": "http://schema.org#",
+      "PropertyValue": "schema:PropertyValue",
+      "value": "schema:value",
+      "IdentityProof": "toot:IdentityProof",
+      "discoverable": "toot:discoverable",
+      "Device": "toot:Device",
+      "Ed25519Signature": "toot:Ed25519Signature",
+      "Ed25519Key": "toot:Ed25519Key",
+      "Curve25519Key": "toot:Curve25519Key",
+      "EncryptedMessage": "toot:EncryptedMessage",
+      "publicKeyBase64": "toot:publicKeyBase64",
+      "deviceId": "toot:deviceId",
+      "claim": {
+        "@type": "@id",
+        "@id": "toot:claim"
+      },
+      "fingerprintKey": {
+        "@type": "@id",
+        "@id": "toot:fingerprintKey"
+      },
+      "identityKey": {
+        "@type": "@id",
+        "@id": "toot:identityKey"
+      },
+      "devices": {
+        "@type": "@id",
+        "@id": "toot:devices"
+      },
+      "messageFranking": "toot:messageFranking",
+      "messageType": "toot:messageType",
+      "cipherText": "toot:cipherText",
+      "Hashtag": "as:Hashtag",
+      "focalPoint": {
+        "@container": "@list",
+        "@id": "toot:focalPoint"
+      }
+    }
+  ],
+  "id": "https://mastodon.madrid/users/felix",
+  "type": "Person",
+  "following": "https://mastodon.madrid/users/felix/following",
+  "followers": "https://mastodon.madrid/users/felix/followers",
+  "inbox": "https://mastodon.madrid/users/felix/inbox",
+  "outbox": "https://mastodon.madrid/users/felix/outbox",
+  "featured": "https://mastodon.madrid/users/felix/collections/featured",
+  "preferredUsername": "felix",
+  "name": "",
+  "summary": "<p><a href=\"https://mastodon.madrid/tags/Lemmy\" class=\"mention hashtag\" rel=\"tag\">#<span>Lemmy</span></a> Maintainer</p>",
+  "url": "https://mastodon.madrid/@felix",
+  "manuallyApprovesFollowers": false,
+  "discoverable": false,
+  "devices": "https://mastodon.madrid/users/felix/collections/devices",
+  "publicKey": {
+    "id": "https://mastodon.madrid/users/felix#main-key",
+    "owner": "https://mastodon.madrid/users/felix",
+    "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzc+evQS6XHTUdniPmFfH\n0U6aa4NaGSTQY4fmJna9w9Sr/8nNN4XWbGJLD4kawPxAXMbK63RMkkxvaHI9w+Oe\nd6oIJH2Z5qH4s2eX8f610SGDvyEZltLAY8TkMhNEp+3bOCKf1zG/uCsE7uC6Mjal\nd6KYyqoom5TwO2UWH5r6l3vyLFvnXWX2zOgSWJwLNLxMWkkd9AqM7k9+pgmeaNWD\n6JvG7Na5ywsR4CZrE5PjgtiC9LWP/H3Elgb2nIzye5HUEJuK2h1+eNFP3HSK5CF3\ncrg4DsZ1n5X3fQVm5YmFUYtEMLZL5S18dFsp6uwE0TmVOODJdnJ6+cgu0/8t2ROR\nJQIDAQAB\n-----END PUBLIC KEY-----\n"
+  },
+  "tag": [
+    {
+      "type": "Hashtag",
+      "href": "https://mastodon.madrid/explore/lemmy",
+      "name": "#lemmy"
+    }
+  ],
+  "attachment": [],
+  "endpoints": {
+    "sharedInbox": "https://mastodon.madrid/inbox"
+  },
+  "icon": {
+    "type": "Image",
+    "mediaType": "image/jpeg",
+    "url": "https://mastodon.madrid/system/accounts/avatars/000/087/969/original/ffdd1c832b453bc9.jpg?1598972149"
+  }
+}
\ No newline at end of file
diff --git a/crates/apub/assets/smithereen/activities/create_note.json b/crates/apub/assets/smithereen/activities/create_note.json
new file mode 100644 (file)
index 0000000..a30bc9a
--- /dev/null
@@ -0,0 +1,54 @@
+{
+  "type": "Create",
+  "id": "https://friends.grishka.me/posts/66561/activityCreate",
+  "published": "2021-11-09T11:42:35Z",
+  "to": [
+    "https://www.w3.org/ns/activitystreams#Public"
+  ],
+  "cc": [
+    "https://ds9.lemmy.ml/u/nutomic"
+  ],
+  "actor": "https://friends.grishka.me/users/1",
+  "object": {
+    "type": "Note",
+    "id": "https://friends.grishka.me/posts/66561",
+    "attributedTo": "https://friends.grishka.me/users/1",
+    "content": "<p>So does this federate now?</p>",
+    "inReplyTo": "https://ds9.lemmy.ml/post/1723",
+    "published": "2021-11-09T11:42:35Z",
+    "tag": {
+      "type": "Mention",
+      "href": "https://ds9.lemmy.ml/u/nutomic"
+    },
+    "url": "https://friends.grishka.me/posts/66561",
+    "to": [
+      "https://www.w3.org/ns/activitystreams#Public"
+    ],
+    "cc": [
+      "https://ds9.lemmy.ml/u/nutomic"
+    ],
+    "replies": {
+      "type": "Collection",
+      "id": "https://friends.grishka.me/posts/66561/replies",
+      "first": {
+        "type": "CollectionPage",
+        "partOf": "https://friends.grishka.me/posts/66561/replies",
+        "next": "https://friends.grishka.me/posts/66561/replies?page=1"
+      }
+    },
+    "sensitive": false,
+    "likes": "https://friends.grishka.me/posts/66561/likes"
+  },
+  "@context": [
+    "https://www.w3.org/ns/activitystreams",
+    {
+      "sensitive": "as:sensitive"
+    }
+  ],
+  "signature": {
+    "creator": "https://friends.grishka.me/users/1#main-key",
+    "created": "2021-11-09T11:42:35Z",
+    "type": "RsaSignature2017",
+    "signatureValue": "MmEf4hjfwfQbm/W8qfONwf0uEXO4dhKApX8PlodSNi9x6E4kEgBvx7BrKg3gtqnXfU/cbGdVIN/yCz8+v7Tp2T2kj1yRpD7WjbgwzkrOlhxLi3zPXd4En/cVVdZYSfc7R6DGflXOSeOZPnKbrmY6i+1kYkM80Yc+LFtoj0Ftdgc/YbwMynt1OwPvDbB5bJo1NVyRnpNqlqia2VNmdAh1+2vREXZmINsCOFMC5c0RVzEENYMw+ZPsbVdXfoz4wfqK2u2i7SlcDKVErVNPrKn71wfGWRRiLUNupokY1x3jsWeZlPqGvAP3WGS9ChU+FxhnVHbtxIf0QmeOas3okLDSjw=="
+  }
+}
\ No newline at end of file
diff --git a/crates/apub/assets/smithereen/objects/note.json b/crates/apub/assets/smithereen/objects/note.json
new file mode 100644 (file)
index 0000000..24d665b
--- /dev/null
@@ -0,0 +1,30 @@
+{
+  "type": "Note",
+  "id": "https://friends.grishka.me/posts/66561",
+  "attributedTo": "https://friends.grishka.me/users/1",
+  "content": "<p>So does this federate now?</p>",
+  "inReplyTo": "https://ds9.lemmy.ml/post/1723",
+  "published": "2021-11-09T11:42:35Z",
+  "tag": {
+    "type": "Mention",
+    "href": "https://ds9.lemmy.ml/u/nutomic"
+  },
+  "url": "https://friends.grishka.me/posts/66561",
+  "to": [
+    "https://www.w3.org/ns/activitystreams#Public"
+  ],
+  "cc": [
+    "https://ds9.lemmy.ml/u/nutomic"
+  ],
+  "replies": {
+    "type": "Collection",
+    "id": "https://friends.grishka.me/posts/66561/replies",
+    "first": {
+      "type": "CollectionPage",
+      "partOf": "https://friends.grishka.me/posts/66561/replies",
+      "next": "https://friends.grishka.me/posts/66561/replies?page=1"
+    }
+  },
+  "sensitive": false,
+  "likes": "https://friends.grishka.me/posts/66561/likes"
+}
\ No newline at end of file
diff --git a/crates/apub/assets/smithereen/objects/person.json b/crates/apub/assets/smithereen/objects/person.json
new file mode 100644 (file)
index 0000000..2773aab
--- /dev/null
@@ -0,0 +1,83 @@
+{
+  "type": "Person",
+  "id": "https://friends.grishka.me/users/1",
+  "name": "Григорий Клюшников",
+  "icon": {
+    "type": "Image",
+    "image": {
+      "type": "Image",
+      "url": "https://friends.grishka.me/i/6QLsOws97AWp5N_osd74C1IC1ijnFopyCBD9MSEeXNQ/q:93/bG9jYWw6Ly8vcy91cGxvYWRzL2F2YXRhcnMvNTYzODRhODEwODk5ZTRjMzI4YmY4YmQwM2Q2MWM3NmMud2VicA.jpg",
+      "mediaType": "image/jpeg",
+      "width": 1280,
+      "height": 960
+    },
+    "width": 573,
+    "height": 572,
+    "cropRegion": [
+      0.26422762870788574,
+      0.3766937553882599,
+      0.7113820910453796,
+      0.9728997349739075
+    ],
+    "url": "https://friends.grishka.me/i/ql_49PQcETAWgY_nC-Qj63H_Oa6FyOAEoWFkUSSkUvQ/c:573:572:nowe:338:362/q:93/bG9jYWw6Ly8vcy91cGxvYWRzL2F2YXRhcnMvNTYzODRhODEwODk5ZTRjMzI4YmY4YmQwM2Q2MWM3NmMud2VicA.jpg",
+    "mediaType": "image/jpeg"
+  },
+  "summary": "<p>Делаю эту хрень, пытаюсь вырвать социальные сети из жадных лап корпораций</p>\n<p></p>\n<p></p>\n<p></p>\n<p>This server does NOT support direct messages. Please write me <a href=\"https://t.me/grishka\">on Telegram</a> or Matrix (@grishk:matrix<span>.org</span>).</p>",
+  "url": "https://friends.grishka.me/grishka",
+  "preferredUsername": "grishka",
+  "inbox": "https://friends.grishka.me/users/1/inbox",
+  "outbox": "https://friends.grishka.me/users/1/outbox",
+  "followers": "https://friends.grishka.me/users/1/followers",
+  "following": "https://friends.grishka.me/users/1/following",
+  "endpoints": {
+    "sharedInbox": "https://friends.grishka.me/activitypub/sharedInbox"
+  },
+  "publicKey": {
+    "id": "https://friends.grishka.me/users/1#main-key",
+    "owner": "https://friends.grishka.me/users/1",
+    "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjlakm+i/d9ER/hIeR7KfiFW+SdLZj2SkKIeM8cmR+YFJuh9ghFqXrkFEjcaqUnAFqe5gYDNSQACnDLA8y4DnzjfGNIohKAnRoa9x6GORmfKQvcnjaTZ53S1NvUiPPyc0Pv/vfCtY/Ab0CEXe5BLqL38oZn817Jf7pBrPRTYH7m012kvwAUTT6k0Y8lPITBEG7nzYbbuGcrN9Y/RDdwE08jmBXlZ45bahRH3VNXVpQE17dCzJB+7k+iJ1R7YCoI+DuMlBYGXGE2KVk46NZTuLnOjFV9SyXfWX4/SrJM4oxev+SX2N75tQgmNZmVVHeqg2ZcbC0WCfNjJOi2HHS9MujwIDAQAB\n-----END PUBLIC KEY-----\n"
+  },
+  "wall": "https://friends.grishka.me/users/1/wall",
+  "firstName": "Григорий",
+  "lastName": "Клюшников",
+  "middleName": "Александрович",
+  "vcard:bday": "1993-01-22",
+  "gender": "http://schema.org#Male",
+  "supportsFriendRequests": true,
+  "friends": "https://friends.grishka.me/users/1/friends",
+  "groups": "https://friends.grishka.me/users/1/groups",
+  "@context": [
+    "https://www.w3.org/ns/activitystreams",
+    {
+      "sm": "http://smithereen.software/ns#",
+      "cropRegion": {
+        "@id": "sm:cropRegion",
+        "@container": "@list"
+      },
+      "wall": {
+        "@id": "sm:wall",
+        "@type": "@id"
+      },
+      "sc": "http://schema.org#",
+      "firstName": "sc:givenName",
+      "lastName": "sc:familyName",
+      "middleName": "sc:additionalName",
+      "gender": {
+        "@id": "sc:gender",
+        "@type": "sc:GenderType"
+      },
+      "supportsFriendRequests": "sm:supportsFriendRequests",
+      "maidenName": "sm:maidenName",
+      "friends": {
+        "@id": "sm:friends",
+        "@type": "@id"
+      },
+      "groups": {
+        "@id": "sm:groups",
+        "@type": "@id"
+      },
+      "vcard": "http://www.w3.org/2006/vcard/ns#"
+    },
+    "https://w3id.org/security/v1"
+  ]
+}
\ No newline at end of file
index 1048d46ac2e73a31420a3abae1cef88643cd1f6a..d391e8286cdb90972cb87d8b5d937c8f8406de48 100644 (file)
@@ -14,7 +14,7 @@ mod tests {
 
   #[actix_rt::test]
   #[serial]
-  async fn test_parse_lemmy_create_or_update() {
+  async fn test_parsey_create_or_update() {
     test_parse_lemmy_item::<CreateOrUpdatePost>(
       "assets/lemmy/activities/create_or_update/create_page.json",
     );
@@ -24,11 +24,9 @@ mod tests {
     test_parse_lemmy_item::<CreateOrUpdateComment>(
       "assets/lemmy/activities/create_or_update/create_note.json",
     );
-  }
 
-  #[actix_rt::test]
-  #[serial]
-  async fn test_parse_pleroma_create_or_update() {
     file_to_json_object::<CreateOrUpdateComment>("assets/pleroma/activities/create_note.json");
+    file_to_json_object::<CreateOrUpdateComment>("assets/smithereen/activities/create_note.json");
+    file_to_json_object::<CreateOrUpdateComment>("assets/mastodon/activities/create_note.json");
   }
 }
index bf53d5c99eca6241ce04e4519f21ea56528cc55e..f8cc877a70c251a1bf72a925f0710394e6afaa95 100644 (file)
@@ -17,19 +17,32 @@ pub struct Endpoints {
 
 #[cfg(test)]
 mod tests {
-  use crate::protocol::{
-    objects::{chat_message::ChatMessage, group::Group, note::Note, page::Page, person::Person},
-    tests::test_parse_lemmy_item,
+  use crate::{
+    objects::tests::file_to_json_object,
+    protocol::{
+      objects::{chat_message::ChatMessage, group::Group, note::Note, page::Page, person::Person},
+      tests::test_parse_lemmy_item,
+    },
   };
   use serial_test::serial;
 
   #[actix_rt::test]
   #[serial]
-  async fn test_parse_lemmy_object() {
+  async fn test_parse_object() {
     test_parse_lemmy_item::<Person>("assets/lemmy/objects/person.json");
     test_parse_lemmy_item::<Group>("assets/lemmy/objects/group.json");
     test_parse_lemmy_item::<Page>("assets/lemmy/objects/page.json");
     test_parse_lemmy_item::<Note>("assets/lemmy/objects/note.json");
     test_parse_lemmy_item::<ChatMessage>("assets/lemmy/objects/chat_message.json");
+
+    file_to_json_object::<Person>("assets/pleroma/objects/person.json");
+    file_to_json_object::<Note>("assets/pleroma/objects/note.json");
+    file_to_json_object::<ChatMessage>("assets/pleroma/objects/chat_message.json");
+
+    file_to_json_object::<Person>("assets/smithereen/objects/person.json");
+    file_to_json_object::<Note>("assets/smithereen/objects/note.json");
+
+    file_to_json_object::<Person>("assets/mastodon/objects/person.json");
+    file_to_json_object::<Note>("assets/mastodon/objects/note.json");
   }
 }
index 3ffc1123d4dea5e1aa97b68a275ab5461c3e6b46..6d582b347915f4c30293a7f6f07bfad12d576f8f 100644 (file)
@@ -27,6 +27,7 @@ pub struct Note {
   pub(crate) cc: Vec<Url>,
   pub(crate) content: String,
   pub(crate) media_type: Option<MediaTypeHtml>,
+  #[serde(default)]
   pub(crate) source: SourceCompat,
   pub(crate) in_reply_to: ObjectId<PostOrComment>,
   pub(crate) published: Option<DateTime<FixedOffset>>,
@@ -40,10 +41,17 @@ pub struct Note {
 #[serde(rename_all = "camelCase")]
 #[serde(untagged)]
 pub(crate) enum SourceCompat {
+  None,
   Lemmy(Source),
   Pleroma(String),
 }
 
+impl Default for SourceCompat {
+  fn default() -> Self {
+    SourceCompat::None
+  }
+}
+
 impl Note {
   pub(crate) async fn get_parents(
     &self,