X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Fostatus%2Fostatus_test.exs;h=e40fae78cc3a1d22f5386ab7cc6a998b236f0db5;hb=bdcf42180fa67e43f13584d5e19f26d751199d03;hp=1674edbd5a7f63d417c006c9624ae2d9183d6ba8;hpb=102455bf296165a88578a04f0ded259c32349d7f;p=akkoma diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index 1674edbd5..e40fae78c 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -2,11 +2,13 @@ defmodule Pleroma.Web.OStatusTest do use Pleroma.DataCase alias Pleroma.Web.OStatus alias Pleroma.Web.XML + alias Pleroma.{Object, Repo, User, Activity} + import Pleroma.Factory test "don't insert create notes twice" do incoming = File.read!("test/fixtures/incoming_note_activity.xml") - {:ok, [_activity]} = OStatus.handle_incoming(incoming) - assert {:ok, [{:error, "duplicate activity"}]} == OStatus.handle_incoming(incoming) + {:ok, [activity]} = OStatus.handle_incoming(incoming) + assert {:ok, [activity]} == OStatus.handle_incoming(incoming) end test "handle incoming note - GS, Salmon" do @@ -30,6 +32,58 @@ defmodule Pleroma.Web.OStatusTest do assert activity.data["object"]["type"] == "Note" assert activity.data["object"]["actor"] == "https://social.heldscal.la/user/23211" assert activity.data["object"]["content"] == "Will it blend?" + user = User.get_cached_by_ap_id(activity.data["actor"]) + assert User.ap_followers(user) in activity.data["to"] + end + + test "handle incoming notes with attachments - GS, subscription" do + incoming = File.read!("test/fixtures/incoming_websub_gnusocial_attachments.xml") + {:ok, [activity]} = OStatus.handle_incoming(incoming) + + assert activity.data["type"] == "Create" + assert activity.data["object"]["type"] == "Note" + assert activity.data["object"]["actor"] == "https://social.heldscal.la/user/23211" + assert activity.data["object"]["attachment"] |> length == 2 + end + + test "handle incoming notes with tags" do + incoming = File.read!("test/fixtures/ostatus_incoming_post_tag.xml") + {:ok, [activity]} = OStatus.handle_incoming(incoming) + + assert activity.data["object"]["tag"] == ["nsfw"] + end + + test "handle incoming notes - Mastodon, salmon, reply" do + # It uses the context of the replied to object + Repo.insert!(%Object{ + data: %{ + "id" => "https://pleroma.soykaf.com/objects/c237d966-ac75-4fe3-a87a-d89d71a3a7a4", + "context" => "2hu" + }}) + incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml") + {:ok, [activity]} = OStatus.handle_incoming(incoming) + + assert activity.data["type"] == "Create" + assert activity.data["object"]["type"] == "Note" + assert activity.data["object"]["actor"] == "https://mastodon.social/users/lambadalambda" + assert activity.data["context"] == "2hu" + end + + test "handle incoming notes - Mastodon, with CW" do + incoming = File.read!("test/fixtures/mastodon-note-cw.xml") + {:ok, [activity]} = OStatus.handle_incoming(incoming) + + assert activity.data["type"] == "Create" + assert activity.data["object"]["type"] == "Note" + assert activity.data["object"]["actor"] == "https://mastodon.social/users/lambadalambda" + assert String.contains?(activity.data["object"]["content"], "technologic") + end + + test "handle incoming retweets - Mastodon, with CW" do + incoming = File.read!("test/fixtures/cw_retweet.xml") + {:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming) + + assert String.contains?(retweeted_activity.data["object"]["content"], "Hey.") end test "handle incoming notes - GS, subscription, reply" do @@ -43,6 +97,97 @@ defmodule Pleroma.Web.OStatusTest do assert activity.data["object"]["inReplyTo"] == "tag:gs.archae.me,2017-04-30:noticeId=778260:objectType=note" end + test "handle incoming retweets - GS, subscription" do + incoming = File.read!("test/fixtures/share-gs.xml") + {:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming) + + assert activity.data["type"] == "Announce" + assert activity.data["actor"] == "https://social.heldscal.la/user/23211" + assert activity.data["object"] == retweeted_activity.data["object"]["id"] + assert "https://pleroma.soykaf.com/users/lain" in activity.data["to"] + refute activity.local + + retweeted_activity = Repo.get(Activity, retweeted_activity.id) + assert retweeted_activity.data["type"] == "Create" + assert retweeted_activity.data["actor"] == "https://pleroma.soykaf.com/users/lain" + refute retweeted_activity.local + assert retweeted_activity.data["object"]["announcement_count"] == 1 + assert String.contains?(retweeted_activity.data["object"]["content"], "mastodon") + refute String.contains?(retweeted_activity.data["object"]["content"], "Test account") + end + + test "handle incoming retweets - GS, subscription - local message" do + incoming = File.read!("test/fixtures/share-gs-local.xml") + note_activity = insert(:note_activity) + user = User.get_cached_by_ap_id(note_activity.data["actor"]) + incoming = incoming + |> String.replace("LOCAL_ID", note_activity.data["object"]["id"]) + |> String.replace("LOCAL_USER", user.ap_id) + + {:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming) + + assert activity.data["type"] == "Announce" + assert activity.data["actor"] == "https://social.heldscal.la/user/23211" + assert activity.data["object"] == retweeted_activity.data["object"]["id"] + assert user.ap_id in activity.data["to"] + refute activity.local + + retweeted_activity = Repo.get(Activity, retweeted_activity.id) + assert note_activity.id == retweeted_activity.id + assert retweeted_activity.data["type"] == "Create" + assert retweeted_activity.data["actor"] == user.ap_id + assert retweeted_activity.local + assert retweeted_activity.data["object"]["announcement_count"] == 1 + end + + test "handle incoming retweets - Mastodon, salmon" do + incoming = File.read!("test/fixtures/share.xml") + {:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming) + + assert activity.data["type"] == "Announce" + assert activity.data["actor"] == "https://mastodon.social/users/lambadalambda" + assert activity.data["object"] == retweeted_activity.data["object"]["id"] + assert activity.data["id"] == "tag:mastodon.social,2017-05-03:objectId=4934452:objectType=Status" + + refute activity.local + assert retweeted_activity.data["type"] == "Create" + assert retweeted_activity.data["actor"] == "https://pleroma.soykaf.com/users/lain" + refute retweeted_activity.local + refute String.contains?(retweeted_activity.data["object"]["content"], "Test account") + end + + test "handle incoming favorites - GS, websub" do + incoming = File.read!("test/fixtures/favorite.xml") + {:ok, [[activity, favorited_activity]]} = OStatus.handle_incoming(incoming) + + assert activity.data["type"] == "Like" + assert activity.data["actor"] == "https://social.heldscal.la/user/23211" + assert activity.data["object"] == favorited_activity.data["object"]["id"] + assert activity.data["id"] == "tag:social.heldscal.la,2017-05-05:fave:23211:comment:2061643:2017-05-05T09:12:50+00:00" + + refute activity.local + assert favorited_activity.data["type"] == "Create" + assert favorited_activity.data["actor"] == "https://shitposter.club/user/1" + assert favorited_activity.data["object"]["id"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment" + refute favorited_activity.local + end + + test "handle incoming favorites with locally available object - GS, websub" do + note_activity = insert(:note_activity) + + incoming = File.read!("test/fixtures/favorite_with_local_note.xml") + |> String.replace("localid", note_activity.data["object"]["id"]) + + {:ok, [[activity, favorited_activity]]} = OStatus.handle_incoming(incoming) + + assert activity.data["type"] == "Like" + assert activity.data["actor"] == "https://social.heldscal.la/user/23211" + assert activity.data["object"] == favorited_activity.data["object"]["id"] + refute activity.local + assert note_activity.id == favorited_activity.id + assert favorited_activity.local + end + test "handle incoming replies" do incoming = File.read!("test/fixtures/incoming_note_activity_answer.xml") {:ok, [activity]} = OStatus.handle_incoming(incoming) @@ -51,11 +196,33 @@ defmodule Pleroma.Web.OStatusTest do assert activity.data["object"]["type"] == "Note" assert activity.data["object"]["inReplyTo"] == "http://pleroma.example.org:4000/objects/55bce8fc-b423-46b1-af71-3759ab4670bc" assert "http://pleroma.example.org:4000/users/lain5" in activity.data["to"] + assert activity.data["object"]["id"] == "tag:gs.example.org:4040,2017-04-25:noticeId=55:objectType=note" + end + + test "handle incoming follows" do + incoming = File.read!("test/fixtures/follow.xml") + {:ok, [activity]} = OStatus.handle_incoming(incoming) + assert activity.data["type"] == "Follow" + assert activity.data["id"] == "tag:social.heldscal.la,2017-05-07:subscription:23211:person:44803:2017-05-07T09:54:48+00:00" + assert activity.data["actor"] == "https://social.heldscal.la/user/23211" + assert activity.data["object"] == "https://pawoo.net/users/pekorino" + refute activity.local + + follower = User.get_by_ap_id(activity.data["actor"]) + followed = User.get_by_ap_id(activity.data["object"]) + + assert User.following?(follower, followed) end describe "new remote user creation" do + test "returns local users" do + local_user = insert(:user) + {:ok, user} = OStatus.find_or_make_user(local_user.ap_id) + + assert user == local_user + end + test "tries to use the information in poco fields" do - # TODO make test local uri = "https://social.heldscal.la/user/23211" {:ok, user} = OStatus.find_or_make_user(uri) @@ -66,6 +233,7 @@ defmodule Pleroma.Web.OStatusTest do assert user.local == false assert user.info["uri"] == uri assert user.ap_id == uri + assert user.bio == "Call me Deacon Blues." assert user.avatar["type"] == "Image" {:ok, user_again} = OStatus.find_or_make_user(uri) @@ -74,11 +242,12 @@ defmodule Pleroma.Web.OStatusTest do end test "find_make_or_update_user takes an author element and returns an updated user" do - # TODO make test local uri = "https://social.heldscal.la/user/23211" {:ok, user} = OStatus.find_or_make_user(uri) - change = Ecto.Changeset.change(user, %{avatar: nil}) + old_name = user.name + old_bio = user.bio + change = Ecto.Changeset.change(user, %{avatar: nil, bio: nil, old_name: nil}) {:ok, user} = Repo.update(change) refute user.avatar @@ -87,6 +256,8 @@ defmodule Pleroma.Web.OStatusTest do [author] = :xmerl_xpath.string('//author[1]', doc) {:ok, user} = OStatus.find_make_or_update_user(author) assert user.avatar["type"] == "Image" + assert user.name == old_name + assert user.bio == old_bio {:ok, user_again} = OStatus.find_make_or_update_user(author) assert user_again == user @@ -101,17 +272,18 @@ defmodule Pleroma.Web.OStatusTest do {:ok, data} = OStatus.gather_user_info(user) expected = %{ - hub: "https://social.heldscal.la/main/push/hub", - magic_key: "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB", - name: "shp", - nickname: "shp", - salmon: "https://social.heldscal.la/main/salmon/user/29191", - subject: "acct:shp@social.heldscal.la", - topic: "https://social.heldscal.la/api/statuses/user_timeline/29191.atom", - uri: "https://social.heldscal.la/user/29191", - host: "social.heldscal.la", - fqn: user, - avatar: %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]} + "hub" => "https://social.heldscal.la/main/push/hub", + "magic_key" => "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB", + "name" => "shp", + "nickname" => "shp", + "salmon" => "https://social.heldscal.la/main/salmon/user/29191", + "subject" => "acct:shp@social.heldscal.la", + "topic" => "https://social.heldscal.la/api/statuses/user_timeline/29191.atom", + "uri" => "https://social.heldscal.la/user/29191", + "host" => "social.heldscal.la", + "fqn" => user, + "bio" => "cofe", + "avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]} } assert data == expected end @@ -123,19 +295,30 @@ defmodule Pleroma.Web.OStatusTest do {:ok, data} = OStatus.gather_user_info(user) expected = %{ - hub: "https://social.heldscal.la/main/push/hub", - magic_key: "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB", - name: "shp", - nickname: "shp", - salmon: "https://social.heldscal.la/main/salmon/user/29191", - subject: "https://social.heldscal.la/user/29191", - topic: "https://social.heldscal.la/api/statuses/user_timeline/29191.atom", - uri: "https://social.heldscal.la/user/29191", - host: "social.heldscal.la", - fqn: user, - avatar: %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]} + "hub" => "https://social.heldscal.la/main/push/hub", + "magic_key" => "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB", + "name" => "shp", + "nickname" => "shp", + "salmon" => "https://social.heldscal.la/main/salmon/user/29191", + "subject" => "https://social.heldscal.la/user/29191", + "topic" => "https://social.heldscal.la/api/statuses/user_timeline/29191.atom", + "uri" => "https://social.heldscal.la/user/29191", + "host" => "social.heldscal.la", + "fqn" => user, + "bio" => "cofe", + "avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]} } assert data == expected end end + + describe "fetching a status by it's HTML url" do + test "it builds a missing status from an html url" do + url = "https://shitposter.club/notice/2827873" + {:ok, [activity] } = OStatus.fetch_activity_from_html_url(url) + + assert activity.data["actor"] == "https://shitposter.club/user/1" + assert activity.data["object"]["id"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment" + end + end end