1 # Pleroma: A lightweight social networking server
2 # Copyright © 2019 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.info.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.info.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, info: %{note_count: 1})
64 assert user.info.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, info: %{note_count: 1})
76 assert user.info.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, info: %{follower_count: 1})
90 assert user.info.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, info: %{follower_count: 1})
102 assert user.info.follower_count == 1
106 |> Map.put("actor", user.ap_id)
108 {:ok, _message} = AntiLinkSpamPolicy.filter(message)
112 describe "with unknown actors" do
113 test "it rejects posts without links" do
116 |> Map.put("actor", "http://invalid.actor")
118 assert capture_log(fn ->
119 {:reject, _} = AntiLinkSpamPolicy.filter(message)
120 end) =~ "[error] Could not decode user at fetch http://invalid.actor"
123 test "it rejects posts with links" do
126 |> Map.put("actor", "http://invalid.actor")
128 assert capture_log(fn ->
129 {:reject, _} = AntiLinkSpamPolicy.filter(message)
130 end) =~ "[error] Could not decode user at fetch http://invalid.actor"
134 describe "with contentless-objects" do
135 test "it does not reject them or error out" do
136 user = insert(:user, info: %{note_count: 1})
140 |> Map.put("actor", user.ap_id)
142 {:ok, _message} = AntiLinkSpamPolicy.filter(message)