1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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
36 user = insert(:user, local: false)
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
48 user = insert(:user, local: false)
50 assert user.note_count == 0
54 |> Map.put("actor", user.ap_id)
56 {:reject, _} = AntiLinkSpamPolicy.filter(message)
59 test "it allows posts with links for local users" do
62 assert user.note_count == 0
66 |> Map.put("actor", user.ap_id)
68 {:ok, _message} = AntiLinkSpamPolicy.filter(message)
72 describe "with old user" do
73 test "it allows posts without 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)
85 test "it allows posts with links" do
86 user = insert(:user, note_count: 1)
88 assert user.note_count == 1
92 |> Map.put("actor", user.ap_id)
94 {:ok, _message} = AntiLinkSpamPolicy.filter(message)
98 describe "with followed new user" do
99 test "it allows posts without 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)
111 test "it allows posts with links" do
112 user = insert(:user, follower_count: 1)
114 assert user.follower_count == 1
118 |> Map.put("actor", user.ap_id)
120 {:ok, _message} = AntiLinkSpamPolicy.filter(message)
124 describe "with unknown actors" do
127 %{method: :get, url: "http://invalid.actor"} ->
128 %Tesla.Env{status: 500, body: ""}
134 test "it rejects posts without links" do
137 |> Map.put("actor", "http://invalid.actor")
139 assert capture_log(fn ->
140 {:reject, _} = AntiLinkSpamPolicy.filter(message)
141 end) =~ "[error] Could not decode user at fetch http://invalid.actor"
144 test "it rejects posts with links" do
147 |> Map.put("actor", "http://invalid.actor")
149 assert capture_log(fn ->
150 {:reject, _} = AntiLinkSpamPolicy.filter(message)
151 end) =~ "[error] Could not decode user at fetch http://invalid.actor"
155 describe "with contentless-objects" do
156 test "it does not reject them or error out" do
157 user = insert(:user, note_count: 1)
161 |> Map.put("actor", user.ap_id)
163 {:ok, _message} = AntiLinkSpamPolicy.filter(message)