Add tests, change default config values, fix a bug
authorKaren Konou <konoukaren@gmail.com>
Fri, 15 Feb 2019 11:47:50 +0000 (12:47 +0100)
committerKaren Konou <konoukaren@gmail.com>
Fri, 15 Feb 2019 11:47:50 +0000 (12:47 +0100)
config/config.exs
lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex
test/web/activity_pub/mrf/hellthread_policy_test.exs [new file with mode: 0644]

index 5db0ea9aa9a5397834fa53514c7b73fb71392724..e2a239a76baea09e3b986bd42d1fe7602adeb82b 100644 (file)
@@ -228,8 +228,8 @@ config :pleroma, :mrf_rejectnonpublic,
   allow_direct: false
 
 config :pleroma, :mrf_hellthread,
-  delist_threshold: 5,
-  reject_threshold: 10
+  delist_threshold: 10,
+  reject_threshold: 20
 
 config :pleroma, :mrf_simple,
   media_removal: [],
index 1f09b4e667605996ed143255d4cee723551fbb67..95211c596a08a28fc9eb5388c1ff3eb45eeb109d 100644 (file)
@@ -47,14 +47,16 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do
     follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address
 
     if Enum.member?(recipients, "https://www.w3.org/ns/activitystreams#Public") do
-      recipients
-      |> List.delete("https://www.w3.org/ns/activitystreams#Public")
-      |> List.delete(follower_collection)
+      recipients =
+        recipients
+        |> List.delete("https://www.w3.org/ns/activitystreams#Public")
+        |> List.delete(follower_collection)
 
       {:public, length(recipients)}
     else
-      recipients
-      |> List.delete(follower_collection)
+      recipients =
+        recipients
+        |> List.delete(follower_collection)
 
       {:not_public, length(recipients)}
     end
diff --git a/test/web/activity_pub/mrf/hellthread_policy_test.exs b/test/web/activity_pub/mrf/hellthread_policy_test.exs
new file mode 100644 (file)
index 0000000..b5bdd35
--- /dev/null
@@ -0,0 +1,50 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
+  use Pleroma.DataCase
+  import Pleroma.Factory
+
+  import Pleroma.Web.ActivityPub.MRF.HellthreadPolicy
+
+  describe "hellthread filter tests" do
+    setup do
+      user = insert(:user)
+
+      message = %{
+        "actor" => user.ap_id,
+        "cc" => [user.follower_address],
+        "type" => "Create",
+        "to" => [
+          "https://www.w3.org/ns/activitystreams#Public",
+          "https://instace.tld/users/user1",
+          "https://instace.tld/users/user2",
+          "https://instace.tld/users/user3"
+        ]
+      }
+
+      [user: user, message: message]
+    end
+
+    test "reject test", %{message: message} do
+      Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2})
+
+      {:reject, nil} = filter(message)
+    end
+
+    test "delist test", %{user: user, message: message} do
+      Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
+
+      {:ok, message} = filter(message)
+      assert user.follower_address in message["to"]
+      assert "https://www.w3.org/ns/activitystreams#Public" in message["cc"]
+    end
+
+    test "threshold test", %{message: message} do
+      Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
+
+      {:ok, _} = filter(message)
+    end
+  end
+end