From 3320c9b176d7665a9d99e235458e04ade1999afe Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Mon, 8 May 2017 18:19:45 +0200 Subject: [PATCH] Fix remote users retweeting local stuff. --- lib/pleroma/web/ostatus/ostatus.ex | 2 +- test/fixtures/share-gs-local.xml | 99 ++++++++++++++++++++++++++++++ test/web/ostatus/ostatus_test.exs | 34 +++++++++- 3 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/share-gs-local.xml diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index 01f65affc..8c1da0920 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -176,7 +176,7 @@ def handle_note(entry, doc \\ nil) do # TODO: Bail out sooner and use transaction. if Object.get_by_ap_id(id) do - {:error, "duplicate activity"} + {:ok, Activity.get_create_activity_by_object_ap_id(id)} else ActivityPub.create(to, actor, context, object, %{}, date, false) end diff --git a/test/fixtures/share-gs-local.xml b/test/fixtures/share-gs-local.xml new file mode 100644 index 000000000..9d52eab7b --- /dev/null +++ b/test/fixtures/share-gs-local.xml @@ -0,0 +1,99 @@ + + + GNU social + https://social.heldscal.la/api/statuses/user_timeline/23211.atom + lambadalambda timeline + Updates from lambadalambda on social.heldscal.la! + https://social.heldscal.la/avatar/23211-96-20170416114255.jpeg + 2017-05-03T08:05:41+00:00 + + http://activitystrea.ms/schema/1.0/person + https://social.heldscal.la/user/23211 + lambadalambda + Call me Deacon Blues. + + + + + + lambadalambda + Constance Variable + Call me Deacon Blues. + + Berlin + + + homepage + https://heldscal.la + true + + + + + + + + + + + + + tag:social.heldscal.la,2017-05-03:noticeId=2028428:objectType=note + lambadalambda repeated a notice by lain + RT @<a href="https://pleroma.soykaf.com/users/lain" class="h-card u-url p-nickname mention" title="Lain Iwakura">lain</a> Added returning the entries as xml... let's see if the mastodon hammering stops now. + + http://activitystrea.ms/schema/1.0/share + 2017-05-03T08:05:41+00:00 + 2017-05-03T08:05:41+00:00 + + http://activitystrea.ms/schema/1.0/activity + LOCAL_ID + + Added returning the entries as xml... let's see if the mastodon hammering stops now. + + http://activitystrea.ms/schema/1.0/post + 2017-05-03T08:04:44+00:00 + 2017-05-03T08:04:44+00:00 + + http://activitystrea.ms/schema/1.0/person + LOCAL_USER + lain + Test account + + + + + + lain + Lain Iwakura + Test account + + + + http://activitystrea.ms/schema/1.0/note + https://pleroma.soykaf.com/objects/4c1bda26-902e-4525-9fcd-b9fd44925193 + New note by lain + Added returning the entries as xml... let's see if the mastodon hammering stops now. + + + + + https://pleroma.soykaf.com/contexts/ede39a2b-7cf3-4fa4-8ccd-cb97431bcc22 + + + https://pleroma.soykaf.com/users/lain/feed.atom + Lain Iwakura + + + https://social.heldscal.la/avatar/43188-96-20170429172422.jpeg + 2017-05-03T08:04:44+00:00 + + + + https://pleroma.soykaf.com/contexts/ede39a2b-7cf3-4fa4-8ccd-cb97431bcc22 + + + + + + diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index ff7afe808..39f299ab4 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -2,13 +2,13 @@ defmodule Pleroma.Web.OStatusTest do use Pleroma.DataCase alias Pleroma.Web.OStatus alias Pleroma.Web.XML - alias Pleroma.{Object, Repo, User} + 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 @@ -80,10 +80,38 @@ test "handle incoming retweets - GS, subscription" do 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 + 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