Disallow following locked accounts over OStatus
authorrinpatch <rinpatch@sdf.org>
Wed, 31 Jul 2019 19:05:12 +0000 (22:05 +0300)
committerrinpatch <rinpatch@sdf.org>
Wed, 31 Jul 2019 19:05:12 +0000 (22:05 +0300)
lib/pleroma/web/ostatus/handlers/follow_handler.ex
test/web/ostatus/ostatus_test.exs

index 03e4cbbb002d23d5aab9cf827ff0c634a1ae26a4..24513972e6bbdff7a53273718f00b593495a7432 100644 (file)
@@ -14,9 +14,13 @@ defmodule Pleroma.Web.OStatus.FollowHandler do
          followed_uri when not is_nil(followed_uri) <-
            XML.string_from_xpath("/entry/activity:object/id", entry),
          {:ok, followed} <- OStatus.find_or_make_user(followed_uri),
+         {:locked, false} <- {:locked, followed.info.locked},
          {:ok, activity} <- ActivityPub.follow(actor, followed, id, false) do
       User.follow(actor, followed)
       {:ok, activity}
+    else
+      {:locked, true} ->
+        {:error, "It's not possible to follow locked accounts over OStatus"}
     end
   end
 end
index d244dbcf77a4a81ed5a3fc1c1a1064fd367c2d77..f8d389020e8fcfa2ce310f792ac982a6f1fea5fd 100644 (file)
@@ -326,6 +326,14 @@ defmodule Pleroma.Web.OStatusTest do
     assert User.following?(follower, followed)
   end
 
+  test "refuse following over OStatus if the followed's account is locked" do
+    incoming = File.read!("test/fixtures/follow.xml")
+    _user = insert(:user, info: %{locked: true}, ap_id: "https://pawoo.net/users/pekorino")
+
+    {:ok, [{:error, "It's not possible to follow locked accounts over OStatus"}]} =
+      OStatus.handle_incoming(incoming)
+  end
+
   test "handle incoming unfollows with existing follow" do
     incoming_follow = File.read!("test/fixtures/follow.xml")
     {:ok, [_activity]} = OStatus.handle_incoming(incoming_follow)