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.RejectNonPublicTest do
9 alias Pleroma.Web.ActivityPub.MRF.RejectNonPublic
12 policy = Pleroma.Config.get([:mrf_rejectnonpublic])
13 on_exit(fn -> Pleroma.Config.put([:mrf_rejectnonpublic], policy) end)
18 describe "public message" do
19 test "it's allowed when address is public" do
20 actor = insert(:user, follower_address: "test-address")
23 "actor" => actor.ap_id,
24 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
25 "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
29 assert {:ok, message} = RejectNonPublic.filter(message)
32 test "it's allowed when cc address contain public address" do
33 actor = insert(:user, follower_address: "test-address")
36 "actor" => actor.ap_id,
37 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
38 "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
42 assert {:ok, message} = RejectNonPublic.filter(message)
46 describe "followers message" do
47 test "it's allowed when addrer of message in the follower addresses of user and it enabled in config" do
48 actor = insert(:user, follower_address: "test-address")
51 "actor" => actor.ap_id,
52 "to" => ["test-address"],
53 "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
57 Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], true)
58 assert {:ok, message} = RejectNonPublic.filter(message)
61 test "it's rejected when addrer of message in the follower addresses of user and it disabled in config" do
62 actor = insert(:user, follower_address: "test-address")
65 "actor" => actor.ap_id,
66 "to" => ["test-address"],
67 "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
71 Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], false)
72 assert {:reject, nil} = RejectNonPublic.filter(message)
76 describe "direct message" do
77 test "it's allows when direct messages are allow" do
81 "actor" => actor.ap_id,
82 "to" => ["https://www.w3.org/ns/activitystreams#Publid"],
83 "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
87 Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], true)
88 assert {:ok, message} = RejectNonPublic.filter(message)
91 test "it's reject when direct messages aren't allow" do
95 "actor" => actor.ap_id,
96 "to" => ["https://www.w3.org/ns/activitystreams#Publid~~~"],
97 "cc" => ["https://www.w3.org/ns/activitystreams#Publid"],
101 Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], false)
102 assert {:reject, nil} = RejectNonPublic.filter(message)