2019-08-13 14:55:13 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 13:38:50 -07:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2019-08-13 14:55:13 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
|
|
|
|
alias Pleroma.Web.ActivityPub.MRF.VocabularyPolicy
|
|
|
|
|
|
|
|
describe "accept" do
|
2020-03-20 09:33:00 -06:00
|
|
|
setup do: clear_config([:mrf_vocabulary, :accept])
|
2019-08-19 09:34:29 -06:00
|
|
|
|
2019-08-13 14:55:13 -06:00
|
|
|
test "it accepts based on parent activity type" do
|
2021-01-26 10:58:43 -07:00
|
|
|
clear_config([:mrf_vocabulary, :accept], ["Like"])
|
2019-08-13 14:55:13 -06:00
|
|
|
|
|
|
|
message = %{
|
|
|
|
"type" => "Like",
|
|
|
|
"object" => "whatever"
|
|
|
|
}
|
|
|
|
|
|
|
|
{:ok, ^message} = VocabularyPolicy.filter(message)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it accepts based on child object type" do
|
2021-01-26 10:58:43 -07:00
|
|
|
clear_config([:mrf_vocabulary, :accept], ["Create", "Note"])
|
2019-08-13 14:55:13 -06:00
|
|
|
|
|
|
|
message = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"object" => %{
|
|
|
|
"type" => "Note",
|
|
|
|
"content" => "whatever"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{:ok, ^message} = VocabularyPolicy.filter(message)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it does not accept disallowed child objects" do
|
2021-01-26 10:58:43 -07:00
|
|
|
clear_config([:mrf_vocabulary, :accept], ["Create", "Note"])
|
2019-08-13 14:55:13 -06:00
|
|
|
|
|
|
|
message = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"object" => %{
|
|
|
|
"type" => "Article",
|
|
|
|
"content" => "whatever"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-13 07:47:13 -06:00
|
|
|
{:reject, _} = VocabularyPolicy.filter(message)
|
2019-08-13 14:55:13 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it does not accept disallowed parent types" do
|
2021-01-26 10:58:43 -07:00
|
|
|
clear_config([:mrf_vocabulary, :accept], ["Announce", "Note"])
|
2019-08-13 14:55:13 -06:00
|
|
|
|
|
|
|
message = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"object" => %{
|
|
|
|
"type" => "Note",
|
|
|
|
"content" => "whatever"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-13 07:47:13 -06:00
|
|
|
{:reject, _} = VocabularyPolicy.filter(message)
|
2019-08-13 14:55:13 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "reject" do
|
2020-03-20 09:33:00 -06:00
|
|
|
setup do: clear_config([:mrf_vocabulary, :reject])
|
2019-08-19 09:34:29 -06:00
|
|
|
|
2019-08-13 14:55:13 -06:00
|
|
|
test "it rejects based on parent activity type" do
|
2021-01-26 10:58:43 -07:00
|
|
|
clear_config([:mrf_vocabulary, :reject], ["Like"])
|
2019-08-13 14:55:13 -06:00
|
|
|
|
|
|
|
message = %{
|
|
|
|
"type" => "Like",
|
|
|
|
"object" => "whatever"
|
|
|
|
}
|
|
|
|
|
2020-07-13 07:47:13 -06:00
|
|
|
{:reject, _} = VocabularyPolicy.filter(message)
|
2019-08-13 14:55:13 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it rejects based on child object type" do
|
2021-01-26 10:58:43 -07:00
|
|
|
clear_config([:mrf_vocabulary, :reject], ["Note"])
|
2019-08-13 14:55:13 -06:00
|
|
|
|
|
|
|
message = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"object" => %{
|
|
|
|
"type" => "Note",
|
|
|
|
"content" => "whatever"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-13 07:47:13 -06:00
|
|
|
{:reject, _} = VocabularyPolicy.filter(message)
|
2019-08-13 14:55:13 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it passes through objects that aren't disallowed" do
|
2021-01-26 10:58:43 -07:00
|
|
|
clear_config([:mrf_vocabulary, :reject], ["Like"])
|
2019-08-13 14:55:13 -06:00
|
|
|
|
|
|
|
message = %{
|
|
|
|
"type" => "Announce",
|
|
|
|
"object" => "whatever"
|
|
|
|
}
|
|
|
|
|
|
|
|
{:ok, ^message} = VocabularyPolicy.filter(message)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|