summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/object_test.exs28
-rw-r--r--test/user_test.exs6
-rw-r--r--test/web/activity_pub/mrf/keyword_policy_test.exs111
3 files changed, 144 insertions, 1 deletions
diff --git a/test/object_test.exs b/test/object_test.exs
index 72194975d..ab6431012 100644
--- a/test/object_test.exs
+++ b/test/object_test.exs
@@ -57,4 +57,32 @@ defmodule Pleroma.ObjectTest do
assert cached_object.data["type"] == "Tombstone"
end
end
+
+ describe "insert_or_get" do
+ test "inserting the same object twice (by id) just returns the original object" do
+ data = %{data: %{"id" => Ecto.UUID.generate()}}
+ cng = Object.change(%Object{}, data)
+ {:ok, object} = Object.insert_or_get(cng)
+ {:ok, second_object} = Object.insert_or_get(cng)
+
+ Cachex.clear(:object_cache)
+ {:ok, third_object} = Object.insert_or_get(cng)
+
+ assert object == second_object
+ assert object == third_object
+ end
+ end
+
+ describe "create" do
+ test "inserts an object for a given data set" do
+ data = %{"id" => Ecto.UUID.generate()}
+
+ {:ok, object} = Object.create(data)
+ assert object.data["id"] == data["id"]
+
+ # Works when doing it twice.
+ {:ok, object} = Object.create(data)
+ assert object.data["id"] == data["id"]
+ end
+ end
end
diff --git a/test/user_test.exs b/test/user_test.exs
index 98d3bc464..523ab1ea4 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -53,16 +53,20 @@ defmodule Pleroma.UserTest do
followed_zero = insert(:user)
followed_one = insert(:user)
followed_two = insert(:user)
+ blocked = insert(:user)
not_followed = insert(:user)
+ {:ok, user} = User.block(user, blocked)
+
{:ok, user} = User.follow(user, followed_zero)
- {:ok, user} = User.follow_all(user, [followed_one, followed_two])
+ {:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked])
assert User.following?(user, followed_one)
assert User.following?(user, followed_two)
assert User.following?(user, followed_zero)
refute User.following?(user, not_followed)
+ refute User.following?(user, blocked)
end
test "follow_all follows mutliple users without duplicating" do
diff --git a/test/web/activity_pub/mrf/keyword_policy_test.exs b/test/web/activity_pub/mrf/keyword_policy_test.exs
new file mode 100644
index 000000000..67a5858d7
--- /dev/null
+++ b/test/web/activity_pub/mrf/keyword_policy_test.exs
@@ -0,0 +1,111 @@
+# 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.KeywordPolicyTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.ActivityPub.MRF.KeywordPolicy
+
+ setup do
+ Pleroma.Config.put([:mrf_keyword], %{reject: [], federated_timeline_removal: [], replace: []})
+ end
+
+ describe "rejecting based on keywords" do
+ test "rejects if string matches" do
+ Pleroma.Config.put([:mrf_keyword, :reject], ["pun"])
+
+ message = %{
+ "type" => "Create",
+ "object" => %{"content" => "just a daily reminder that compLAINer is a good pun"}
+ }
+
+ assert {:reject, nil} == KeywordPolicy.filter(message)
+ end
+
+ test "rejects if regex matches" do
+ Pleroma.Config.put([:mrf_keyword, :reject], [~r/comp[lL][aA][iI][nN]er/])
+
+ assert true ==
+ Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content ->
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "content" => "just a daily reminder that #{content} is a good pun"
+ }
+ }
+
+ {:reject, nil} == KeywordPolicy.filter(message)
+ end)
+ end
+ end
+
+ describe "delisting from ftl based on keywords" do
+ test "delists if string matches" do
+ Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], ["pun"])
+
+ message = %{
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "type" => "Create",
+ "object" => %{"content" => "just a daily reminder that compLAINer is a good pun"}
+ }
+
+ {:ok, result} = KeywordPolicy.filter(message)
+ assert ["https://www.w3.org/ns/activitystreams#Public"] == result["cc"]
+ refute ["https://www.w3.org/ns/activitystreams#Public"] == result["to"]
+ end
+
+ test "delists if regex matches" do
+ Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], [~r/comp[lL][aA][iI][nN]er/])
+
+ assert true ==
+ Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content ->
+ message = %{
+ "type" => "Create",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "object" => %{
+ "content" => "just a daily reminder that #{content} is a good pun"
+ }
+ }
+
+ {:ok, result} = KeywordPolicy.filter(message)
+
+ ["https://www.w3.org/ns/activitystreams#Public"] == result["cc"] and
+ not (["https://www.w3.org/ns/activitystreams#Public"] == result["to"])
+ end)
+ end
+ end
+
+ describe "replacing keywords" do
+ test "replaces keyword if string matches" do
+ Pleroma.Config.put([:mrf_keyword, :replace], [{"opensource", "free software"}])
+
+ message = %{
+ "type" => "Create",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "object" => %{"content" => "ZFS is opensource"}
+ }
+
+ {:ok, %{"object" => %{"content" => result}}} = KeywordPolicy.filter(message)
+ assert result == "ZFS is free software"
+ end
+
+ test "replaces keyword if regex matches" do
+ Pleroma.Config.put([:mrf_keyword, :replace], [
+ {~r/open(-|\s)?source\s?(software)?/, "free software"}
+ ])
+
+ assert true ==
+ Enum.all?(["opensource", "open-source", "open source"], fn content ->
+ message = %{
+ "type" => "Create",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "object" => %{"content" => "ZFS is #{content}"}
+ }
+
+ {:ok, %{"object" => %{"content" => result}}} = KeywordPolicy.filter(message)
+ result == "ZFS is free software"
+ end)
+ end
+ end
+end