From d045b96f957e0698ecd0110ca240f0527e3fea43 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Mon, 21 May 2018 05:11:13 -0400 Subject: [PATCH] Add tests for incoming unfollow over OStatus --- .../web/ostatus/activity_representer.ex | 1 + test/fixtures/unfollow.xml | 68 +++++++++++++++++++ test/web/ostatus/ostatus_test.exs | 24 +++++++ 3 files changed, 93 insertions(+) create mode 100644 test/fixtures/unfollow.xml diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index a9c2b89b4..4179d86c9 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -247,6 +247,7 @@ def to_simple_form( mentions = (activity.recipients || []) |> get_mentions follow_activity = Activity.get_by_ap_id(follow_activity["id"]) + [ {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/activity']}, {:"activity:verb", ['http://activitystrea.ms/schema/1.0/unfollow']}, diff --git a/test/fixtures/unfollow.xml b/test/fixtures/unfollow.xml new file mode 100644 index 000000000..7a8f8fd2e --- /dev/null +++ b/test/fixtures/unfollow.xml @@ -0,0 +1,68 @@ + + + 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-07T09:54:49+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 + + + + + + + + + + + + + undo:tag:social.heldscal.la,2017-05-07:subscription:23211:person:44803:2017-05-07T09:54:48+00:00 + Constance Variable (lambadalambda@social.heldscal.la)'s status on Sunday, 07-May-2017 09:54:49 UTC + <a href="https://social.heldscal.la/lambadalambda">Constance Variable</a> stopped following <a href="https://pawoo.net/@pekorino">mono</a>. + + http://activitystrea.ms/schema/1.0/unfollow + 2017-05-07T09:54:49+00:00 + 2017-05-07T09:54:49+00:00 + + http://activitystrea.ms/schema/1.0/person + https://pawoo.net/users/pekorino + mono + http://shitposter.club/mono 孤独のグルメ + + + + + pekorino + mono + http://shitposter.club/mono 孤独のグルメ + + + tag:social.heldscal.la,2017-05-07:objectType=thread:nonce=6e80caf94e03029f + + + + + + diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index 3e7cf0155..f095e41dd 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -278,6 +278,30 @@ test "handle incoming follows" do assert User.following?(follower, followed) end + test "handle incoming unfollows with existing follow" do + incoming_follow = File.read!("test/fixtures/follow.xml") + {:ok, [_activity]} = OStatus.handle_incoming(incoming_follow) + + incoming = File.read!("test/fixtures/unfollow.xml") + {:ok, [activity]} = OStatus.handle_incoming(incoming) + + assert activity.data["type"] == "Undo" + + assert activity.data["id"] == + "undo: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 is_map(activity.data["object"]) + assert activity.data["object"]["type"] == "Follow" + assert activity.data["object"]["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"]["object"]) + + refute User.following?(follower, followed) + end + describe "new remote user creation" do test "returns local users" do local_user = insert(:user)