From 74518d0b607695a80e25f17de8369f47c7652b17 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 6 Feb 2019 22:34:44 +0000 Subject: hide_followings was renamed to hide_followers in the FE, but never synced up in the BE This was a dirty regex replace which worked on my server --- test/web/activity_pub/activity_pub_controller_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/web/activity_pub') diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 0a0103793..570bee6b3 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -441,8 +441,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do assert result["first"]["orderedItems"] == [user_two.ap_id] end - test "it returns returns empty if the user has 'hide_followings' set", %{conn: conn} do - user = insert(:user, %{info: %{hide_followings: true}}) + test "it returns returns empty if the user has 'hide_follows' set", %{conn: conn} do + user = insert(:user, %{info: %{hide_follows: true}}) user_two = insert(:user) User.follow(user, user_two) -- cgit v1.2.3 From 9a23f8f3ea9e788978055f0ad3a10db105f68cc6 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 8 Feb 2019 20:23:26 +0300 Subject: Add tests and fix a typo in docs --- test/web/activity_pub/mrf/keyword_policy_test.exs | 113 ++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 test/web/activity_pub/mrf/keyword_policy_test.exs (limited to 'test/web/activity_pub') 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..77e2a08c9 --- /dev/null +++ b/test/web/activity_pub/mrf/keyword_policy_test.exs @@ -0,0 +1,113 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2019 Pleroma Authors +# 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) + IO.inspect(content) + IO.inspect(result) + result == "ZFS is free software" + end) + end + end +end -- cgit v1.2.3 From b05a3411871fbfb8d1a5525d6875a635917abffa Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 9 Feb 2019 08:12:30 +0300 Subject: oof --- test/web/activity_pub/mrf/keyword_policy_test.exs | 2 -- 1 file changed, 2 deletions(-) (limited to 'test/web/activity_pub') diff --git a/test/web/activity_pub/mrf/keyword_policy_test.exs b/test/web/activity_pub/mrf/keyword_policy_test.exs index 77e2a08c9..67a5858d7 100644 --- a/test/web/activity_pub/mrf/keyword_policy_test.exs +++ b/test/web/activity_pub/mrf/keyword_policy_test.exs @@ -104,8 +104,6 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do } {:ok, %{"object" => %{"content" => result}}} = KeywordPolicy.filter(message) - IO.inspect(content) - IO.inspect(result) result == "ZFS is free software" end) end -- cgit v1.2.3