Merge branch 'develop' into 'fix/2412-filters'
# Conflicts: # CHANGELOG.md
This commit is contained in:
commit
008499f65a
245 changed files with 1917 additions and 905 deletions
|
|
@ -7,7 +7,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Delivery
|
||||
alias Pleroma.Instances
|
||||
alias Pleroma.Object
|
||||
|
|
@ -46,7 +45,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
end
|
||||
|
||||
test "with the relay disabled, it returns 404", %{conn: conn} do
|
||||
Config.put([:instance, :allow_relay], false)
|
||||
clear_config([:instance, :allow_relay], false)
|
||||
|
||||
conn
|
||||
|> get(activity_pub_path(conn, :relay))
|
||||
|
|
@ -54,7 +53,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
end
|
||||
|
||||
test "on non-federating instance, it returns 404", %{conn: conn} do
|
||||
Config.put([:instance, :federating], false)
|
||||
clear_config([:instance, :federating], false)
|
||||
user = insert(:user)
|
||||
|
||||
conn
|
||||
|
|
@ -75,7 +74,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
end
|
||||
|
||||
test "on non-federating instance, it returns 404", %{conn: conn} do
|
||||
Config.put([:instance, :federating], false)
|
||||
clear_config([:instance, :federating], false)
|
||||
user = insert(:user)
|
||||
|
||||
conn
|
||||
|
|
@ -493,7 +492,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
end
|
||||
|
||||
test "accept follow activity", %{conn: conn} do
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
clear_config([:instance, :federating], true)
|
||||
relay = Relay.get_actor()
|
||||
|
||||
assert {:ok, %Activity{} = activity} = Relay.follow("https://relay.mastodon.host/actor")
|
||||
|
|
@ -539,7 +538,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
conn = put_req_header(conn, "content-type", "application/activity+json")
|
||||
|
||||
Config.put([:instance, :federating], false)
|
||||
clear_config([:instance, :federating], false)
|
||||
|
||||
conn
|
||||
|> post("/inbox", data)
|
||||
|
|
@ -549,7 +548,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|> post("/inbox", non_create_data)
|
||||
|> json_response(403)
|
||||
|
||||
Config.put([:instance, :federating], true)
|
||||
clear_config([:instance, :federating], true)
|
||||
|
||||
ret_conn = post(conn, "/inbox", data)
|
||||
assert "ok" == json_response(ret_conn, 200)
|
||||
|
|
@ -1246,7 +1245,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
end
|
||||
|
||||
test "Character limitation", %{conn: conn, activity: activity} do
|
||||
Pleroma.Config.put([:instance, :limit], 5)
|
||||
clear_config([:instance, :limit], 5)
|
||||
user = insert(:user)
|
||||
|
||||
result =
|
||||
|
|
@ -1275,7 +1274,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
end
|
||||
|
||||
test "on non-federating instance, it returns 404", %{conn: conn} do
|
||||
Config.put([:instance, :federating], false)
|
||||
clear_config([:instance, :federating], false)
|
||||
user = insert(:user)
|
||||
|
||||
conn
|
||||
|
|
@ -1296,7 +1295,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
end
|
||||
|
||||
test "on non-federating instance, it returns 404", %{conn: conn} do
|
||||
Config.put([:instance, :federating], false)
|
||||
clear_config([:instance, :federating], false)
|
||||
user = insert(:user)
|
||||
|
||||
conn
|
||||
|
|
@ -1608,9 +1607,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
desc = "Description of the image"
|
||||
|
||||
image = %Plug.Upload{
|
||||
content_type: "bad/content-type",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.png"
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
object =
|
||||
|
|
|
|||
|
|
@ -1079,15 +1079,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
test "it sets the default description depending on the configuration", %{test_file: file} do
|
||||
clear_config([Pleroma.Upload, :default_description])
|
||||
|
||||
Pleroma.Config.put([Pleroma.Upload, :default_description], nil)
|
||||
clear_config([Pleroma.Upload, :default_description], nil)
|
||||
{:ok, %Object{} = object} = ActivityPub.upload(file)
|
||||
assert object.data["name"] == ""
|
||||
|
||||
Pleroma.Config.put([Pleroma.Upload, :default_description], :filename)
|
||||
clear_config([Pleroma.Upload, :default_description], :filename)
|
||||
{:ok, %Object{} = object} = ActivityPub.upload(file)
|
||||
assert object.data["name"] == "an_image.jpg"
|
||||
|
||||
Pleroma.Config.put([Pleroma.Upload, :default_description], "unnamed attachment")
|
||||
clear_config([Pleroma.Upload, :default_description], "unnamed attachment")
|
||||
{:ok, %Object{} = object} = ActivityPub.upload(file)
|
||||
assert object.data["name"] == "unnamed attachment"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
|
|||
setup do: clear_config(:mrf_hellthread)
|
||||
|
||||
test "doesn't die on chat messages" do
|
||||
Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
|
||||
clear_config([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
|
||||
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
|
@ -48,7 +48,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
|
|||
test "rejects the message if the recipient count is above reject_threshold", %{
|
||||
message: message
|
||||
} do
|
||||
Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2})
|
||||
clear_config([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2})
|
||||
|
||||
assert {:reject, "[HellthreadPolicy] 3 recipients is over the limit of 2"} ==
|
||||
filter(message)
|
||||
|
|
@ -57,7 +57,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
|
|||
test "does not reject the message if the recipient count is below reject_threshold", %{
|
||||
message: message
|
||||
} do
|
||||
Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
|
||||
clear_config([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
|
||||
|
||||
assert {:ok, ^message} = filter(message)
|
||||
end
|
||||
|
|
@ -68,7 +68,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
|
|||
user: user,
|
||||
message: message
|
||||
} do
|
||||
Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
|
||||
clear_config([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
|
||||
|
||||
{:ok, message} = filter(message)
|
||||
assert user.follower_address in message["to"]
|
||||
|
|
@ -78,14 +78,14 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
|
|||
test "does not delist the message if the recipient count is below delist_threshold", %{
|
||||
message: message
|
||||
} do
|
||||
Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 4, reject_threshold: 0})
|
||||
clear_config([:mrf_hellthread], %{delist_threshold: 4, reject_threshold: 0})
|
||||
|
||||
assert {:ok, ^message} = filter(message)
|
||||
end
|
||||
end
|
||||
|
||||
test "excludes follower collection and public URI from threshold count", %{message: message} do
|
||||
Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
|
||||
clear_config([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
|
||||
|
||||
assert {:ok, ^message} = filter(message)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
|
|||
setup do: clear_config(:mrf_keyword)
|
||||
|
||||
setup do
|
||||
Pleroma.Config.put([:mrf_keyword], %{reject: [], federated_timeline_removal: [], replace: []})
|
||||
clear_config([:mrf_keyword], %{reject: [], federated_timeline_removal: [], replace: []})
|
||||
end
|
||||
|
||||
describe "rejecting based on keywords" do
|
||||
test "rejects if string matches in content" do
|
||||
Pleroma.Config.put([:mrf_keyword, :reject], ["pun"])
|
||||
clear_config([:mrf_keyword, :reject], ["pun"])
|
||||
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
|
|
@ -30,7 +30,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
|
|||
end
|
||||
|
||||
test "rejects if string matches in summary" do
|
||||
Pleroma.Config.put([:mrf_keyword, :reject], ["pun"])
|
||||
clear_config([:mrf_keyword, :reject], ["pun"])
|
||||
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
|
|
@ -45,7 +45,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
|
|||
end
|
||||
|
||||
test "rejects if regex matches in content" do
|
||||
Pleroma.Config.put([:mrf_keyword, :reject], [~r/comp[lL][aA][iI][nN]er/])
|
||||
clear_config([:mrf_keyword, :reject], [~r/comp[lL][aA][iI][nN]er/])
|
||||
|
||||
assert true ==
|
||||
Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content ->
|
||||
|
|
@ -63,7 +63,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
|
|||
end
|
||||
|
||||
test "rejects if regex matches in summary" do
|
||||
Pleroma.Config.put([:mrf_keyword, :reject], [~r/comp[lL][aA][iI][nN]er/])
|
||||
clear_config([:mrf_keyword, :reject], [~r/comp[lL][aA][iI][nN]er/])
|
||||
|
||||
assert true ==
|
||||
Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content ->
|
||||
|
|
@ -83,7 +83,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
|
|||
|
||||
describe "delisting from ftl based on keywords" do
|
||||
test "delists if string matches in content" do
|
||||
Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], ["pun"])
|
||||
clear_config([:mrf_keyword, :federated_timeline_removal], ["pun"])
|
||||
|
||||
message = %{
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
|
|
@ -100,7 +100,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
|
|||
end
|
||||
|
||||
test "delists if string matches in summary" do
|
||||
Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], ["pun"])
|
||||
clear_config([:mrf_keyword, :federated_timeline_removal], ["pun"])
|
||||
|
||||
message = %{
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
|
|
@ -117,7 +117,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
|
|||
end
|
||||
|
||||
test "delists if regex matches in content" do
|
||||
Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], [~r/comp[lL][aA][iI][nN]er/])
|
||||
clear_config([:mrf_keyword, :federated_timeline_removal], [~r/comp[lL][aA][iI][nN]er/])
|
||||
|
||||
assert true ==
|
||||
Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content ->
|
||||
|
|
@ -138,7 +138,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
|
|||
end
|
||||
|
||||
test "delists if regex matches in summary" do
|
||||
Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], [~r/comp[lL][aA][iI][nN]er/])
|
||||
clear_config([:mrf_keyword, :federated_timeline_removal], [~r/comp[lL][aA][iI][nN]er/])
|
||||
|
||||
assert true ==
|
||||
Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content ->
|
||||
|
|
@ -161,7 +161,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
|
|||
|
||||
describe "replacing keywords" do
|
||||
test "replaces keyword if string matches in content" do
|
||||
Pleroma.Config.put([:mrf_keyword, :replace], [{"opensource", "free software"}])
|
||||
clear_config([:mrf_keyword, :replace], [{"opensource", "free software"}])
|
||||
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
|
|
@ -174,7 +174,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
|
|||
end
|
||||
|
||||
test "replaces keyword if string matches in summary" do
|
||||
Pleroma.Config.put([:mrf_keyword, :replace], [{"opensource", "free software"}])
|
||||
clear_config([:mrf_keyword, :replace], [{"opensource", "free software"}])
|
||||
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
|
|
@ -187,7 +187,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
|
|||
end
|
||||
|
||||
test "replaces keyword if regex matches in content" do
|
||||
Pleroma.Config.put([:mrf_keyword, :replace], [
|
||||
clear_config([:mrf_keyword, :replace], [
|
||||
{~r/open(-|\s)?source\s?(software)?/, "free software"}
|
||||
])
|
||||
|
||||
|
|
@ -205,7 +205,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
|
|||
end
|
||||
|
||||
test "replaces keyword if regex matches in summary" do
|
||||
Pleroma.Config.put([:mrf_keyword, :replace], [
|
||||
clear_config([:mrf_keyword, :replace], [
|
||||
{~r/open(-|\s)?source\s?(software)?/, "free software"}
|
||||
])
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicyTest do
|
|||
|
||||
describe "allow" do
|
||||
test "empty" do
|
||||
Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
|
||||
clear_config([:mrf_mention], %{actors: ["https://example.com/blocked"]})
|
||||
|
||||
message = %{
|
||||
"type" => "Create"
|
||||
|
|
@ -33,7 +33,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicyTest do
|
|||
end
|
||||
|
||||
test "to" do
|
||||
Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
|
||||
clear_config([:mrf_mention], %{actors: ["https://example.com/blocked"]})
|
||||
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
|
|
@ -44,7 +44,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicyTest do
|
|||
end
|
||||
|
||||
test "cc" do
|
||||
Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
|
||||
clear_config([:mrf_mention], %{actors: ["https://example.com/blocked"]})
|
||||
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
|
|
@ -55,7 +55,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicyTest do
|
|||
end
|
||||
|
||||
test "both" do
|
||||
Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
|
||||
clear_config([:mrf_mention], %{actors: ["https://example.com/blocked"]})
|
||||
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
|
|
@ -69,7 +69,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicyTest do
|
|||
|
||||
describe "deny" do
|
||||
test "to" do
|
||||
Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
|
||||
clear_config([:mrf_mention], %{actors: ["https://example.com/blocked"]})
|
||||
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
|
|
@ -81,7 +81,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicyTest do
|
|||
end
|
||||
|
||||
test "cc" do
|
||||
Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
|
||||
clear_config([:mrf_mention], %{actors: ["https://example.com/blocked"]})
|
||||
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy
|
||||
alias Pleroma.Web.ActivityPub.Visibility
|
||||
|
|
@ -39,7 +38,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||
|
||||
describe "with reject action" do
|
||||
test "works with objects with empty to or cc fields" do
|
||||
Config.put([:mrf_object_age, :actions], [:reject])
|
||||
clear_config([:mrf_object_age, :actions], [:reject])
|
||||
|
||||
data =
|
||||
get_old_message()
|
||||
|
|
@ -50,7 +49,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||
end
|
||||
|
||||
test "it rejects an old post" do
|
||||
Config.put([:mrf_object_age, :actions], [:reject])
|
||||
clear_config([:mrf_object_age, :actions], [:reject])
|
||||
|
||||
data = get_old_message()
|
||||
|
||||
|
|
@ -58,7 +57,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||
end
|
||||
|
||||
test "it allows a new post" do
|
||||
Config.put([:mrf_object_age, :actions], [:reject])
|
||||
clear_config([:mrf_object_age, :actions], [:reject])
|
||||
|
||||
data = get_new_message()
|
||||
|
||||
|
|
@ -68,7 +67,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||
|
||||
describe "with delist action" do
|
||||
test "works with objects with empty to or cc fields" do
|
||||
Config.put([:mrf_object_age, :actions], [:delist])
|
||||
clear_config([:mrf_object_age, :actions], [:delist])
|
||||
|
||||
data =
|
||||
get_old_message()
|
||||
|
|
@ -83,7 +82,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||
end
|
||||
|
||||
test "it delists an old post" do
|
||||
Config.put([:mrf_object_age, :actions], [:delist])
|
||||
clear_config([:mrf_object_age, :actions], [:delist])
|
||||
|
||||
data = get_old_message()
|
||||
|
||||
|
|
@ -95,7 +94,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||
end
|
||||
|
||||
test "it allows a new post" do
|
||||
Config.put([:mrf_object_age, :actions], [:delist])
|
||||
clear_config([:mrf_object_age, :actions], [:delist])
|
||||
|
||||
data = get_new_message()
|
||||
|
||||
|
|
@ -107,7 +106,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||
|
||||
describe "with strip_followers action" do
|
||||
test "works with objects with empty to or cc fields" do
|
||||
Config.put([:mrf_object_age, :actions], [:strip_followers])
|
||||
clear_config([:mrf_object_age, :actions], [:strip_followers])
|
||||
|
||||
data =
|
||||
get_old_message()
|
||||
|
|
@ -123,7 +122,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||
end
|
||||
|
||||
test "it strips followers collections from an old post" do
|
||||
Config.put([:mrf_object_age, :actions], [:strip_followers])
|
||||
clear_config([:mrf_object_age, :actions], [:strip_followers])
|
||||
|
||||
data = get_old_message()
|
||||
|
||||
|
|
@ -136,7 +135,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||
end
|
||||
|
||||
test "it allows a new post" do
|
||||
Config.put([:mrf_object_age, :actions], [:strip_followers])
|
||||
clear_config([:mrf_object_age, :actions], [:strip_followers])
|
||||
|
||||
data = get_new_message()
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
|
|||
"type" => "Create"
|
||||
}
|
||||
|
||||
Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], true)
|
||||
clear_config([:mrf_rejectnonpublic, :allow_followersonly], true)
|
||||
assert {:ok, _message} = RejectNonPublic.filter(message)
|
||||
end
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
|
|||
"type" => "Create"
|
||||
}
|
||||
|
||||
Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], false)
|
||||
clear_config([:mrf_rejectnonpublic, :allow_followersonly], false)
|
||||
assert {:reject, _} = RejectNonPublic.filter(message)
|
||||
end
|
||||
end
|
||||
|
|
@ -79,7 +79,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
|
|||
"type" => "Create"
|
||||
}
|
||||
|
||||
Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], true)
|
||||
clear_config([:mrf_rejectnonpublic, :allow_direct], true)
|
||||
assert {:ok, _message} = RejectNonPublic.filter(message)
|
||||
end
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
|
|||
"type" => "Create"
|
||||
}
|
||||
|
||||
Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], false)
|
||||
clear_config([:mrf_rejectnonpublic, :allow_direct], false)
|
||||
assert {:reject, _} = RejectNonPublic.filter(message)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Web.ActivityPub.MRF.SimplePolicy
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
|
|
@ -25,7 +24,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|
||||
describe "when :media_removal" do
|
||||
test "is empty" do
|
||||
Config.put([:mrf_simple, :media_removal], [])
|
||||
clear_config([:mrf_simple, :media_removal], [])
|
||||
media_message = build_media_message()
|
||||
local_message = build_local_message()
|
||||
|
||||
|
|
@ -34,7 +33,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "has a matching host" do
|
||||
Config.put([:mrf_simple, :media_removal], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :media_removal], ["remote.instance"])
|
||||
media_message = build_media_message()
|
||||
local_message = build_local_message()
|
||||
|
||||
|
|
@ -47,7 +46,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "match with wildcard domain" do
|
||||
Config.put([:mrf_simple, :media_removal], ["*.remote.instance"])
|
||||
clear_config([:mrf_simple, :media_removal], ["*.remote.instance"])
|
||||
media_message = build_media_message()
|
||||
local_message = build_local_message()
|
||||
|
||||
|
|
@ -62,7 +61,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|
||||
describe "when :media_nsfw" do
|
||||
test "is empty" do
|
||||
Config.put([:mrf_simple, :media_nsfw], [])
|
||||
clear_config([:mrf_simple, :media_nsfw], [])
|
||||
media_message = build_media_message()
|
||||
local_message = build_local_message()
|
||||
|
||||
|
|
@ -71,7 +70,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "has a matching host" do
|
||||
Config.put([:mrf_simple, :media_nsfw], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :media_nsfw], ["remote.instance"])
|
||||
media_message = build_media_message()
|
||||
local_message = build_local_message()
|
||||
|
||||
|
|
@ -85,7 +84,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "match with wildcard domain" do
|
||||
Config.put([:mrf_simple, :media_nsfw], ["*.remote.instance"])
|
||||
clear_config([:mrf_simple, :media_nsfw], ["*.remote.instance"])
|
||||
media_message = build_media_message()
|
||||
local_message = build_local_message()
|
||||
|
||||
|
|
@ -113,7 +112,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|
||||
describe "when :report_removal" do
|
||||
test "is empty" do
|
||||
Config.put([:mrf_simple, :report_removal], [])
|
||||
clear_config([:mrf_simple, :report_removal], [])
|
||||
report_message = build_report_message()
|
||||
local_message = build_local_message()
|
||||
|
||||
|
|
@ -122,7 +121,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "has a matching host" do
|
||||
Config.put([:mrf_simple, :report_removal], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :report_removal], ["remote.instance"])
|
||||
report_message = build_report_message()
|
||||
local_message = build_local_message()
|
||||
|
||||
|
|
@ -131,7 +130,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "match with wildcard domain" do
|
||||
Config.put([:mrf_simple, :report_removal], ["*.remote.instance"])
|
||||
clear_config([:mrf_simple, :report_removal], ["*.remote.instance"])
|
||||
report_message = build_report_message()
|
||||
local_message = build_local_message()
|
||||
|
||||
|
|
@ -149,7 +148,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|
||||
describe "when :federated_timeline_removal" do
|
||||
test "is empty" do
|
||||
Config.put([:mrf_simple, :federated_timeline_removal], [])
|
||||
clear_config([:mrf_simple, :federated_timeline_removal], [])
|
||||
{_, ftl_message} = build_ftl_actor_and_message()
|
||||
local_message = build_local_message()
|
||||
|
||||
|
|
@ -166,7 +165,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|> URI.parse()
|
||||
|> Map.fetch!(:host)
|
||||
|
||||
Config.put([:mrf_simple, :federated_timeline_removal], [ftl_message_actor_host])
|
||||
clear_config([:mrf_simple, :federated_timeline_removal], [ftl_message_actor_host])
|
||||
local_message = build_local_message()
|
||||
|
||||
assert {:ok, ftl_message} = SimplePolicy.filter(ftl_message)
|
||||
|
|
@ -187,7 +186,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|> URI.parse()
|
||||
|> Map.fetch!(:host)
|
||||
|
||||
Config.put([:mrf_simple, :federated_timeline_removal], ["*." <> ftl_message_actor_host])
|
||||
clear_config([:mrf_simple, :federated_timeline_removal], ["*." <> ftl_message_actor_host])
|
||||
local_message = build_local_message()
|
||||
|
||||
assert {:ok, ftl_message} = SimplePolicy.filter(ftl_message)
|
||||
|
|
@ -210,7 +209,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|
||||
ftl_message = Map.put(ftl_message, "cc", [])
|
||||
|
||||
Config.put([:mrf_simple, :federated_timeline_removal], [ftl_message_actor_host])
|
||||
clear_config([:mrf_simple, :federated_timeline_removal], [ftl_message_actor_host])
|
||||
|
||||
assert {:ok, ftl_message} = SimplePolicy.filter(ftl_message)
|
||||
refute "https://www.w3.org/ns/activitystreams#Public" in ftl_message["to"]
|
||||
|
|
@ -231,7 +230,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|
||||
describe "when :reject" do
|
||||
test "is empty" do
|
||||
Config.put([:mrf_simple, :reject], [])
|
||||
clear_config([:mrf_simple, :reject], [])
|
||||
|
||||
remote_message = build_remote_message()
|
||||
|
||||
|
|
@ -239,7 +238,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "activity has a matching host" do
|
||||
Config.put([:mrf_simple, :reject], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :reject], ["remote.instance"])
|
||||
|
||||
remote_message = build_remote_message()
|
||||
|
||||
|
|
@ -247,7 +246,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "activity matches with wildcard domain" do
|
||||
Config.put([:mrf_simple, :reject], ["*.remote.instance"])
|
||||
clear_config([:mrf_simple, :reject], ["*.remote.instance"])
|
||||
|
||||
remote_message = build_remote_message()
|
||||
|
||||
|
|
@ -255,7 +254,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "actor has a matching host" do
|
||||
Config.put([:mrf_simple, :reject], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :reject], ["remote.instance"])
|
||||
|
||||
remote_user = build_remote_user()
|
||||
|
||||
|
|
@ -265,7 +264,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|
||||
describe "when :followers_only" do
|
||||
test "is empty" do
|
||||
Config.put([:mrf_simple, :followers_only], [])
|
||||
clear_config([:mrf_simple, :followers_only], [])
|
||||
{_, ftl_message} = build_ftl_actor_and_message()
|
||||
local_message = build_local_message()
|
||||
|
||||
|
|
@ -305,7 +304,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|> URI.parse()
|
||||
|> Map.fetch!(:host)
|
||||
|
||||
Config.put([:mrf_simple, :followers_only], [actor_domain])
|
||||
clear_config([:mrf_simple, :followers_only], [actor_domain])
|
||||
|
||||
assert {:ok, new_activity} = SimplePolicy.filter(activity)
|
||||
assert actor.follower_address in new_activity["cc"]
|
||||
|
|
@ -323,7 +322,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|
||||
describe "when :accept" do
|
||||
test "is empty" do
|
||||
Config.put([:mrf_simple, :accept], [])
|
||||
clear_config([:mrf_simple, :accept], [])
|
||||
|
||||
local_message = build_local_message()
|
||||
remote_message = build_remote_message()
|
||||
|
|
@ -333,7 +332,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "is not empty but activity doesn't have a matching host" do
|
||||
Config.put([:mrf_simple, :accept], ["non.matching.remote"])
|
||||
clear_config([:mrf_simple, :accept], ["non.matching.remote"])
|
||||
|
||||
local_message = build_local_message()
|
||||
remote_message = build_remote_message()
|
||||
|
|
@ -343,7 +342,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "activity has a matching host" do
|
||||
Config.put([:mrf_simple, :accept], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :accept], ["remote.instance"])
|
||||
|
||||
local_message = build_local_message()
|
||||
remote_message = build_remote_message()
|
||||
|
|
@ -353,7 +352,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "activity matches with wildcard domain" do
|
||||
Config.put([:mrf_simple, :accept], ["*.remote.instance"])
|
||||
clear_config([:mrf_simple, :accept], ["*.remote.instance"])
|
||||
|
||||
local_message = build_local_message()
|
||||
remote_message = build_remote_message()
|
||||
|
|
@ -363,7 +362,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "actor has a matching host" do
|
||||
Config.put([:mrf_simple, :accept], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :accept], ["remote.instance"])
|
||||
|
||||
remote_user = build_remote_user()
|
||||
|
||||
|
|
@ -373,7 +372,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|
||||
describe "when :avatar_removal" do
|
||||
test "is empty" do
|
||||
Config.put([:mrf_simple, :avatar_removal], [])
|
||||
clear_config([:mrf_simple, :avatar_removal], [])
|
||||
|
||||
remote_user = build_remote_user()
|
||||
|
||||
|
|
@ -381,7 +380,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "is not empty but it doesn't have a matching host" do
|
||||
Config.put([:mrf_simple, :avatar_removal], ["non.matching.remote"])
|
||||
clear_config([:mrf_simple, :avatar_removal], ["non.matching.remote"])
|
||||
|
||||
remote_user = build_remote_user()
|
||||
|
||||
|
|
@ -389,7 +388,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "has a matching host" do
|
||||
Config.put([:mrf_simple, :avatar_removal], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :avatar_removal], ["remote.instance"])
|
||||
|
||||
remote_user = build_remote_user()
|
||||
{:ok, filtered} = SimplePolicy.filter(remote_user)
|
||||
|
|
@ -398,7 +397,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "match with wildcard domain" do
|
||||
Config.put([:mrf_simple, :avatar_removal], ["*.remote.instance"])
|
||||
clear_config([:mrf_simple, :avatar_removal], ["*.remote.instance"])
|
||||
|
||||
remote_user = build_remote_user()
|
||||
{:ok, filtered} = SimplePolicy.filter(remote_user)
|
||||
|
|
@ -409,7 +408,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|
||||
describe "when :banner_removal" do
|
||||
test "is empty" do
|
||||
Config.put([:mrf_simple, :banner_removal], [])
|
||||
clear_config([:mrf_simple, :banner_removal], [])
|
||||
|
||||
remote_user = build_remote_user()
|
||||
|
||||
|
|
@ -417,7 +416,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "is not empty but it doesn't have a matching host" do
|
||||
Config.put([:mrf_simple, :banner_removal], ["non.matching.remote"])
|
||||
clear_config([:mrf_simple, :banner_removal], ["non.matching.remote"])
|
||||
|
||||
remote_user = build_remote_user()
|
||||
|
||||
|
|
@ -425,7 +424,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "has a matching host" do
|
||||
Config.put([:mrf_simple, :banner_removal], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :banner_removal], ["remote.instance"])
|
||||
|
||||
remote_user = build_remote_user()
|
||||
{:ok, filtered} = SimplePolicy.filter(remote_user)
|
||||
|
|
@ -434,7 +433,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "match with wildcard domain" do
|
||||
Config.put([:mrf_simple, :banner_removal], ["*.remote.instance"])
|
||||
clear_config([:mrf_simple, :banner_removal], ["*.remote.instance"])
|
||||
|
||||
remote_user = build_remote_user()
|
||||
{:ok, filtered} = SimplePolicy.filter(remote_user)
|
||||
|
|
@ -444,10 +443,10 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
describe "when :reject_deletes is empty" do
|
||||
setup do: Config.put([:mrf_simple, :reject_deletes], [])
|
||||
setup do: clear_config([:mrf_simple, :reject_deletes], [])
|
||||
|
||||
test "it accepts deletions even from rejected servers" do
|
||||
Config.put([:mrf_simple, :reject], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :reject], ["remote.instance"])
|
||||
|
||||
deletion_message = build_remote_deletion_message()
|
||||
|
||||
|
|
@ -455,7 +454,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "it accepts deletions even from non-whitelisted servers" do
|
||||
Config.put([:mrf_simple, :accept], ["non.matching.remote"])
|
||||
clear_config([:mrf_simple, :accept], ["non.matching.remote"])
|
||||
|
||||
deletion_message = build_remote_deletion_message()
|
||||
|
||||
|
|
@ -464,10 +463,10 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
describe "when :reject_deletes is not empty but it doesn't have a matching host" do
|
||||
setup do: Config.put([:mrf_simple, :reject_deletes], ["non.matching.remote"])
|
||||
setup do: clear_config([:mrf_simple, :reject_deletes], ["non.matching.remote"])
|
||||
|
||||
test "it accepts deletions even from rejected servers" do
|
||||
Config.put([:mrf_simple, :reject], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :reject], ["remote.instance"])
|
||||
|
||||
deletion_message = build_remote_deletion_message()
|
||||
|
||||
|
|
@ -475,7 +474,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "it accepts deletions even from non-whitelisted servers" do
|
||||
Config.put([:mrf_simple, :accept], ["non.matching.remote"])
|
||||
clear_config([:mrf_simple, :accept], ["non.matching.remote"])
|
||||
|
||||
deletion_message = build_remote_deletion_message()
|
||||
|
||||
|
|
@ -484,7 +483,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
describe "when :reject_deletes has a matching host" do
|
||||
setup do: Config.put([:mrf_simple, :reject_deletes], ["remote.instance"])
|
||||
setup do: clear_config([:mrf_simple, :reject_deletes], ["remote.instance"])
|
||||
|
||||
test "it rejects the deletion" do
|
||||
deletion_message = build_remote_deletion_message()
|
||||
|
|
@ -494,7 +493,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
describe "when :reject_deletes match with wildcard domain" do
|
||||
setup do: Config.put([:mrf_simple, :reject_deletes], ["*.remote.instance"])
|
||||
setup do: clear_config([:mrf_simple, :reject_deletes], ["*.remote.instance"])
|
||||
|
||||
test "it rejects the deletion" do
|
||||
deletion_message = build_remote_deletion_message()
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SubchainPolicyTest do
|
|||
setup do: clear_config([:mrf_subchain, :match_actor])
|
||||
|
||||
test "it matches and processes subchains when the actor matches a configured target" do
|
||||
Pleroma.Config.put([:mrf_subchain, :match_actor], %{
|
||||
clear_config([:mrf_subchain, :match_actor], %{
|
||||
~r/^https:\/\/banned.com/s => [DropPolicy]
|
||||
})
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SubchainPolicyTest do
|
|||
end
|
||||
|
||||
test "it doesn't match and process subchains when the actor doesn't match a configured target" do
|
||||
Pleroma.Config.put([:mrf_subchain, :match_actor], %{
|
||||
clear_config([:mrf_subchain, :match_actor], %{
|
||||
~r/^https:\/\/borked.com/s => [DropPolicy]
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -17,14 +17,14 @@ defmodule Pleroma.Web.ActivityPub.MRF.UserAllowListPolicyTest do
|
|||
|
||||
test "pass filter if allow list isn't empty and user in allow list" do
|
||||
actor = insert(:user)
|
||||
Pleroma.Config.put([:mrf_user_allowlist], %{"localhost" => [actor.ap_id, "test-ap-id"]})
|
||||
clear_config([:mrf_user_allowlist], %{"localhost" => [actor.ap_id, "test-ap-id"]})
|
||||
message = %{"actor" => actor.ap_id}
|
||||
assert UserAllowListPolicy.filter(message) == {:ok, message}
|
||||
end
|
||||
|
||||
test "rejected if allow list isn't empty and user not in allow list" do
|
||||
actor = insert(:user)
|
||||
Pleroma.Config.put([:mrf_user_allowlist], %{"localhost" => ["test-ap-id"]})
|
||||
clear_config([:mrf_user_allowlist], %{"localhost" => ["test-ap-id"]})
|
||||
message = %{"actor" => actor.ap_id}
|
||||
assert {:reject, _} = UserAllowListPolicy.filter(message)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
|
|||
setup do: clear_config([:mrf_vocabulary, :accept])
|
||||
|
||||
test "it accepts based on parent activity type" do
|
||||
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Like"])
|
||||
clear_config([:mrf_vocabulary, :accept], ["Like"])
|
||||
|
||||
message = %{
|
||||
"type" => "Like",
|
||||
|
|
@ -22,7 +22,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
|
|||
end
|
||||
|
||||
test "it accepts based on child object type" do
|
||||
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
|
||||
clear_config([:mrf_vocabulary, :accept], ["Create", "Note"])
|
||||
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
|
|
@ -36,7 +36,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
|
|||
end
|
||||
|
||||
test "it does not accept disallowed child objects" do
|
||||
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
|
||||
clear_config([:mrf_vocabulary, :accept], ["Create", "Note"])
|
||||
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
|
|
@ -50,7 +50,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
|
|||
end
|
||||
|
||||
test "it does not accept disallowed parent types" do
|
||||
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Announce", "Note"])
|
||||
clear_config([:mrf_vocabulary, :accept], ["Announce", "Note"])
|
||||
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
|
|
@ -68,7 +68,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
|
|||
setup do: clear_config([:mrf_vocabulary, :reject])
|
||||
|
||||
test "it rejects based on parent activity type" do
|
||||
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
|
||||
clear_config([:mrf_vocabulary, :reject], ["Like"])
|
||||
|
||||
message = %{
|
||||
"type" => "Like",
|
||||
|
|
@ -79,7 +79,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
|
|||
end
|
||||
|
||||
test "it rejects based on child object type" do
|
||||
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Note"])
|
||||
clear_config([:mrf_vocabulary, :reject], ["Note"])
|
||||
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
|
|
@ -93,7 +93,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
|
|||
end
|
||||
|
||||
test "it passes through objects that aren't disallowed" do
|
||||
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
|
||||
clear_config([:mrf_vocabulary, :reject], ["Like"])
|
||||
|
||||
message = %{
|
||||
"type" => "Announce",
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
|
|||
test "does not validate if the message is longer than the remote_limit", %{
|
||||
valid_chat_message: valid_chat_message
|
||||
} do
|
||||
Pleroma.Config.put([:instance, :remote_limit], 2)
|
||||
clear_config([:instance, :remote_limit], 2)
|
||||
refute match?({:ok, _object, _meta}, ObjectValidator.validate(valid_chat_message, []))
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
|||
end
|
||||
|
||||
test "it rejects incoming follow requests from blocked users when deny_follow_blocked is enabled" do
|
||||
Pleroma.Config.put([:user, :deny_follow_blocked], true)
|
||||
clear_config([:user, :deny_follow_blocked], true)
|
||||
|
||||
user = insert(:user)
|
||||
{:ok, target} = User.get_or_fetch("http://mastodon.example.org/users/admin")
|
||||
|
|
|
|||
|
|
@ -415,7 +415,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
data: data,
|
||||
items: items
|
||||
} do
|
||||
Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 10)
|
||||
clear_config([:instance, :federation_incoming_replies_max_depth], 10)
|
||||
|
||||
{:ok, _activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
|
|
@ -427,7 +427,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
|
||||
test "does NOT schedule background fetching of `replies` beyond max thread depth limit allows",
|
||||
%{data: data} do
|
||||
Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
|
||||
clear_config([:instance, :federation_incoming_replies_max_depth], 0)
|
||||
|
||||
{:ok, _activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
|
|
@ -464,7 +464,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
federation_output: federation_output,
|
||||
replies_uris: replies_uris
|
||||
} do
|
||||
Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 1)
|
||||
clear_config([:instance, :federation_incoming_replies_max_depth], 1)
|
||||
|
||||
{:ok, _activity} = Transmogrifier.handle_incoming(federation_output)
|
||||
|
||||
|
|
@ -476,7 +476,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
|
||||
test "does NOT schedule background fetching of `replies` beyond max thread depth limit allows",
|
||||
%{federation_output: federation_output} do
|
||||
Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
|
||||
clear_config([:instance, :federation_incoming_replies_max_depth], 0)
|
||||
|
||||
{:ok, _activity} = Transmogrifier.handle_incoming(federation_output)
|
||||
|
||||
|
|
@ -551,7 +551,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
end
|
||||
|
||||
test "returns object with inReplyTo when denied incoming reply", %{data: data} do
|
||||
Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
|
||||
clear_config([:instance, :federation_incoming_replies_max_depth], 0)
|
||||
|
||||
object_with_reply =
|
||||
Map.put(data["object"], "inReplyTo", "https://shitposter.club/notice/2827873")
|
||||
|
|
@ -585,7 +585,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
"https://mstdn.io/users/mayuutann/statuses/99568293732299394"
|
||||
)
|
||||
|
||||
Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 5)
|
||||
clear_config([:instance, :federation_incoming_replies_max_depth], 5)
|
||||
modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
|
||||
|
||||
assert modified_object["inReplyTo"] ==
|
||||
|
|
|
|||
|
|
@ -405,13 +405,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
setup do
|
||||
user = insert(:user)
|
||||
|
||||
date1 = (DateTime.to_unix(DateTime.utc_now()) + 2000) |> DateTime.from_unix!()
|
||||
date2 = (DateTime.to_unix(DateTime.utc_now()) + 1000) |> DateTime.from_unix!()
|
||||
date3 = (DateTime.to_unix(DateTime.utc_now()) + 3000) |> DateTime.from_unix!()
|
||||
|
||||
insert(:note_activity, user: user, published: date1)
|
||||
insert(:note_activity, user: user, published: date2)
|
||||
insert(:note_activity, user: user, published: date3)
|
||||
insert(:note_activity, user: user)
|
||||
insert(:note_activity, user: user)
|
||||
insert(:note_activity, user: user)
|
||||
|
||||
%{user: user}
|
||||
end
|
||||
|
|
@ -419,23 +415,22 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
test "renders user's statuses", %{conn: conn, user: user} do
|
||||
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses")
|
||||
|
||||
assert json_response(conn, 200) |> length() == 3
|
||||
assert %{"total" => 3, "activities" => activities} = json_response(conn, 200)
|
||||
assert length(activities) == 3
|
||||
end
|
||||
|
||||
test "renders user's statuses with pagination", %{conn: conn, user: user} do
|
||||
conn1 = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?page_size=1&page=1")
|
||||
%{"total" => 3, "activities" => [activity1]} =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/users/#{user.nickname}/statuses?page_size=1&page=1")
|
||||
|> json_response(200)
|
||||
|
||||
response1 = json_response(conn1, 200)
|
||||
%{"total" => 3, "activities" => [activity2]} =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/users/#{user.nickname}/statuses?page_size=1&page=2")
|
||||
|> json_response(200)
|
||||
|
||||
assert response1 |> length() == 1
|
||||
|
||||
conn2 = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?page_size=1&page=2")
|
||||
|
||||
response2 = json_response(conn2, 200)
|
||||
|
||||
assert response2 |> length() == 1
|
||||
|
||||
refute response1 == response2
|
||||
refute activity1 == activity2
|
||||
end
|
||||
|
||||
test "doesn't return private statuses by default", %{conn: conn, user: user} do
|
||||
|
|
@ -443,9 +438,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
{:ok, _public_status} = CommonAPI.post(user, %{status: "public", visibility: "public"})
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses")
|
||||
%{"total" => 4, "activities" => activities} =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/users/#{user.nickname}/statuses")
|
||||
|> json_response(200)
|
||||
|
||||
assert json_response(conn, 200) |> length() == 4
|
||||
assert length(activities) == 4
|
||||
end
|
||||
|
||||
test "returns private statuses with godmode on", %{conn: conn, user: user} do
|
||||
|
|
@ -453,9 +451,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
{:ok, _public_status} = CommonAPI.post(user, %{status: "public", visibility: "public"})
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?godmode=true")
|
||||
%{"total" => 5, "activities" => activities} =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/users/#{user.nickname}/statuses?godmode=true")
|
||||
|> json_response(200)
|
||||
|
||||
assert json_response(conn, 200) |> length() == 5
|
||||
assert length(activities) == 5
|
||||
end
|
||||
|
||||
test "excludes reblogs by default", %{conn: conn, user: user} do
|
||||
|
|
@ -463,13 +464,17 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
{:ok, activity} = CommonAPI.post(user, %{status: "."})
|
||||
{:ok, %Activity{}} = CommonAPI.repeat(activity.id, other_user)
|
||||
|
||||
conn_res = get(conn, "/api/pleroma/admin/users/#{other_user.nickname}/statuses")
|
||||
assert json_response(conn_res, 200) |> length() == 0
|
||||
assert %{"total" => 0, "activities" => []} ==
|
||||
conn
|
||||
|> get("/api/pleroma/admin/users/#{other_user.nickname}/statuses")
|
||||
|> json_response(200)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/pleroma/admin/users/#{other_user.nickname}/statuses?with_reblogs=true")
|
||||
|
||||
assert json_response(conn_res, 200) |> length() == 1
|
||||
assert %{"total" => 1, "activities" => [_]} =
|
||||
conn
|
||||
|> get(
|
||||
"/api/pleroma/admin/users/#{other_user.nickname}/statuses?with_reblogs=true"
|
||||
)
|
||||
|> json_response(200)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -859,33 +864,30 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
insert_pair(:note_activity, user: user)
|
||||
activity = insert(:note_activity, user: user2)
|
||||
|
||||
ret_conn = get(conn, "/api/pleroma/admin/instances/archae.me/statuses")
|
||||
%{"total" => 2, "activities" => activities} =
|
||||
conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
|
||||
|
||||
response = json_response(ret_conn, 200)
|
||||
assert length(activities) == 2
|
||||
|
||||
assert length(response) == 2
|
||||
%{"total" => 1, "activities" => [_]} =
|
||||
conn |> get("/api/pleroma/admin/instances/test.com/statuses") |> json_response(200)
|
||||
|
||||
ret_conn = get(conn, "/api/pleroma/admin/instances/test.com/statuses")
|
||||
|
||||
response = json_response(ret_conn, 200)
|
||||
|
||||
assert length(response) == 1
|
||||
|
||||
ret_conn = get(conn, "/api/pleroma/admin/instances/nonexistent.com/statuses")
|
||||
|
||||
response = json_response(ret_conn, 200)
|
||||
|
||||
assert Enum.empty?(response)
|
||||
%{"total" => 0, "activities" => []} =
|
||||
conn |> get("/api/pleroma/admin/instances/nonexistent.com/statuses") |> json_response(200)
|
||||
|
||||
CommonAPI.repeat(activity.id, user)
|
||||
|
||||
ret_conn = get(conn, "/api/pleroma/admin/instances/archae.me/statuses")
|
||||
response = json_response(ret_conn, 200)
|
||||
assert length(response) == 2
|
||||
%{"total" => 2, "activities" => activities} =
|
||||
conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
|
||||
|
||||
ret_conn = get(conn, "/api/pleroma/admin/instances/archae.me/statuses?with_reblogs=true")
|
||||
response = json_response(ret_conn, 200)
|
||||
assert length(response) == 3
|
||||
assert length(activities) == 2
|
||||
|
||||
%{"total" => 3, "activities" => activities} =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/instances/archae.me/statuses?with_reblogs=true")
|
||||
|> json_response(200)
|
||||
|
||||
assert length(activities) == 3
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
import ExUnit.CaptureLog
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.ConfigDB
|
||||
|
||||
setup do
|
||||
|
|
@ -27,7 +26,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
setup do: clear_config(:configurable_from_database, true)
|
||||
|
||||
test "when configuration from database is off", %{conn: conn} do
|
||||
Config.put(:configurable_from_database, false)
|
||||
clear_config(:configurable_from_database, false)
|
||||
conn = get(conn, "/api/pleroma/admin/config")
|
||||
|
||||
assert json_response_and_validate_schema(conn, 400) ==
|
||||
|
|
@ -410,8 +409,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
end
|
||||
|
||||
test "saving config which need pleroma reboot", %{conn: conn} do
|
||||
chat = Config.get(:chat)
|
||||
on_exit(fn -> Config.put(:chat, chat) end)
|
||||
clear_config([:chat, :enabled], true)
|
||||
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|
|
@ -456,8 +454,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
end
|
||||
|
||||
test "update setting which need reboot, don't change reboot flag until reboot", %{conn: conn} do
|
||||
chat = Config.get(:chat)
|
||||
on_exit(fn -> Config.put(:chat, chat) end)
|
||||
clear_config([:chat, :enabled], true)
|
||||
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ defmodule Pleroma.Web.AdminAPI.InviteControllerTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.UserInviteToken
|
||||
|
||||
|
|
@ -119,8 +118,8 @@ defmodule Pleroma.Web.AdminAPI.InviteControllerTest do
|
|||
setup do: clear_config([:instance, :invites_enabled])
|
||||
|
||||
test "it returns 500 if `invites_enabled` is not enabled", %{conn: conn} do
|
||||
Config.put([:instance, :registrations_open], false)
|
||||
Config.put([:instance, :invites_enabled], false)
|
||||
clear_config([:instance, :registrations_open], false)
|
||||
clear_config([:instance, :invites_enabled], false)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -138,8 +137,8 @@ defmodule Pleroma.Web.AdminAPI.InviteControllerTest do
|
|||
end
|
||||
|
||||
test "it returns 500 if `registrations_open` is enabled", %{conn: conn} do
|
||||
Config.put([:instance, :registrations_open], true)
|
||||
Config.put([:instance, :invites_enabled], true)
|
||||
clear_config([:instance, :registrations_open], true)
|
||||
clear_config([:instance, :invites_enabled], true)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
|
|||
|> assign(:user, admin)
|
||||
|> assign(:token, token)
|
||||
|
||||
Config.put([:media_proxy, :enabled], true)
|
||||
Config.put([:media_proxy, :invalidation, :enabled], true)
|
||||
Config.put([:media_proxy, :invalidation, :provider], MediaProxy.Invalidation.Script)
|
||||
clear_config([:media_proxy, :enabled], true)
|
||||
clear_config([:media_proxy, :invalidation, :enabled], true)
|
||||
clear_config([:media_proxy, :invalidation, :provider], MediaProxy.Invalidation.Script)
|
||||
|
||||
{:ok, %{admin: admin, token: token, conn: conn}}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ defmodule Pleroma.Web.ChatChannelTest do
|
|||
end
|
||||
|
||||
test "it ignores messages above a certain length", %{socket: socket} do
|
||||
Pleroma.Config.put([:instance, :chat_limit], 2)
|
||||
clear_config([:instance, :chat_limit], 2)
|
||||
push(socket, "new_msg", %{"text" => "123"})
|
||||
refute_broadcast("new_msg", %{text: "123"})
|
||||
end
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
end
|
||||
|
||||
test "it reject messages over the local limit" do
|
||||
Pleroma.Config.put([:instance, :chat_limit], 2)
|
||||
clear_config([:instance, :chat_limit], 2)
|
||||
|
||||
author = insert(:user)
|
||||
recipient = insert(:user)
|
||||
|
|
@ -475,7 +475,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
jafnhar = insert(:user)
|
||||
tridi = insert(:user)
|
||||
|
||||
Pleroma.Config.put([:instance, :safe_dm_mentions], true)
|
||||
clear_config([:instance, :safe_dm_mentions], true)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(har, %{
|
||||
|
|
@ -642,7 +642,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
end
|
||||
|
||||
test "it validates character limits are correctly enforced" do
|
||||
Pleroma.Config.put([:instance, :limit], 5)
|
||||
clear_config([:instance, :limit], 5)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -793,7 +793,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
describe "pinned statuses" do
|
||||
setup do
|
||||
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
|
||||
clear_config([:instance, :max_pinned_statuses], 1)
|
||||
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "HI!!!"})
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
activity: activity,
|
||||
relay_mock: relay_mock
|
||||
} do
|
||||
Pleroma.Config.put([:instance, :allow_relay], false)
|
||||
clear_config([:instance, :allow_relay], false)
|
||||
|
||||
with_mocks([relay_mock]) do
|
||||
Federator.publish(activity)
|
||||
|
|
@ -155,9 +155,9 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
end
|
||||
|
||||
test "it does not crash if MRF rejects the post" do
|
||||
Pleroma.Config.put([:mrf_keyword, :reject], ["lain"])
|
||||
clear_config([:mrf_keyword, :reject], ["lain"])
|
||||
|
||||
Pleroma.Config.put(
|
||||
clear_config(
|
||||
[:mrf, :policies],
|
||||
Pleroma.Web.ActivityPub.MRF.KeywordPolicy
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
import Pleroma.Factory
|
||||
import SweetXml
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.Feed.FeedView
|
||||
|
|
@ -16,7 +15,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
setup do: clear_config([:feed])
|
||||
|
||||
test "gets a feed (ATOM)", %{conn: conn} do
|
||||
Config.put(
|
||||
clear_config(
|
||||
[:feed, :post_title],
|
||||
%{max_length: 25, omission: "..."}
|
||||
)
|
||||
|
|
@ -83,7 +82,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
end
|
||||
|
||||
test "gets a feed (RSS)", %{conn: conn} do
|
||||
Config.put(
|
||||
clear_config(
|
||||
[:feed, :post_title],
|
||||
%{max_length: 25, omission: "..."}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
import Pleroma.Factory
|
||||
import SweetXml
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
|
@ -20,7 +19,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
setup do: clear_config([:feed])
|
||||
|
||||
setup do
|
||||
Config.put(
|
||||
clear_config(
|
||||
[:feed, :post_title],
|
||||
%{max_length: 15, omission: "..."}
|
||||
)
|
||||
|
|
@ -236,7 +235,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
setup do: clear_config([:instance, :public])
|
||||
|
||||
test "returns 404 for user feed", %{conn: conn} do
|
||||
Config.put([:instance, :public], false)
|
||||
clear_config([:instance, :public], false)
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "test"})
|
||||
|
|
|
|||
|
|
@ -29,6 +29,45 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|> json_response_and_validate_schema(404)
|
||||
end
|
||||
|
||||
test "relationship field" do
|
||||
%{conn: conn, user: user} = oauth_access(["read"])
|
||||
|
||||
other_user = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{other_user.id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response["id"] == other_user.id
|
||||
assert response["pleroma"]["relationship"] == %{}
|
||||
|
||||
assert %{"pleroma" => %{"relationship" => %{"following" => false, "followed_by" => false}}} =
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{other_user.id}?with_relationships=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
{:ok, _, %{id: other_id}} = User.follow(user, other_user)
|
||||
|
||||
assert %{
|
||||
"id" => ^other_id,
|
||||
"pleroma" => %{"relationship" => %{"following" => true, "followed_by" => false}}
|
||||
} =
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{other_id}?with_relationships=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
{:ok, _, _} = User.follow(other_user, user)
|
||||
|
||||
assert %{
|
||||
"id" => ^other_id,
|
||||
"pleroma" => %{"relationship" => %{"following" => true, "followed_by" => true}}
|
||||
} =
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{other_id}?with_relationships=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "works by nickname" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -590,6 +629,45 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert [%{"id" => ^user_id}] = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "following with relationship", %{conn: conn, user: user} do
|
||||
other_user = insert(:user)
|
||||
{:ok, %{id: id}, _} = User.follow(other_user, user)
|
||||
|
||||
assert [
|
||||
%{
|
||||
"id" => ^id,
|
||||
"pleroma" => %{
|
||||
"relationship" => %{
|
||||
"id" => ^id,
|
||||
"following" => false,
|
||||
"followed_by" => true
|
||||
}
|
||||
}
|
||||
}
|
||||
] =
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{user.id}/followers?with_relationships=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
{:ok, _, _} = User.follow(user, other_user)
|
||||
|
||||
assert [
|
||||
%{
|
||||
"id" => ^id,
|
||||
"pleroma" => %{
|
||||
"relationship" => %{
|
||||
"id" => ^id,
|
||||
"following" => true,
|
||||
"followed_by" => true
|
||||
}
|
||||
}
|
||||
}
|
||||
] =
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{user.id}/followers?with_relationships=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "getting followers, hide_followers", %{user: user, conn: conn} do
|
||||
other_user = insert(:user, hide_followers: true)
|
||||
{:ok, _user, _other_user} = User.follow(user, other_user)
|
||||
|
|
@ -660,6 +738,24 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert id == to_string(other_user.id)
|
||||
end
|
||||
|
||||
test "following with relationship", %{conn: conn, user: user} do
|
||||
other_user = insert(:user)
|
||||
{:ok, user, other_user} = User.follow(user, other_user)
|
||||
|
||||
conn = get(conn, "/api/v1/accounts/#{user.id}/following?with_relationships=true")
|
||||
|
||||
id = other_user.id
|
||||
|
||||
assert [
|
||||
%{
|
||||
"id" => ^id,
|
||||
"pleroma" => %{
|
||||
"relationship" => %{"id" => ^id, "following" => true, "followed_by" => false}
|
||||
}
|
||||
}
|
||||
] = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "getting following, hide_follows, other user requesting" do
|
||||
user = insert(:user, hide_follows: true)
|
||||
other_user = insert(:user)
|
||||
|
|
@ -1007,7 +1103,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert %{"error" => "{\"email\":[\"Invalid email\"]}"} =
|
||||
json_response_and_validate_schema(conn, 400)
|
||||
|
||||
Pleroma.Config.put([User, :email_blacklist], [])
|
||||
clear_config([User, :email_blacklist], [])
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|
|
@ -1565,7 +1661,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/mutes")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
|
|
@ -1573,7 +1668,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/mutes?limit=1")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
|
|
@ -1581,7 +1675,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/mutes?since_id=#{id1}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
|
|
@ -1589,7 +1682,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/mutes?since_id=#{id1}&max_id=#{id3}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
|
|
@ -1597,13 +1689,45 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/mutes?since_id=#{id1}&limit=1")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"id" => ^id2}] = result
|
||||
end
|
||||
|
||||
test "list of mutes with with_relationships parameter" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:mutes"])
|
||||
%{id: id1} = other_user1 = insert(:user)
|
||||
%{id: id2} = other_user2 = insert(:user)
|
||||
%{id: id3} = other_user3 = insert(:user)
|
||||
|
||||
{:ok, _, _} = User.follow(other_user1, user)
|
||||
{:ok, _, _} = User.follow(other_user2, user)
|
||||
{:ok, _, _} = User.follow(other_user3, user)
|
||||
|
||||
{:ok, _} = User.mute(user, other_user1)
|
||||
{:ok, _} = User.mute(user, other_user2)
|
||||
{:ok, _} = User.mute(user, other_user3)
|
||||
|
||||
assert [
|
||||
%{
|
||||
"id" => ^id1,
|
||||
"pleroma" => %{"relationship" => %{"muting" => true, "followed_by" => true}}
|
||||
},
|
||||
%{
|
||||
"id" => ^id2,
|
||||
"pleroma" => %{"relationship" => %{"muting" => true, "followed_by" => true}}
|
||||
},
|
||||
%{
|
||||
"id" => ^id3,
|
||||
"pleroma" => %{"relationship" => %{"muting" => true, "followed_by" => true}}
|
||||
}
|
||||
] =
|
||||
conn
|
||||
|> get("/api/v1/mutes?with_relationships=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "getting a list of blocks" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:blocks"])
|
||||
%{id: id1} = other_user1 = insert(:user)
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
|
|||
assert result["pleroma"]["metadata"]["federation"]
|
||||
assert result["pleroma"]["metadata"]["fields_limits"]
|
||||
assert result["pleroma"]["vapid_public_key"]
|
||||
assert result["pleroma"]["stats"]["mau"] == 0
|
||||
|
||||
assert email == from_config_email
|
||||
assert thumbnail == from_config_thumbnail
|
||||
|
|
|
|||
|
|
@ -55,30 +55,39 @@ defmodule Pleroma.Web.MastodonAPI.ListControllerTest do
|
|||
test "adding users to a list" do
|
||||
%{user: user, conn: conn} = oauth_access(["write:lists"])
|
||||
other_user = insert(:user)
|
||||
third_user = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
|
||||
assert %{} ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]})
|
||||
|> post("/api/v1/lists/#{list.id}/accounts", %{
|
||||
"account_ids" => [other_user.id, third_user.id]
|
||||
})
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
%Pleroma.List{following: following} = Pleroma.List.get(list.id, user)
|
||||
assert following == [other_user.follower_address]
|
||||
assert length(following) == 2
|
||||
assert other_user.follower_address in following
|
||||
assert third_user.follower_address in following
|
||||
end
|
||||
|
||||
test "removing users from a list, body params" do
|
||||
%{user: user, conn: conn} = oauth_access(["write:lists"])
|
||||
other_user = insert(:user)
|
||||
third_user = insert(:user)
|
||||
fourth_user = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
{:ok, list} = Pleroma.List.follow(list, other_user)
|
||||
{:ok, list} = Pleroma.List.follow(list, third_user)
|
||||
{:ok, list} = Pleroma.List.follow(list, fourth_user)
|
||||
|
||||
assert %{} ==
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> delete("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]})
|
||||
|> delete("/api/v1/lists/#{list.id}/accounts", %{
|
||||
"account_ids" => [other_user.id, fourth_user.id]
|
||||
})
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
%Pleroma.List{following: following} = Pleroma.List.get(list.id, user)
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityControllerTest do
|
|||
end
|
||||
|
||||
test "updates a scheduled activity" do
|
||||
Pleroma.Config.put([ScheduledActivity, :enabled], true)
|
||||
clear_config([ScheduledActivity, :enabled], true)
|
||||
%{user: user, conn: conn} = oauth_access(["write:statuses"])
|
||||
|
||||
scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60)
|
||||
|
|
@ -103,7 +103,7 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityControllerTest do
|
|||
end
|
||||
|
||||
test "deletes a scheduled activity" do
|
||||
Pleroma.Config.put([ScheduledActivity, :enabled], true)
|
||||
clear_config([ScheduledActivity, :enabled], true)
|
||||
%{user: user, conn: conn} = oauth_access(["write:statuses"])
|
||||
scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Conversation.Participation
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
|
|
@ -29,7 +28,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
setup do: oauth_access(["write:statuses"])
|
||||
|
||||
test "posting a status does not increment reblog_count when relaying", %{conn: conn} do
|
||||
Config.put([:instance, :federating], true)
|
||||
clear_config([:instance, :federating], true)
|
||||
Config.get([:instance, :allow_relay], true)
|
||||
|
||||
response =
|
||||
|
|
@ -151,8 +150,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
end
|
||||
|
||||
test "Get MRF reason when posting a status is rejected by one", %{conn: conn} do
|
||||
Config.put([:mrf_keyword, :reject], ["GNO"])
|
||||
Config.put([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.KeywordPolicy])
|
||||
clear_config([:mrf_keyword, :reject], ["GNO"])
|
||||
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.KeywordPolicy])
|
||||
|
||||
assert %{"error" => "[KeywordPolicy] Matches with rejected keyword"} =
|
||||
conn
|
||||
|
|
@ -264,6 +263,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
fake_conn =
|
||||
conn
|
||||
|> assign(:user, refresh_record(conn.assigns.user))
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses", %{
|
||||
"status" =>
|
||||
|
|
@ -516,7 +516,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
end)
|
||||
|
||||
assert NaiveDateTime.diff(NaiveDateTime.from_iso8601!(response["poll"]["expires_at"]), time) in 420..430
|
||||
refute response["poll"]["expred"]
|
||||
assert response["poll"]["expired"] == false
|
||||
|
||||
question = Object.get_by_id(response["poll"]["id"])
|
||||
|
||||
|
|
@ -592,6 +592,44 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
%{"error" => error} = json_response_and_validate_schema(conn, 422)
|
||||
assert error == "Expiration date is too far in the future"
|
||||
end
|
||||
|
||||
test "scheduled poll", %{conn: conn} do
|
||||
clear_config([ScheduledActivity, :enabled], true)
|
||||
|
||||
scheduled_at =
|
||||
NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(6), :millisecond)
|
||||
|> NaiveDateTime.to_iso8601()
|
||||
|> Kernel.<>("Z")
|
||||
|
||||
%{"id" => scheduled_id} =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses", %{
|
||||
"status" => "very cool poll",
|
||||
"poll" => %{
|
||||
"options" => ~w(a b c),
|
||||
"expires_in" => 420
|
||||
},
|
||||
"scheduled_at" => scheduled_at
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert {:ok, %{id: activity_id}} =
|
||||
perform_job(Pleroma.Workers.ScheduledActivityWorker, %{
|
||||
activity_id: scheduled_id
|
||||
})
|
||||
|
||||
assert Repo.all(Oban.Job) == []
|
||||
|
||||
object =
|
||||
Activity
|
||||
|> Repo.get(activity_id)
|
||||
|> Object.normalize()
|
||||
|
||||
assert object.data["content"] == "very cool poll"
|
||||
assert object.data["type"] == "Question"
|
||||
assert length(object.data["oneOf"]) == 3
|
||||
end
|
||||
end
|
||||
|
||||
test "get a status" do
|
||||
|
|
@ -1204,7 +1242,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
describe "cards" do
|
||||
setup do
|
||||
Config.put([:rich_media, :enabled], true)
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
|
||||
oauth_access(["read:statuses"])
|
||||
end
|
||||
|
|
|
|||
|
|
@ -90,6 +90,65 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
}
|
||||
] = result
|
||||
end
|
||||
|
||||
test "filtering", %{conn: conn, user: user} do
|
||||
local_user = insert(:user)
|
||||
{:ok, user, local_user} = User.follow(user, local_user)
|
||||
{:ok, local_activity} = CommonAPI.post(local_user, %{status: "Status"})
|
||||
with_media = create_with_media_activity(local_user)
|
||||
|
||||
remote_user = insert(:user, local: false)
|
||||
{:ok, _user, remote_user} = User.follow(user, remote_user)
|
||||
remote_activity = create_remote_activity(remote_user)
|
||||
|
||||
without_filter_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/home")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert local_activity.id in without_filter_ids
|
||||
assert remote_activity.id in without_filter_ids
|
||||
assert with_media.id in without_filter_ids
|
||||
|
||||
only_local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/home?local=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert local_activity.id in only_local_ids
|
||||
refute remote_activity.id in only_local_ids
|
||||
assert with_media.id in only_local_ids
|
||||
|
||||
only_local_media_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/home?local=true&only_media=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute local_activity.id in only_local_media_ids
|
||||
refute remote_activity.id in only_local_media_ids
|
||||
assert with_media.id in only_local_media_ids
|
||||
|
||||
remote_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/home?remote=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute local_activity.id in remote_ids
|
||||
assert remote_activity.id in remote_ids
|
||||
refute with_media.id in remote_ids
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/home?remote=true&only_media=true")
|
||||
|> json_response_and_validate_schema(200) == []
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/home?remote=true&local=true")
|
||||
|> json_response_and_validate_schema(200) == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "public" do
|
||||
|
|
@ -98,27 +157,80 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "test"})
|
||||
with_media = create_with_media_activity(user)
|
||||
|
||||
_activity = insert(:note_activity, local: false)
|
||||
remote = insert(:note_activity, local: false)
|
||||
|
||||
conn = get(conn, "/api/v1/timelines/public?local=False")
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/public?local=False")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> length == 3
|
||||
|
||||
assert length(json_response_and_validate_schema(conn, :ok)) == 2
|
||||
local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?local=True")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
conn = get(build_conn(), "/api/v1/timelines/public?local=True")
|
||||
assert activity.id in local_ids
|
||||
assert with_media.id in local_ids
|
||||
refute remote.id in local_ids
|
||||
|
||||
assert [%{"content" => "test"}] = json_response_and_validate_schema(conn, :ok)
|
||||
local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?local=True")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
conn = get(build_conn(), "/api/v1/timelines/public?local=1")
|
||||
assert activity.id in local_ids
|
||||
assert with_media.id in local_ids
|
||||
refute remote.id in local_ids
|
||||
|
||||
assert [%{"content" => "test"}] = json_response_and_validate_schema(conn, :ok)
|
||||
local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?local=True&only_media=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute activity.id in local_ids
|
||||
assert with_media.id in local_ids
|
||||
refute remote.id in local_ids
|
||||
|
||||
local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?local=1")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert activity.id in local_ids
|
||||
assert with_media.id in local_ids
|
||||
refute remote.id in local_ids
|
||||
|
||||
remote_id = remote.id
|
||||
|
||||
assert [%{"id" => ^remote_id}] =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?remote=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
with_media_id = with_media.id
|
||||
|
||||
assert [%{"id" => ^with_media_id}] =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?only_media=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/public?remote=true&only_media=true")
|
||||
|> json_response_and_validate_schema(:ok) == []
|
||||
|
||||
# does not contain repeats
|
||||
{:ok, _} = CommonAPI.repeat(activity.id, user)
|
||||
|
||||
conn = get(build_conn(), "/api/v1/timelines/public?local=true")
|
||||
|
||||
assert [_] = json_response_and_validate_schema(conn, :ok)
|
||||
assert [_, _] =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?local=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
end
|
||||
|
||||
test "the public timeline includes only public statuses for an authenticated user" do
|
||||
|
|
@ -544,6 +656,77 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
}
|
||||
] = result
|
||||
end
|
||||
|
||||
test "filtering", %{user: user, conn: conn} do
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
|
||||
local_user = insert(:user)
|
||||
{:ok, local_activity} = CommonAPI.post(local_user, %{status: "Marisa is stupid."})
|
||||
with_media = create_with_media_activity(local_user)
|
||||
{:ok, list} = Pleroma.List.follow(list, local_user)
|
||||
|
||||
remote_user = insert(:user, local: false)
|
||||
remote_activity = create_remote_activity(remote_user)
|
||||
{:ok, list} = Pleroma.List.follow(list, remote_user)
|
||||
|
||||
all_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert local_activity.id in all_ids
|
||||
assert with_media.id in all_ids
|
||||
assert remote_activity.id in all_ids
|
||||
|
||||
only_local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}?local=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert local_activity.id in only_local_ids
|
||||
assert with_media.id in only_local_ids
|
||||
refute remote_activity.id in only_local_ids
|
||||
|
||||
only_local_media_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}?local=true&only_media=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute local_activity.id in only_local_media_ids
|
||||
assert with_media.id in only_local_media_ids
|
||||
refute remote_activity.id in only_local_media_ids
|
||||
|
||||
remote_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}?remote=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute local_activity.id in remote_ids
|
||||
refute with_media.id in remote_ids
|
||||
assert remote_activity.id in remote_ids
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}?remote=true&only_media=true")
|
||||
|> json_response_and_validate_schema(200) == []
|
||||
|
||||
only_media_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}?only_media=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute local_activity.id in only_media_ids
|
||||
assert with_media.id in only_media_ids
|
||||
refute remote_activity.id in only_media_ids
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}?only_media=true&local=true&remote=true")
|
||||
|> json_response_and_validate_schema(200) == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "hashtag" do
|
||||
|
|
@ -554,19 +737,85 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
following = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(following, %{status: "test #2hu"})
|
||||
with_media = create_with_media_activity(following)
|
||||
|
||||
nconn = get(conn, "/api/v1/timelines/tag/2hu")
|
||||
remote = insert(:user, local: false)
|
||||
remote_activity = create_remote_activity(remote)
|
||||
|
||||
assert [%{"id" => id}] = json_response_and_validate_schema(nconn, :ok)
|
||||
all_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2hu")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert id == to_string(activity.id)
|
||||
assert activity.id in all_ids
|
||||
assert with_media.id in all_ids
|
||||
assert remote_activity.id in all_ids
|
||||
|
||||
# works for different capitalization too
|
||||
nconn = get(conn, "/api/v1/timelines/tag/2HU")
|
||||
all_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2HU")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert [%{"id" => id}] = json_response_and_validate_schema(nconn, :ok)
|
||||
assert activity.id in all_ids
|
||||
assert with_media.id in all_ids
|
||||
assert remote_activity.id in all_ids
|
||||
|
||||
assert id == to_string(activity.id)
|
||||
local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2hu?local=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert activity.id in local_ids
|
||||
assert with_media.id in local_ids
|
||||
refute remote_activity.id in local_ids
|
||||
|
||||
remote_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2hu?remote=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute activity.id in remote_ids
|
||||
refute with_media.id in remote_ids
|
||||
assert remote_activity.id in remote_ids
|
||||
|
||||
media_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2hu?only_media=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute activity.id in media_ids
|
||||
assert with_media.id in media_ids
|
||||
refute remote_activity.id in media_ids
|
||||
|
||||
media_local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2hu?only_media=true&local=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute activity.id in media_local_ids
|
||||
assert with_media.id in media_local_ids
|
||||
refute remote_activity.id in media_local_ids
|
||||
|
||||
ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2hu?only_media=true&local=true&remote=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute activity.id in ids
|
||||
refute with_media.id in ids
|
||||
refute remote_activity.id in ids
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/tag/2hu?only_media=true&remote=true")
|
||||
|> json_response_and_validate_schema(:ok) == []
|
||||
end
|
||||
|
||||
test "multi-hashtag timeline", %{conn: conn} do
|
||||
|
|
@ -726,4 +975,37 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
ensure_authenticated_access(base_uri)
|
||||
end
|
||||
end
|
||||
|
||||
defp create_remote_activity(user) do
|
||||
obj =
|
||||
insert(:note, %{
|
||||
data: %{
|
||||
"to" => [
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
User.ap_followers(user)
|
||||
]
|
||||
},
|
||||
user: user
|
||||
})
|
||||
|
||||
insert(:note_activity, %{
|
||||
note: obj,
|
||||
recipients: [
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
User.ap_followers(user)
|
||||
],
|
||||
user: user,
|
||||
local: false
|
||||
})
|
||||
end
|
||||
|
||||
defp create_with_media_activity(user) do
|
||||
obj = insert(:attachment_note, user: user)
|
||||
|
||||
insert(:note_activity, %{
|
||||
note: obj,
|
||||
recipients: ["https://www.w3.org/ns/activitystreams#Public", User.ap_followers(user)],
|
||||
user: user
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.MastoFEControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.User
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
@ -55,7 +54,7 @@ defmodule Pleroma.Web.MastodonAPI.MastoFEControllerTest do
|
|||
conn: conn,
|
||||
path: path
|
||||
} do
|
||||
Config.put([:instance, :public], false)
|
||||
clear_config([:instance, :public], false)
|
||||
|
||||
conn = get(conn, path)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserRelationship
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
|
@ -74,6 +73,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
},
|
||||
fields: []
|
||||
},
|
||||
fqn: "shp@shitposter.club",
|
||||
pleroma: %{
|
||||
ap_id: user.ap_id,
|
||||
also_known_as: ["https://shitposter.zone/users/shp"],
|
||||
|
|
@ -173,6 +173,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
},
|
||||
fields: []
|
||||
},
|
||||
fqn: "shp@shitposter.club",
|
||||
pleroma: %{
|
||||
ap_id: user.ap_id,
|
||||
also_known_as: [],
|
||||
|
|
@ -556,7 +557,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
)
|
||||
|
||||
with media_preview_enabled <- [false, true] do
|
||||
Config.put([:media_preview_proxy, :enabled], media_preview_enabled)
|
||||
clear_config([:media_preview_proxy, :enabled], media_preview_enabled)
|
||||
|
||||
AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
|> Enum.all?(fn
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
defmodule Pleroma.Web.MediaProxy.InvalidationTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Web.MediaProxy.Invalidation
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
|
|
@ -16,11 +15,11 @@ defmodule Pleroma.Web.MediaProxy.InvalidationTest do
|
|||
|
||||
describe "Invalidation.Http" do
|
||||
test "perform request to clear cache" do
|
||||
Config.put([:media_proxy, :enabled], false)
|
||||
Config.put([:media_proxy, :invalidation, :enabled], true)
|
||||
Config.put([:media_proxy, :invalidation, :provider], Invalidation.Http)
|
||||
clear_config([:media_proxy, :enabled], false)
|
||||
clear_config([:media_proxy, :invalidation, :enabled], true)
|
||||
clear_config([:media_proxy, :invalidation, :provider], Invalidation.Http)
|
||||
|
||||
Config.put([Invalidation.Http], method: :purge, headers: [{"x-refresh", 1}])
|
||||
clear_config([Invalidation.Http], method: :purge, headers: [{"x-refresh", 1}])
|
||||
image_url = "http://example.com/media/example.jpg"
|
||||
Pleroma.Web.MediaProxy.put_in_banned_urls(image_url)
|
||||
|
||||
|
|
@ -43,10 +42,10 @@ defmodule Pleroma.Web.MediaProxy.InvalidationTest do
|
|||
|
||||
describe "Invalidation.Script" do
|
||||
test "run script to clear cache" do
|
||||
Config.put([:media_proxy, :enabled], false)
|
||||
Config.put([:media_proxy, :invalidation, :enabled], true)
|
||||
Config.put([:media_proxy, :invalidation, :provider], Invalidation.Script)
|
||||
Config.put([Invalidation.Script], script_path: "purge-nginx")
|
||||
clear_config([:media_proxy, :enabled], false)
|
||||
clear_config([:media_proxy, :invalidation, :enabled], true)
|
||||
clear_config([:media_proxy, :invalidation, :provider], Invalidation.Script)
|
||||
clear_config([Invalidation.Script], script_path: "purge-nginx")
|
||||
|
||||
image_url = "http://example.com/media/example.jpg"
|
||||
Pleroma.Web.MediaProxy.put_in_banned_urls(image_url)
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
|||
end
|
||||
|
||||
test "it returns 403 for invalid signature", %{conn: conn, url: url} do
|
||||
Pleroma.Config.put([Pleroma.Web.Endpoint, :secret_key_base], "000")
|
||||
clear_config([Pleroma.Web.Endpoint, :secret_key_base], "000")
|
||||
%{path: path} = URI.parse(url)
|
||||
|
||||
assert %Conn{
|
||||
|
|
@ -128,7 +128,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
|||
end
|
||||
|
||||
test "it returns 403 for invalid signature", %{conn: conn, url: url} do
|
||||
Pleroma.Config.put([Pleroma.Web.Endpoint, :secret_key_base], "000")
|
||||
clear_config([Pleroma.Web.Endpoint, :secret_key_base], "000")
|
||||
%{path: path} = URI.parse(url)
|
||||
|
||||
assert %Conn{
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
|
|||
end
|
||||
|
||||
test "it does not render attachments if post is nsfw" do
|
||||
Pleroma.Config.put([Pleroma.Web.Metadata, :unfurl_nsfw], false)
|
||||
clear_config([Pleroma.Web.Metadata, :unfurl_nsfw], false)
|
||||
user = insert(:user, avatar: %{"url" => [%{"href" => "https://pleroma.gov/tenshi.png"}]})
|
||||
|
||||
note =
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
|
|||
end
|
||||
|
||||
test "it renders avatar not attachment if post is nsfw and unfurl_nsfw is disabled" do
|
||||
Pleroma.Config.put([Pleroma.Web.Metadata, :unfurl_nsfw], false)
|
||||
clear_config([Pleroma.Web.Metadata, :unfurl_nsfw], false)
|
||||
user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "HI"})
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Config
|
||||
|
||||
setup do: clear_config([:mrf_simple])
|
||||
setup do: clear_config(:instance)
|
||||
|
||||
|
|
@ -93,7 +91,7 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||
|
||||
assert "safe_dm_mentions" in response["metadata"]["features"]
|
||||
|
||||
Config.put([:instance, :safe_dm_mentions], false)
|
||||
clear_config([:instance, :safe_dm_mentions], false)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -107,7 +105,7 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||
setup do: clear_config([:instance, :federating])
|
||||
|
||||
test "it shows if federation is enabled/disabled", %{conn: conn} do
|
||||
Config.put([:instance, :federating], true)
|
||||
clear_config([:instance, :federating], true)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -116,7 +114,7 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||
|
||||
assert response["metadata"]["federation"]["enabled"] == true
|
||||
|
||||
Config.put([:instance, :federating], false)
|
||||
clear_config([:instance, :federating], false)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
|
|||
|
|
@ -923,7 +923,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
end
|
||||
|
||||
test "rejects token exchange for valid credentials belonging to unconfirmed user and confirmation is required" do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
clear_config([:instance, :account_activation_required], true)
|
||||
password = "testpassword"
|
||||
|
||||
{:ok, user} =
|
||||
|
|
@ -1007,7 +1007,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
end
|
||||
|
||||
test "rejects token exchange for user with confirmation_pending set to true" do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
clear_config([:instance, :account_activation_required], true)
|
||||
password = "testpassword"
|
||||
|
||||
user =
|
||||
|
|
@ -1086,7 +1086,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
setup do: clear_config([:oauth2, :issue_new_refresh_token])
|
||||
|
||||
test "issues a new access token with keep fresh token" do
|
||||
Pleroma.Config.put([:oauth2, :issue_new_refresh_token], true)
|
||||
clear_config([:oauth2, :issue_new_refresh_token], true)
|
||||
user = insert(:user)
|
||||
app = insert(:oauth_app, scopes: ["read", "write"])
|
||||
|
||||
|
|
@ -1125,7 +1125,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
end
|
||||
|
||||
test "issues a new access token with new fresh token" do
|
||||
Pleroma.Config.put([:oauth2, :issue_new_refresh_token], false)
|
||||
clear_config([:oauth2, :issue_new_refresh_token], false)
|
||||
user = insert(:user)
|
||||
app = insert(:oauth_app, scopes: ["read", "write"])
|
||||
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ defmodule Pleroma.Web.PleromaAPI.ConversationControllerTest do
|
|||
[participation] = Participation.for_user(user)
|
||||
participation = Repo.preload(participation, :recipients)
|
||||
|
||||
assert user in participation.recipients
|
||||
assert refresh_record(user) in participation.recipients
|
||||
assert other_user in participation.recipients
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
|
|||
end
|
||||
|
||||
test "GET /api/pleroma/emoji/packs when :public: false", %{conn: conn} do
|
||||
Config.put([:instance, :public], false)
|
||||
clear_config([:instance, :public], false)
|
||||
conn |> get("/api/pleroma/emoji/packs") |> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ defmodule Pleroma.Web.Plugs.AdminSecretAuthenticationPlugTest do
|
|||
end
|
||||
|
||||
test "with `admin_token` query parameter", %{conn: conn} do
|
||||
Pleroma.Config.put(:admin_token, "password123")
|
||||
clear_config(:admin_token, "password123")
|
||||
|
||||
conn =
|
||||
%{conn | params: %{"admin_token" => "wrong_password"}}
|
||||
|
|
@ -54,7 +54,7 @@ defmodule Pleroma.Web.Plugs.AdminSecretAuthenticationPlugTest do
|
|||
end
|
||||
|
||||
test "with `x-admin-token` HTTP header", %{conn: conn} do
|
||||
Pleroma.Config.put(:admin_token, "☕️")
|
||||
clear_config(:admin_token, "☕️")
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
|
|||
|
|
@ -5,14 +5,13 @@
|
|||
defmodule Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlugTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug
|
||||
|
||||
setup do: clear_config([:instance, :public])
|
||||
|
||||
test "it halts if not public and no user is assigned", %{conn: conn} do
|
||||
Config.put([:instance, :public], false)
|
||||
clear_config([:instance, :public], false)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -23,7 +22,7 @@ defmodule Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlugTest do
|
|||
end
|
||||
|
||||
test "it continues if public", %{conn: conn} do
|
||||
Config.put([:instance, :public], true)
|
||||
clear_config([:instance, :public], true)
|
||||
|
||||
ret_conn =
|
||||
conn
|
||||
|
|
@ -33,7 +32,7 @@ defmodule Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlugTest do
|
|||
end
|
||||
|
||||
test "it continues if a user is assigned, even if not public", %{conn: conn} do
|
||||
Config.put([:instance, :public], false)
|
||||
clear_config([:instance, :public], false)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ defmodule Pleroma.Web.Plugs.FederatingPlugTest do
|
|||
setup do: clear_config([:instance, :federating])
|
||||
|
||||
test "returns and halt the conn when federating is disabled" do
|
||||
Pleroma.Config.put([:instance, :federating], false)
|
||||
clear_config([:instance, :federating], false)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|
|
@ -19,7 +19,7 @@ defmodule Pleroma.Web.Plugs.FederatingPlugTest do
|
|||
end
|
||||
|
||||
test "does nothing when federating is enabled" do
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
clear_config([:instance, :federating], true)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|
|
|
|||
|
|
@ -72,6 +72,21 @@ defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do
|
|||
assert csp =~ "media-src 'self' https:;"
|
||||
assert csp =~ "img-src 'self' data: blob: https:;"
|
||||
end
|
||||
|
||||
test "it sets the Service-Worker-Allowed header", %{conn: conn} do
|
||||
clear_config([:http_security, :enabled], true)
|
||||
clear_config([:frontends, :primary], %{"name" => "fedi-fe", "ref" => "develop"})
|
||||
|
||||
clear_config([:frontends, :available], %{
|
||||
"fedi-fe" => %{
|
||||
"name" => "fedi-fe",
|
||||
"custom-http-headers" => [{"service-worker-allowed", "/"}]
|
||||
}
|
||||
})
|
||||
|
||||
conn = get(conn, "/api/v1/instance")
|
||||
assert Conn.get_resp_header(conn, "service-worker-allowed") == ["/"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "img-src and media-src" do
|
||||
|
|
|
|||
|
|
@ -32,11 +32,7 @@ defmodule Pleroma.Web.Plugs.HTTPSignaturePlugTest do
|
|||
|
||||
describe "requires a signature when `authorized_fetch_mode` is enabled" do
|
||||
setup do
|
||||
Pleroma.Config.put([:activitypub, :authorized_fetch_mode], true)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:activitypub, :authorized_fetch_mode], false)
|
||||
end)
|
||||
clear_config([:activitypub, :authorized_fetch_mode], true)
|
||||
|
||||
params = %{"actor" => "http://mastodon.example.org/users/admin"}
|
||||
conn = build_conn(:get, "/doesntmattter", params) |> put_format("activity+json")
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ defmodule Pleroma.Web.Plugs.OAuthScopesPlugTest do
|
|||
"and [optionally] keeps only prefixed scopes, " <>
|
||||
"depending on `[:auth, :enforce_oauth_admin_scope_usage]` setting",
|
||||
%{f: f} do
|
||||
Pleroma.Config.put([:auth, :enforce_oauth_admin_scope_usage], false)
|
||||
clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
|
||||
|
||||
assert f.(["read"], %{admin: true}) == ["admin:read", "read"]
|
||||
|
||||
|
|
@ -192,7 +192,7 @@ defmodule Pleroma.Web.Plugs.OAuthScopesPlugTest do
|
|||
"write"
|
||||
]
|
||||
|
||||
Pleroma.Config.put([:auth, :enforce_oauth_admin_scope_usage], true)
|
||||
clear_config([:auth, :enforce_oauth_admin_scope_usage], true)
|
||||
|
||||
assert f.(["read:accounts"], %{admin: true}) == ["admin:read:accounts"]
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Phoenix.ConnTest
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Web.Plugs.RateLimiter
|
||||
alias Plug.Conn
|
||||
|
||||
|
|
@ -22,8 +21,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
|
|||
setup do: clear_config([Pleroma.Web.Plugs.RemoteIp, :enabled])
|
||||
|
||||
test "config is required for plug to work" do
|
||||
Config.put([:rate_limit, @limiter_name], {1, 1})
|
||||
Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
|
||||
clear_config([:rate_limit, @limiter_name], {1, 1})
|
||||
clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
|
||||
|
||||
assert %{limits: {1, 1}, name: :test_init, opts: [name: :test_init]} ==
|
||||
[name: @limiter_name]
|
||||
|
|
@ -54,8 +53,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
|
|||
scale = 80
|
||||
limit = 5
|
||||
|
||||
Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
|
||||
Config.put([:rate_limit, limiter_name], {scale, limit})
|
||||
clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
|
||||
clear_config([:rate_limit, limiter_name], {scale, limit})
|
||||
|
||||
plug_opts = RateLimiter.init(name: limiter_name)
|
||||
conn = build_conn(:get, "/")
|
||||
|
|
@ -86,8 +85,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
|
|||
test "`bucket_name` option overrides default bucket name" do
|
||||
limiter_name = :test_bucket_name
|
||||
|
||||
Config.put([:rate_limit, limiter_name], {1000, 5})
|
||||
Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
|
||||
clear_config([:rate_limit, limiter_name], {1000, 5})
|
||||
clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
|
||||
|
||||
base_bucket_name = "#{limiter_name}:group1"
|
||||
plug_opts = RateLimiter.init(name: limiter_name, bucket_name: base_bucket_name)
|
||||
|
|
@ -101,8 +100,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
|
|||
|
||||
test "`params` option allows different queries to be tracked independently" do
|
||||
limiter_name = :test_params
|
||||
Config.put([:rate_limit, limiter_name], {1000, 5})
|
||||
Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
|
||||
clear_config([:rate_limit, limiter_name], {1000, 5})
|
||||
clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
|
||||
|
||||
plug_opts = RateLimiter.init(name: limiter_name, params: ["id"])
|
||||
|
||||
|
|
@ -117,8 +116,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
|
|||
|
||||
test "it supports combination of options modifying bucket name" do
|
||||
limiter_name = :test_options_combo
|
||||
Config.put([:rate_limit, limiter_name], {1000, 5})
|
||||
Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
|
||||
clear_config([:rate_limit, limiter_name], {1000, 5})
|
||||
clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
|
||||
|
||||
base_bucket_name = "#{limiter_name}:group1"
|
||||
|
||||
|
|
@ -140,8 +139,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
|
|||
describe "unauthenticated users" do
|
||||
test "are restricted based on remote IP" do
|
||||
limiter_name = :test_unauthenticated
|
||||
Config.put([:rate_limit, limiter_name], [{1000, 5}, {1, 10}])
|
||||
Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
|
||||
clear_config([:rate_limit, limiter_name], [{1000, 5}, {1, 10}])
|
||||
clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
|
||||
|
||||
plug_opts = RateLimiter.init(name: limiter_name)
|
||||
|
||||
|
|
@ -180,8 +179,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
|
|||
|
||||
scale = 50
|
||||
limit = 5
|
||||
Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
|
||||
Config.put([:rate_limit, limiter_name], [{1000, 1}, {scale, limit}])
|
||||
clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
|
||||
clear_config([:rate_limit, limiter_name], [{1000, 1}, {scale, limit}])
|
||||
|
||||
plug_opts = RateLimiter.init(name: limiter_name)
|
||||
|
||||
|
|
@ -202,8 +201,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
|
|||
|
||||
test "different users are counted independently" do
|
||||
limiter_name = :test_authenticated2
|
||||
Config.put([:rate_limit, limiter_name], [{1, 10}, {1000, 5}])
|
||||
Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
|
||||
clear_config([:rate_limit, limiter_name], [{1, 10}, {1000, 5}])
|
||||
clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
|
||||
|
||||
plug_opts = RateLimiter.init(name: limiter_name)
|
||||
|
||||
|
|
@ -232,8 +231,8 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
|
|||
|
||||
test "doesn't crash due to a race condition when multiple requests are made at the same time and the bucket is not yet initialized" do
|
||||
limiter_name = :test_race_condition
|
||||
Pleroma.Config.put([:rate_limit, limiter_name], {1000, 5})
|
||||
Pleroma.Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
|
||||
clear_config([:rate_limit, limiter_name], {1000, 5})
|
||||
clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
|
||||
|
||||
opts = RateLimiter.init(name: limiter_name)
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ defmodule Pleroma.Web.Plugs.RemoteIpTest do
|
|||
)
|
||||
|
||||
test "disabled" do
|
||||
Pleroma.Config.put(RemoteIp, enabled: false)
|
||||
clear_config(RemoteIp, enabled: false)
|
||||
|
||||
%{remote_ip: remote_ip} = conn(:get, "/")
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ defmodule Pleroma.Web.Plugs.RemoteIpTest do
|
|||
end
|
||||
|
||||
test "custom headers" do
|
||||
Pleroma.Config.put(RemoteIp, enabled: true, headers: ["cf-connecting-ip"])
|
||||
clear_config(RemoteIp, enabled: true, headers: ["cf-connecting-ip"])
|
||||
|
||||
conn =
|
||||
conn(:get, "/")
|
||||
|
|
@ -73,7 +73,7 @@ defmodule Pleroma.Web.Plugs.RemoteIpTest do
|
|||
|
||||
refute conn.remote_ip == {1, 1, 1, 1}
|
||||
|
||||
Pleroma.Config.put([RemoteIp, :proxies], ["173.245.48.0/20"])
|
||||
clear_config([RemoteIp, :proxies], ["173.245.48.0/20"])
|
||||
|
||||
conn =
|
||||
conn(:get, "/")
|
||||
|
|
@ -84,7 +84,7 @@ defmodule Pleroma.Web.Plugs.RemoteIpTest do
|
|||
end
|
||||
|
||||
test "proxies set without CIDR format" do
|
||||
Pleroma.Config.put([RemoteIp, :proxies], ["173.245.48.1"])
|
||||
clear_config([RemoteIp, :proxies], ["173.245.48.1"])
|
||||
|
||||
conn =
|
||||
conn(:get, "/")
|
||||
|
|
@ -95,8 +95,8 @@ defmodule Pleroma.Web.Plugs.RemoteIpTest do
|
|||
end
|
||||
|
||||
test "proxies set `nonsensical` CIDR" do
|
||||
Pleroma.Config.put([RemoteIp, :reserved], ["127.0.0.0/8"])
|
||||
Pleroma.Config.put([RemoteIp, :proxies], ["10.0.0.3/24"])
|
||||
clear_config([RemoteIp, :reserved], ["127.0.0.0/8"])
|
||||
clear_config([RemoteIp, :proxies], ["10.0.0.3/24"])
|
||||
|
||||
conn =
|
||||
conn(:get, "/")
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ defmodule Pleroma.Web.Plugs.UserEnabledPlugTest do
|
|||
|
||||
test "with a user that's not confirmed and a config requiring confirmation, it removes that user",
|
||||
%{conn: conn} do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
clear_config([:instance, :account_activation_required], true)
|
||||
|
||||
user = insert(:user, is_confirmed: false)
|
||||
|
||||
|
|
|
|||
58
test/pleroma/web/plugs/user_tracking_plug_test.exs
Normal file
58
test/pleroma/web/plugs/user_tracking_plug_test.exs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Plugs.UserTrackingPlugTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Web.Plugs.UserTrackingPlug
|
||||
|
||||
test "updates last_active_at for a new user", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
assert is_nil(user.last_active_at)
|
||||
|
||||
test_started_at = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
|
||||
|
||||
%{assigns: %{user: user}} =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> UserTrackingPlug.call(%{})
|
||||
|
||||
assert user.last_active_at >= test_started_at
|
||||
assert user.last_active_at <= NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
|
||||
end
|
||||
|
||||
test "doesn't update last_active_at if it was updated recently", %{conn: conn} do
|
||||
last_active_at =
|
||||
NaiveDateTime.utc_now()
|
||||
|> NaiveDateTime.add(-:timer.hours(1), :millisecond)
|
||||
|> NaiveDateTime.truncate(:second)
|
||||
|
||||
user = insert(:user, %{last_active_at: last_active_at})
|
||||
|
||||
%{assigns: %{user: user}} =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> UserTrackingPlug.call(%{})
|
||||
|
||||
assert user.last_active_at == last_active_at
|
||||
end
|
||||
|
||||
test "skips updating last_active_at if user ID is nil", %{conn: conn} do
|
||||
%{assigns: %{user: user}} =
|
||||
conn
|
||||
|> assign(:user, %Pleroma.User{})
|
||||
|> UserTrackingPlug.call(%{})
|
||||
|
||||
assert is_nil(user.last_active_at)
|
||||
end
|
||||
|
||||
test "does nothing if user is not present", %{conn: conn} do
|
||||
%{assigns: assigns} = UserTrackingPlug.call(conn, %{})
|
||||
|
||||
refute Map.has_key?(assigns, :user)
|
||||
end
|
||||
end
|
||||
|
|
@ -5,7 +5,6 @@
|
|||
defmodule Pleroma.Web.RichMedia.HelpersTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.RichMedia.Helpers
|
||||
|
||||
|
|
@ -29,7 +28,7 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
|
|||
content_type: "text/markdown"
|
||||
})
|
||||
|
||||
Config.put([:rich_media, :enabled], true)
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
|
||||
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
||||
end
|
||||
|
|
@ -43,7 +42,7 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
|
|||
content_type: "text/markdown"
|
||||
})
|
||||
|
||||
Config.put([:rich_media, :enabled], true)
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
|
||||
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
||||
end
|
||||
|
|
@ -57,7 +56,7 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
|
|||
content_type: "text/markdown"
|
||||
})
|
||||
|
||||
Config.put([:rich_media, :enabled], true)
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
|
||||
assert %{page_url: "https://example.com/ogp", rich_media: _} =
|
||||
Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
||||
|
|
@ -74,7 +73,7 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
|
|||
{:ok, activity4} = CommonAPI.post(user, %{status: "https://192.168.10.40/notice/9kCP7V"})
|
||||
{:ok, activity5} = CommonAPI.post(user, %{status: "https://pleroma.local/notice/9kCP7V"})
|
||||
|
||||
Config.put([:rich_media, :enabled], true)
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
|
||||
assert %{} = Helpers.fetch_data_for_activity(activity)
|
||||
assert %{} = Helpers.fetch_data_for_activity(activity2)
|
||||
|
|
|
|||
|
|
@ -510,7 +510,7 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
|
||||
describe "thread_containment/2" do
|
||||
test "it filters to user if recipients invalid and thread containment is enabled" do
|
||||
Pleroma.Config.put([:instance, :skip_thread_containment], false)
|
||||
clear_config([:instance, :skip_thread_containment], false)
|
||||
author = insert(:user)
|
||||
%{user: user, token: oauth_token} = oauth_access(["read"])
|
||||
User.follow(user, author, :follow_accept)
|
||||
|
|
@ -531,7 +531,7 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
end
|
||||
|
||||
test "it sends message if recipients invalid and thread containment is disabled" do
|
||||
Pleroma.Config.put([:instance, :skip_thread_containment], true)
|
||||
clear_config([:instance, :skip_thread_containment], true)
|
||||
author = insert(:user)
|
||||
%{user: user, token: oauth_token} = oauth_access(["read"])
|
||||
User.follow(user, author, :follow_accept)
|
||||
|
|
@ -553,7 +553,7 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
end
|
||||
|
||||
test "it sends message if recipients invalid and thread containment is enabled but user's thread containment is disabled" do
|
||||
Pleroma.Config.put([:instance, :skip_thread_containment], false)
|
||||
clear_config([:instance, :skip_thread_containment], false)
|
||||
author = insert(:user)
|
||||
user = insert(:user, skip_thread_containment: true)
|
||||
%{token: oauth_token} = oauth_access(["read"], user: user)
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
|
|||
end
|
||||
|
||||
test "returns error when user is blocked", %{conn: conn} do
|
||||
Pleroma.Config.put([:user, :deny_follow_blocked], true)
|
||||
clear_config([:user, :deny_follow_blocked], true)
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
|
|
@ -365,7 +365,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
|
|||
end
|
||||
|
||||
test "returns error when user is blocked", %{conn: conn} do
|
||||
Pleroma.Config.put([:user, :deny_follow_blocked], true)
|
||||
clear_config([:user, :deny_follow_blocked], true)
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
{:ok, _user_block} = Pleroma.User.block(user2, user)
|
||||
|
|
|
|||
|
|
@ -46,12 +46,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
end
|
||||
|
||||
test "it sends confirmation email if :account_activation_required is specified in instance config" do
|
||||
setting = Pleroma.Config.get([:instance, :account_activation_required])
|
||||
|
||||
unless setting do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
|
||||
end
|
||||
clear_config([:instance, :account_activation_required], true)
|
||||
|
||||
data = %{
|
||||
:username => "lain",
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
|
||||
|
|
@ -66,7 +65,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
}
|
||||
]
|
||||
|
||||
Config.put(:frontend_configurations, config)
|
||||
clear_config(:frontend_configurations, config)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -99,7 +98,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
setup do: clear_config([:instance, :healthcheck])
|
||||
|
||||
test "returns 503 when healthcheck disabled", %{conn: conn} do
|
||||
Config.put([:instance, :healthcheck], false)
|
||||
clear_config([:instance, :healthcheck], false)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -110,7 +109,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
end
|
||||
|
||||
test "returns 200 when healthcheck enabled and all ok", %{conn: conn} do
|
||||
Config.put([:instance, :healthcheck], true)
|
||||
clear_config([:instance, :healthcheck], true)
|
||||
|
||||
with_mock Pleroma.Healthcheck,
|
||||
system_info: fn -> %Pleroma.Healthcheck{healthy: true} end do
|
||||
|
|
@ -130,7 +129,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
end
|
||||
|
||||
test "returns 503 when healthcheck enabled and health is false", %{conn: conn} do
|
||||
Config.put([:instance, :healthcheck], true)
|
||||
clear_config([:instance, :healthcheck], true)
|
||||
|
||||
with_mock Pleroma.Healthcheck,
|
||||
system_info: fn -> %Pleroma.Healthcheck{healthy: false} end do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue