X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=inline;f=test%2Fweb%2Factivity_pub%2Ftransmogrifier%2Ffollow_handling_test.exs;h=7d6d0814d7eb6e21d035d5f7fb4c8592f0f50c8d;hb=6cb31edd76fd42a0e33bc365d982cd02e3578d6c;hp=9f89e876b65e8f6d4e6847ab2a7c0b27499a940a;hpb=8b9a0dd4a7e60f610e3aa1db92e62bc0fbe54521;p=akkoma
diff --git a/test/web/activity_pub/transmogrifier/follow_handling_test.exs b/test/web/activity_pub/transmogrifier/follow_handling_test.exs
index 9f89e876b..7d6d0814d 100644
--- a/test/web/activity_pub/transmogrifier/follow_handling_test.exs
+++ b/test/web/activity_pub/transmogrifier/follow_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
@@ -19,6 +19,25 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
end
describe "handle_incoming" do
+ test "it works for osada follow request" do
+ user = insert(:user)
+
+ data =
+ File.read!("test/fixtures/osada-follow-activity.json")
+ |> Poison.decode!()
+ |> Map.put("object", user.ap_id)
+
+ {:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
+
+ assert data["actor"] == "https://apfed.club/channel/indio"
+ assert data["type"] == "Follow"
+ assert data["id"] == "https://apfed.club/follow/9"
+
+ activity = Repo.get(Activity, activity.id)
+ assert activity.data["state"] == "accept"
+ assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
+ end
+
test "it works for incoming follow requests" do
user = insert(:user)
@@ -27,18 +46,46 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|> Poison.decode!()
|> Map.put("object", user.ap_id)
- {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+ {:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
assert data["actor"] == "http://mastodon.example.org/users/admin"
assert data["type"] == "Follow"
assert data["id"] == "http://mastodon.example.org/users/admin#follows/2"
+
+ activity = Repo.get(Activity, activity.id)
+ assert activity.data["state"] == "accept"
assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
end
+ test "with locked accounts, it does not create a follow or an accept" do
+ user = insert(:user, locked: true)
+
+ data =
+ File.read!("test/fixtures/mastodon-follow-activity.json")
+ |> Poison.decode!()
+ |> Map.put("object", user.ap_id)
+
+ {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+
+ assert data["state"] == "pending"
+
+ refute User.following?(User.get_cached_by_ap_id(data["actor"]), user)
+
+ accepts =
+ from(
+ a in Activity,
+ where: fragment("?->>'type' = ?", a.data, "Accept")
+ )
+ |> Repo.all()
+
+ assert length(accepts) == 0
+ end
+
test "it works for follow requests when you are already followed, creating a new accept activity" do
- # This is important because the remote might have the wrong idea about the current follow status.
- # This can lead to instance A thinking that x@A is followed by y@B, but B thinks they are not. In
- # this case, the follow can never go through again because it will never get an Accept.
+ # This is important because the remote might have the wrong idea about the
+ # current follow status. This can lead to instance A thinking that x@A is
+ # followed by y@B, but B thinks they are not. In this case, the follow can
+ # never go through again because it will never get an Accept.
user = insert(:user)
data =
@@ -81,7 +128,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
user = insert(:user)
{:ok, target} = User.get_or_fetch("http://mastodon.example.org/users/admin")
- {:ok, user} = User.block(user, target)
+ {:ok, _user_relationship} = User.block(user, target)
data =
File.read!("test/fixtures/mastodon-follow-activity.json")