1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
8 import ExUnit.CaptureLog
10 alias Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy
15 "content" => "hi world!"
22 "content" => "<a href='https://example.com'>hi world!</a>"
34 describe "with new user" do
35 test "it allows posts without links" do
38 assert user.note_count == 0
42 |> Map.put("actor", user.ap_id)
44 {:ok, _message} = AntiLinkSpamPolicy.filter(message)
47 test "it disallows posts with links" do
50 assert user.note_count == 0
54 |> Map.put("actor", user.ap_id)
56 {:reject, _} = AntiLinkSpamPolicy.filter(message)
60 describe "with old user" do
61 test "it allows posts without links" do
62 user = insert(:user, note_count: 1)
64 assert user.note_count == 1
68 |> Map.put("actor", user.ap_id)
70 {:ok, _message} = AntiLinkSpamPolicy.filter(message)
73 test "it allows posts with links" do
74 user = insert(:user, note_count: 1)
76 assert user.note_count == 1
80 |> Map.put("actor", user.ap_id)
82 {:ok, _message} = AntiLinkSpamPolicy.filter(message)
86 describe "with followed new user" do
87 test "it allows posts without links" do
88 user = insert(:user, follower_count: 1)
90 assert user.follower_count == 1
94 |> Map.put("actor", user.ap_id)
96 {:ok, _message} = AntiLinkSpamPolicy.filter(message)
99 test "it allows posts with links" do
100 user = insert(:user, follower_count: 1)
102 assert user.follower_count == 1
106 |> Map.put("actor", user.ap_id)
108 {:ok, _message} = AntiLinkSpamPolicy.filter(message)
112 describe "with unknown actors" do
115 %{method: :get, url: "http://invalid.actor"} ->
116 %Tesla.Env{status: 500, body: ""}
122 test "it rejects posts without links" do
125 |> Map.put("actor", "http://invalid.actor")
127 assert capture_log(fn ->
128 {:reject, _} = AntiLinkSpamPolicy.filter(message)
129 end) =~ "[error] Could not decode user at fetch http://invalid.actor"
132 test "it rejects posts with links" do
135 |> Map.put("actor", "http://invalid.actor")
137 assert capture_log(fn ->
138 {:reject, _} = AntiLinkSpamPolicy.filter(message)
139 end) =~ "[error] Could not decode user at fetch http://invalid.actor"
143 describe "with contentless-objects" do
144 test "it does not reject them or error out" do
145 user = insert(:user, note_count: 1)
149 |> Map.put("actor", user.ap_id)
151 {:ok, _message} = AntiLinkSpamPolicy.filter(message)