From: Felix Ableitner Date: Tue, 9 Nov 2021 12:25:19 +0000 (+0100) Subject: Add federation test cases for Smithereen and Mastodon X-Git-Url: http://these/git/ui/assets/static/%7Bvideo_url%7D?a=commitdiff_plain;h=5319046dc75762068f24dce66a9620dc10de56d0;p=lemmy.git Add federation test cases for Smithereen and Mastodon --- diff --git a/crates/apub/assets/mastodon/activities/create_note.json b/crates/apub/assets/mastodon/activities/create_note.json new file mode 100644 index 00000000..8b836fb2 --- /dev/null +++ b/crates/apub/assets/mastodon/activities/create_note.json @@ -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": "

@retiolus 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.

", + "contentMap": { + "en": "

@retiolus 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.

" + }, + "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 index 00000000..cf0d9fe5 --- /dev/null +++ b/crates/apub/assets/mastodon/objects/note.json @@ -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": "

@retiolus 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.

", + "contentMap": { + "en": "

@retiolus 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.

" + }, + "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 index 00000000..0ae4e7fa --- /dev/null +++ b/crates/apub/assets/mastodon/objects/person.json @@ -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": "

#Lemmy Maintainer

", + "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 index 00000000..a30bc9a5 --- /dev/null +++ b/crates/apub/assets/smithereen/activities/create_note.json @@ -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": "

So does this federate now?

", + "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 index 00000000..24d665b2 --- /dev/null +++ b/crates/apub/assets/smithereen/objects/note.json @@ -0,0 +1,30 @@ +{ + "type": "Note", + "id": "https://friends.grishka.me/posts/66561", + "attributedTo": "https://friends.grishka.me/users/1", + "content": "

So does this federate now?

", + "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 index 00000000..2773aab2 --- /dev/null +++ b/crates/apub/assets/smithereen/objects/person.json @@ -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": "

Делаю эту хрень, пытаюсь вырвать социальные сети из жадных лап корпораций

\n

\n

\n

\n

This server does NOT support direct messages. Please write me on Telegram or Matrix (@grishk:matrix.org).

", + "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 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 1048d46a..d391e828 100644 --- a/crates/apub/src/protocol/activities/create_or_update/mod.rs +++ b/crates/apub/src/protocol/activities/create_or_update/mod.rs @@ -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::( "assets/lemmy/activities/create_or_update/create_page.json", ); @@ -24,11 +24,9 @@ mod tests { test_parse_lemmy_item::( "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::("assets/pleroma/activities/create_note.json"); + file_to_json_object::("assets/smithereen/activities/create_note.json"); + file_to_json_object::("assets/mastodon/activities/create_note.json"); } } diff --git a/crates/apub/src/protocol/objects/mod.rs b/crates/apub/src/protocol/objects/mod.rs index bf53d5c9..f8cc877a 100644 --- a/crates/apub/src/protocol/objects/mod.rs +++ b/crates/apub/src/protocol/objects/mod.rs @@ -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::("assets/lemmy/objects/person.json"); test_parse_lemmy_item::("assets/lemmy/objects/group.json"); test_parse_lemmy_item::("assets/lemmy/objects/page.json"); test_parse_lemmy_item::("assets/lemmy/objects/note.json"); test_parse_lemmy_item::("assets/lemmy/objects/chat_message.json"); + + file_to_json_object::("assets/pleroma/objects/person.json"); + file_to_json_object::("assets/pleroma/objects/note.json"); + file_to_json_object::("assets/pleroma/objects/chat_message.json"); + + file_to_json_object::("assets/smithereen/objects/person.json"); + file_to_json_object::("assets/smithereen/objects/note.json"); + + file_to_json_object::("assets/mastodon/objects/person.json"); + file_to_json_object::("assets/mastodon/objects/note.json"); } } diff --git a/crates/apub/src/protocol/objects/note.rs b/crates/apub/src/protocol/objects/note.rs index 3ffc1123..6d582b34 100644 --- a/crates/apub/src/protocol/objects/note.rs +++ b/crates/apub/src/protocol/objects/note.rs @@ -27,6 +27,7 @@ pub struct Note { pub(crate) cc: Vec, pub(crate) content: String, pub(crate) media_type: Option, + #[serde(default)] pub(crate) source: SourceCompat, pub(crate) in_reply_to: ObjectId, pub(crate) published: Option>, @@ -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,