From 7252d5a3f48999f7fbcfe629696fc5cabdff74a3 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Tue, 31 Jul 2018 15:50:09 -0700 Subject: [PATCH] also parse the object inside Create activities --- lib/XRay/Formats/ActivityStreams.php | 5 ++ tests/ActivityStreamsTest.php | 18 +++++ .../data/activitystreams.example/create.json | 75 +++++++++++++++++++ tests/data/activitystreams.example/jamey | 65 ++++++++++++++++ 4 files changed, 163 insertions(+) create mode 100644 tests/data/activitystreams.example/create.json create mode 100644 tests/data/activitystreams.example/jamey diff --git a/lib/XRay/Formats/ActivityStreams.php b/lib/XRay/Formats/ActivityStreams.php index 0687a05..a8e4ac3 100644 --- a/lib/XRay/Formats/ActivityStreams.php +++ b/lib/XRay/Formats/ActivityStreams.php @@ -29,6 +29,11 @@ class ActivityStreams extends Format { if(!isset($as2['type'])) return false; + if($as2['type'] == 'Create' && is_array($as2['object'])) { + // Extract the object and parse that instead + $as2 = $as2['object']; + } + switch($as2['type']) { case 'Person': return self::parseAsHCard($as2, $url, $http, $opts); diff --git a/tests/ActivityStreamsTest.php b/tests/ActivityStreamsTest.php index 8872276..deb6b84 100644 --- a/tests/ActivityStreamsTest.php +++ b/tests/ActivityStreamsTest.php @@ -209,5 +209,23 @@ class ActivityStreamsTest extends PHPUnit_Framework_TestCase { $this->assertEquals('This is the text content of an ActivityStreams note', $data['data']['refs']['http://activitystreams.example/note.json']['data']['content']['text']); } + public function testNoteWrappedInCreate() { + $url = 'http://activitystreams.example/create.json'; + $response = $this->parse(['url' => $url]); + + $body = $response->getContent(); + $this->assertEquals(200, $response->getStatusCode()); + $data = json_decode($body, true); + + $this->assertEquals('activity+json', $data['source-format']); + $this->assertEquals('reply', $data['data']['post-type']); + $this->assertEquals('https://toot.cat/@jamey/100471682482196371', $data['data']['url']); + $this->assertEquals('2018-07-31T22:30:09+00:00', $data['data']['published']); + $this->assertEquals('@darius Huh, I just have never encountered anyone using the phrase generically like that.But you might consider writing IndieWeb.org-style bots (Atom+WebSub, and optionally WebMention if you want them to be interactive), and then using https://fed.brid.gy/ as an alternative to implementing ActivityPub yourself...', $data['data']['content']['text']); + $this->assertEquals('https://social.tinysubversions.com/users/darius/statuses/100471614681787834', $data['data']['in-reply-to'][0]); + $this->assertEquals('Jamey Sharp', $data['data']['author']['name']); + $this->assertEquals('https://s3-us-west-2.amazonaws.com/tootcatapril2017/accounts/avatars/000/013/259/original/c904452a8411e4f5.jpg', $data['data']['author']['photo']); + $this->assertEquals('https://toot.cat/@jamey', $data['data']['author']['url']); + } } diff --git a/tests/data/activitystreams.example/create.json b/tests/data/activitystreams.example/create.json new file mode 100644 index 0000000..4ade18f --- /dev/null +++ b/tests/data/activitystreams.example/create.json @@ -0,0 +1,75 @@ +HTTP/1.1 200 OK +Server: Apache +Date: Wed, 30 Jul 2018 03:29:14 GMT +Content-Type: application/activity+json +Connection: keep-alive + +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "sensitive": "as:sensitive", + "movedTo": "as:movedTo", + "Hashtag": "as:Hashtag", + "ostatus": "http://ostatus.org#", + "atomUri": "ostatus:atomUri", + "inReplyToAtomUri": "ostatus:inReplyToAtomUri", + "conversation": "ostatus:conversation", + "toot": "http://joinmastodon.org/ns#", + "Emoji": "toot:Emoji", + "focalPoint": { + "@container": "@list", + "@id": "toot:focalPoint" + }, + "featured": "toot:featured" + } + ], + "id": "https://toot.cat/users/jamey/statuses/100471682482196371/activity", + "type": "Create", + "actor": "https://toot.cat/users/jamey", + "published": "2018-07-31T22:30:09Z", + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc": [ + "https://toot.cat/users/jamey/followers", + "https://social.tinysubversions.com/users/darius" + ], + "object": { + "id": "https://toot.cat/users/jamey/statuses/100471682482196371", + "type": "Note", + "summary": null, + "content": "

@darius Huh, I just have never encountered anyone using the phrase generically like that.

But you might consider writing IndieWeb.org-style bots (Atom+WebSub, and optionally WebMention if you want them to be interactive), and then using https://fed.brid.gy/ as an alternative to implementing ActivityPub yourself...

", + "inReplyTo": "https://social.tinysubversions.com/users/darius/statuses/100471614681787834", + "published": "2018-07-31T22:30:09Z", + "url": "https://toot.cat/@jamey/100471682482196371", + "attributedTo": "http://activitystreams.example/jamey", + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc": [ + "https://toot.cat/users/jamey/followers", + "https://social.tinysubversions.com/users/darius" + ], + "sensitive": false, + "atomUri": "https://toot.cat/users/jamey/statuses/100471682482196371", + "inReplyToAtomUri": "https://social.tinysubversions.com/users/darius/statuses/100471614681787834", + "conversation": "tag:tinysubversions.com,2018-07-31:objectId=141754:objectType=Conversation", + "attachment": [], + "tag": [ + { + "type": "Mention", + "href": "https://social.tinysubversions.com/users/darius", + "name": "@darius@tinysubversions.com" + } + ] + }, + "signature": { + "type": "RsaSignature2017", + "creator": "https://toot.cat/users/jamey#main-key", + "created": "2018-07-31T22:30:10Z", + "signatureValue": "EV0Bv0kRqOQLiHYHwcy0ElgPNkOPXfQ1ygpAG028b24a3bwCmw3JQO/AyfxTyqf7MgUUVGMR8sFYQA4+MeZPCH39R3xdZ4K8Ce0GEv+GxT34jpIQkB4LQsL7X9GZFo6M20cP9m3197zU+/giPBjnOHfPJr61wHkkHklHfKVK13mmR4pqrrr6TOecXfr32n3y2+3qtrGIWBWl6DaDKK6aQTaXxu66wxbmIhIIcAvS7oQVvDMqXKuDrCfT+3wiVm+6mGENU1WtiiVEtpC9gfcXEbRWPhI35AHP+4ruuIvoZL3pOMk5fuCrnAbL3Vn0uFPrsh7JY19UbPrNRyK3je5oog==" + } +} diff --git a/tests/data/activitystreams.example/jamey b/tests/data/activitystreams.example/jamey new file mode 100644 index 0000000..c5f5189 --- /dev/null +++ b/tests/data/activitystreams.example/jamey @@ -0,0 +1,65 @@ +HTTP/1.1 200 OK +Date: Tue, 31 Jul 2018 22:46:57 GMT +Content-Type: application/activity+json; charset=utf-8 +Transfer-Encoding: chunked +Connection: keep-alive +Server: Mastodon +X-Frame-Options: DENY +X-Content-Type-Options: nosniff +X-XSS-Protection: 1; mode=block +Link: ; rel="lrdd"; type="application/xrd+xml", ; rel="alternate"; type="application/atom+xml", ; rel="alternate"; type="application/activity+json" +Vary: Accept,Accept-Encoding +Cache-Control: max-age=180, public +ETag: W/"e354d3ca6ebb3ebfdfbe129a17d2cfbc" +X-Request-Id: c3e7bab2-2cf2-4f2b-a380-7c6feb991704 +X-Runtime: 0.178355 +Strict-Transport-Security: max-age=31536000; includeSubDomains + +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "sensitive": "as:sensitive", + "movedTo": "as:movedTo", + "Hashtag": "as:Hashtag", + "ostatus": "http://ostatus.org#", + "atomUri": "ostatus:atomUri", + "inReplyToAtomUri": "ostatus:inReplyToAtomUri", + "conversation": "ostatus:conversation", + "toot": "http://joinmastodon.org/ns#", + "Emoji": "toot:Emoji", + "focalPoint": { + "@container": "@list", + "@id": "toot:focalPoint" + }, + "featured": "toot:featured" + } + ], + "id": "https://toot.cat/users/jamey", + "type": "Person", + "following": "https://toot.cat/users/jamey/following", + "followers": "https://toot.cat/users/jamey/followers", + "inbox": "https://toot.cat/users/jamey/inbox", + "outbox": "https://toot.cat/users/jamey/outbox", + "featured": "https://toot.cat/users/jamey/collections/featured", + "preferredUsername": "jamey", + "name": "Jamey Sharp", + "summary": "

Making the computer boxes do what they're supposed to, and nothing else : https://jamey.thesharps.us : https://liberapay.com/jamey/ : 30s, he/they

", + "url": "https://toot.cat/@jamey", + "manuallyApprovesFollowers": false, + "publicKey": { + "id": "https://toot.cat/users/jamey#main-key", + "owner": "https://toot.cat/users/jamey", + "publicKeyPem": "-----BEGIN PUBLIC KEY-----\r\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAm6OHTzDVR+hineYdFpUE\r\ngNJax20CjDWGl0jslR7sfcVSvc8UZ+IjooHeq8rTDA2NhVvnDevvaBpUmVqYg5bT\r\n0b6kQnyhI/RlUtLC4DpbA2pCitzBJ9S20NCVPX2YYZg6Hpbx1AY0vre2Od6N3M1p\r\nct+peO654xz4a0sRMSgqgxzyehBc1ovW4KXL927dytWu6N/b3572qI3SoTTLHTOA\r\nKrWrXMGWbKWEEV/3FqgcSUw49Kss3wh+0nko/dyxY0+SGsckxkJQvQFQRtoGO6OQ\r\nGscuox65dokqIvyBujfmSC46F69tWNOtrRGHMQ433LmWbDZW7dGVShH5bG2itMeD\r\n8wIDAQAB\r\n-----END PUBLIC KEY-----\r\n" + }, + "endpoints": { + "sharedInbox": "https://toot.cat/inbox" + }, + "icon": { + "type": "Image", + "mediaType": "image/jpeg", + "url": "https://s3-us-west-2.amazonaws.com/tootcatapril2017/accounts/avatars/000/013/259/original/c904452a8411e4f5.jpg" + } +}