InstanceView: lint tests
This commit is contained in:
parent
93fe0f5ab5
commit
9912b2d16a
1 changed files with 136 additions and 71 deletions
|
|
@ -27,16 +27,23 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
|
||||||
:polls
|
:polls
|
||||||
]
|
]
|
||||||
|
|
||||||
@configuration2_keys @configuration_keys ++ [
|
@configuration2_keys @configuration_keys ++
|
||||||
:urls,
|
[
|
||||||
:vapid,
|
:urls,
|
||||||
:translation,
|
:vapid,
|
||||||
:timelines_access
|
:translation,
|
||||||
]
|
:timelines_access
|
||||||
|
]
|
||||||
|
|
||||||
# Used for filtering out values from configuration.json render in configuration2.json render
|
# Used for filtering out values from configuration.json render in configuration2.json render
|
||||||
@configuration2_filter [
|
@configuration2_filter [
|
||||||
{:accounts, [:max_pinned_statuses, :max_profile_fields, :profile_field_name_limit, :profile_field_value_limit]},
|
{:accounts,
|
||||||
|
[
|
||||||
|
:max_pinned_statuses,
|
||||||
|
:max_profile_fields,
|
||||||
|
:profile_field_name_limit,
|
||||||
|
:profile_field_value_limit
|
||||||
|
]},
|
||||||
{:statuses, [:characters_reserved_per_url]},
|
{:statuses, [:characters_reserved_per_url]},
|
||||||
{:urls, [:streaming, :status]},
|
{:urls, [:streaming, :status]},
|
||||||
{:vapid, [:public_key]},
|
{:vapid, [:public_key]},
|
||||||
|
|
@ -51,48 +58,59 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
|
||||||
]
|
]
|
||||||
|
|
||||||
@pleroma_configuration2_filter [
|
@pleroma_configuration2_filter [
|
||||||
{:metadata, [:avatar_upload_limit, :background_upload_limit, :banner_upload_limit, :background_image, :chat_limit, :description_limit, :shout_limit]}
|
{:metadata,
|
||||||
|
[
|
||||||
|
:avatar_upload_limit,
|
||||||
|
:background_upload_limit,
|
||||||
|
:banner_upload_limit,
|
||||||
|
:background_image,
|
||||||
|
:chat_limit,
|
||||||
|
:description_limit,
|
||||||
|
:shout_limit
|
||||||
|
]}
|
||||||
]
|
]
|
||||||
|
|
||||||
@show_keys @common_information_keys ++ [
|
@show_keys @common_information_keys ++
|
||||||
:uri,
|
[
|
||||||
:description,
|
:uri,
|
||||||
:short_description,
|
:description,
|
||||||
:email,
|
:short_description,
|
||||||
:urls,
|
:email,
|
||||||
:stats,
|
:urls,
|
||||||
:thumbnail,
|
:stats,
|
||||||
:registrations,
|
:thumbnail,
|
||||||
:approval_required,
|
:registrations,
|
||||||
:contact_account,
|
:approval_required,
|
||||||
:configuration,
|
:contact_account,
|
||||||
# Extra (not present in Mastodon)
|
:configuration,
|
||||||
:max_toot_chars,
|
# Extra (not present in Mastodon)
|
||||||
:max_media_attachments,
|
:max_toot_chars,
|
||||||
:poll_limits,
|
:max_media_attachments,
|
||||||
:upload_limit,
|
:poll_limits,
|
||||||
:avatar_upload_limit,
|
:upload_limit,
|
||||||
:background_upload_limit,
|
:avatar_upload_limit,
|
||||||
:banner_upload_limit,
|
:background_upload_limit,
|
||||||
:background_image,
|
:banner_upload_limit,
|
||||||
:shout_limit,
|
:background_image,
|
||||||
:description_limit,
|
:shout_limit,
|
||||||
:chat_limit,
|
:description_limit,
|
||||||
:pleroma
|
:chat_limit,
|
||||||
]
|
:pleroma
|
||||||
|
]
|
||||||
|
|
||||||
@show2_keys @common_information_keys ++ [
|
@show2_keys @common_information_keys ++
|
||||||
:domain,
|
[
|
||||||
:source_url,
|
:domain,
|
||||||
:description,
|
:source_url,
|
||||||
:usage,
|
:description,
|
||||||
:thumbnail,
|
:usage,
|
||||||
:configuration,
|
:thumbnail,
|
||||||
:registrations,
|
:configuration,
|
||||||
:contact,
|
:registrations,
|
||||||
# Extra (not present in Mastodon)
|
:contact,
|
||||||
:pleroma
|
# Extra (not present in Mastodon)
|
||||||
]
|
:pleroma
|
||||||
|
]
|
||||||
|
|
||||||
@features [
|
@features [
|
||||||
"pleroma_api",
|
"pleroma_api",
|
||||||
|
|
@ -158,7 +176,9 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
|
||||||
languages: ["en", "cs"],
|
languages: ["en", "cs"],
|
||||||
rules: InstanceView.render("rules.json", %{}),
|
rules: InstanceView.render("rules.json", %{}),
|
||||||
title: "test title",
|
title: "test title",
|
||||||
version: InstanceView.mastodon_api_level() <> " (compatible; #{Pleroma.Application.named_version()})"
|
version:
|
||||||
|
InstanceView.mastodon_api_level() <>
|
||||||
|
" (compatible; #{Pleroma.Application.named_version()})"
|
||||||
}
|
}
|
||||||
|
|
||||||
Map.equal?(expected, filtered_info)
|
Map.equal?(expected, filtered_info)
|
||||||
|
|
@ -194,7 +214,9 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
|
||||||
|
|
||||||
defp check_configuration(info) do
|
defp check_configuration(info) do
|
||||||
configuration = info[:configuration]
|
configuration = info[:configuration]
|
||||||
filtered_configuration = Map.reject(configuration, fn {key, _value} -> key not in @configuration_keys end)
|
|
||||||
|
filtered_configuration =
|
||||||
|
Map.reject(configuration, fn {key, _value} -> key not in @configuration_keys end)
|
||||||
|
|
||||||
expected = %{
|
expected = %{
|
||||||
accounts: %{
|
accounts: %{
|
||||||
|
|
@ -222,6 +244,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
|
||||||
|
|
||||||
defp check_configuration2(info) do
|
defp check_configuration2(info) do
|
||||||
configuration = info[:configuration]
|
configuration = info[:configuration]
|
||||||
|
|
||||||
filtered_configuration =
|
filtered_configuration =
|
||||||
configuration
|
configuration
|
||||||
|> Map.reject(fn {key, _value} -> key not in @configuration2_keys end)
|
|> Map.reject(fn {key, _value} -> key not in @configuration2_keys end)
|
||||||
|
|
@ -274,11 +297,16 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
|
||||||
|
|
||||||
defp check_pleroma_configuration(info) do
|
defp check_pleroma_configuration(info) do
|
||||||
configuration = info[:pleroma]
|
configuration = info[:pleroma]
|
||||||
filtered_configuration = Map.reject(configuration, fn {key, _value} -> key not in @pleroma_configuration_keys end)
|
|
||||||
|
filtered_configuration =
|
||||||
|
Map.reject(configuration, fn {key, _value} -> key not in @pleroma_configuration_keys end)
|
||||||
|
|
||||||
# Tested elsewhere already
|
# Tested elsewhere already
|
||||||
metadata = Map.fetch!(filtered_configuration, :metadata)
|
metadata = Map.fetch!(filtered_configuration, :metadata)
|
||||||
filtered_metadata = Map.reject(metadata, fn {key, _value} -> key in [:features, :federation] end)
|
|
||||||
|
filtered_metadata =
|
||||||
|
Map.reject(metadata, fn {key, _value} -> key in [:features, :federation] end)
|
||||||
|
|
||||||
filtered_configuration = %{filtered_configuration | metadata: filtered_metadata}
|
filtered_configuration = %{filtered_configuration | metadata: filtered_metadata}
|
||||||
|
|
||||||
expected = %{
|
expected = %{
|
||||||
|
|
@ -293,19 +321,18 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
|
||||||
post_formats: ["text/plain"],
|
post_formats: ["text/plain"],
|
||||||
birthday_required: true,
|
birthday_required: true,
|
||||||
birthday_min_age: 1,
|
birthday_min_age: 1,
|
||||||
translation:
|
translation: %{
|
||||||
%{
|
source_languages: ["en", "pl"],
|
||||||
source_languages: ["en", "pl"],
|
target_languages: ["en", "pl"]
|
||||||
target_languages: ["en", "pl"]
|
},
|
||||||
},
|
|
||||||
base_urls: %{
|
base_urls: %{
|
||||||
media_proxy: "https://mediaproxy.example.com",
|
media_proxy: "https://mediaproxy.example.com",
|
||||||
upload: "https://upload.example.com"
|
upload: "https://upload.example.com"
|
||||||
},
|
},
|
||||||
markup: %{
|
markup: %{
|
||||||
allow_inline_images: true,
|
allow_inline_images: true,
|
||||||
allow_headings: true,
|
allow_headings: true,
|
||||||
allow_tables: true
|
allow_tables: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
stats: %{mau: Pleroma.User.active_user_count()},
|
stats: %{mau: Pleroma.User.active_user_count()},
|
||||||
|
|
@ -317,11 +344,16 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
|
||||||
|
|
||||||
defp check_pleroma_configuration2(info) do
|
defp check_pleroma_configuration2(info) do
|
||||||
configuration = info[:pleroma]
|
configuration = info[:pleroma]
|
||||||
filtered_configuration = Map.reject(configuration, fn {key, _value} -> key not in @pleroma_configuration_keys end)
|
|
||||||
|
filtered_configuration =
|
||||||
|
Map.reject(configuration, fn {key, _value} -> key not in @pleroma_configuration_keys end)
|
||||||
|
|
||||||
# Tested elsewhere already
|
# Tested elsewhere already
|
||||||
metadata = Map.fetch!(filtered_configuration, :metadata)
|
metadata = Map.fetch!(filtered_configuration, :metadata)
|
||||||
filtered_metadata = Map.reject(metadata, fn {key, _value} -> key in [:features, :federation] end)
|
|
||||||
|
filtered_metadata =
|
||||||
|
Map.reject(metadata, fn {key, _value} -> key in [:features, :federation] end)
|
||||||
|
|
||||||
filtered_configuration =
|
filtered_configuration =
|
||||||
%{filtered_configuration | metadata: filtered_metadata}
|
%{filtered_configuration | metadata: filtered_metadata}
|
||||||
|> filter_render(@pleroma_configuration2_filter, %{})
|
|> filter_render(@pleroma_configuration2_filter, %{})
|
||||||
|
|
@ -386,14 +418,26 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
|
||||||
|
|
||||||
output = InstanceView.federation()
|
output = InstanceView.federation()
|
||||||
assert %{quarantined_instances: ["quarantine.example.com"]} = output
|
assert %{quarantined_instances: ["quarantine.example.com"]} = output
|
||||||
assert %{quarantined_instances_info: %{"quarantined_instances" => %{"quarantine.example.com" => %{"reason" => "crimes"}}}} = output
|
|
||||||
|
assert %{
|
||||||
|
quarantined_instances_info: %{
|
||||||
|
"quarantined_instances" => %{"quarantine.example.com" => %{"reason" => "crimes"}}
|
||||||
|
}
|
||||||
|
} = output
|
||||||
end
|
end
|
||||||
|
|
||||||
test "rejected instances" do
|
test "rejected instances" do
|
||||||
clear_config([:instance, :rejected_instances], [{"rejected.example.com", "not enough #cofe posting"}])
|
clear_config([:instance, :rejected_instances], [
|
||||||
|
{"rejected.example.com", "not enough #cofe posting"}
|
||||||
|
])
|
||||||
|
|
||||||
output = InstanceView.federation()
|
output = InstanceView.federation()
|
||||||
assert %{rejected_instances: %{"rejected.example.com" => %{"reason" => "not enough #cofe posting"}}} = output
|
|
||||||
|
assert %{
|
||||||
|
rejected_instances: %{
|
||||||
|
"rejected.example.com" => %{"reason" => "not enough #cofe posting"}
|
||||||
|
}
|
||||||
|
} = output
|
||||||
end
|
end
|
||||||
|
|
||||||
test "federating" do
|
test "federating" do
|
||||||
|
|
@ -405,29 +449,39 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
|
||||||
|
|
||||||
test "transparency" do
|
test "transparency" do
|
||||||
clear_config([:instance, :quarantined_instances], [{"quarantine.example.com", "crimes"}])
|
clear_config([:instance, :quarantined_instances], [{"quarantine.example.com", "crimes"}])
|
||||||
clear_config([:instance, :rejected_instances], [{"rejected.example.com", "not enough #cofe posting"}])
|
|
||||||
clear_config([:instance, :federating], true)
|
clear_config([:instance, :federating], true)
|
||||||
clear_config([:mrf, :transparency], false)
|
clear_config([:mrf, :transparency], false)
|
||||||
|
|
||||||
|
clear_config([:instance, :rejected_instances], [
|
||||||
|
{"rejected.example.com", "not enough #cofe posting"}
|
||||||
|
])
|
||||||
|
|
||||||
output = InstanceView.federation()
|
output = InstanceView.federation()
|
||||||
assert %{enabled: true} == output
|
assert %{enabled: true} == output
|
||||||
end
|
end
|
||||||
|
|
||||||
test "MRFs" do
|
test "MRFs" do
|
||||||
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
|
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
|
||||||
clear_config([:mrf, :transparency_exclusions], [{"media1.example.com", "the Fediverse doesn't need to know"}])
|
|
||||||
clear_config([:mrf_simple, :media_removal], [{"media1.example.com", "NSFW"}, {"media2.example.com", "usual suspects"}])
|
|
||||||
clear_config([:mrf_simple, :reject], [{"rejected.example.com", "not enough #cofe posting"}])
|
clear_config([:mrf_simple, :reject], [{"rejected.example.com", "not enough #cofe posting"}])
|
||||||
|
|
||||||
|
clear_config([:mrf, :transparency_exclusions], [
|
||||||
|
{"media1.example.com", "the Fediverse doesn't need to know"}
|
||||||
|
])
|
||||||
|
|
||||||
|
clear_config([:mrf_simple, :media_removal], [
|
||||||
|
{"media1.example.com", "NSFW"},
|
||||||
|
{"media2.example.com", "usual suspects"}
|
||||||
|
])
|
||||||
|
|
||||||
output = InstanceView.federation()
|
output = InstanceView.federation()
|
||||||
|
|
||||||
expected = %{
|
expected = %{
|
||||||
mrf_simple: %{
|
mrf_simple: %{
|
||||||
reject: ["rejected.example.com"],
|
reject: ["rejected.example.com"],
|
||||||
media_removal: ["media2.example.com"],
|
media_removal: ["media2.example.com"]
|
||||||
},
|
},
|
||||||
mrf_hashtag: %{
|
mrf_hashtag: %{
|
||||||
sensitive: ["nsfw"],
|
sensitive: ["nsfw"]
|
||||||
},
|
},
|
||||||
exclusions: true,
|
exclusions: true,
|
||||||
mrf_policies: ["SimplePolicy", "HashtagPolicy"],
|
mrf_policies: ["SimplePolicy", "HashtagPolicy"],
|
||||||
|
|
@ -569,10 +623,21 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
|
||||||
describe "render domain_blocks.json" do
|
describe "render domain_blocks.json" do
|
||||||
setup do
|
setup do
|
||||||
clear_config([:mrf, :transparency], true)
|
clear_config([:mrf, :transparency], true)
|
||||||
clear_config([:mrf, :transparency_exclusions], [{"removed1.example.com", "the Fediverse doesn't need to know"}])
|
|
||||||
clear_config([:mrf_simple, :media_removal], [{"media1.example.com", "NSFW"}])
|
clear_config([:mrf_simple, :media_removal], [{"media1.example.com", "NSFW"}])
|
||||||
clear_config([:mrf_simple, :reject], [{"rejected.example.com", "not enough #cofe posting"}, {"rejected-without-reason.example.com", ""}])
|
|
||||||
clear_config([:mrf_simple, :federated_timeline_removal], [{"removed1.example.com", "spam"}, {"removed2.example.com", "more spam"}])
|
clear_config([:mrf, :transparency_exclusions], [
|
||||||
|
{"removed1.example.com", "the Fediverse doesn't need to know"}
|
||||||
|
])
|
||||||
|
|
||||||
|
clear_config([:mrf_simple, :reject], [
|
||||||
|
{"rejected.example.com", "not enough #cofe posting"},
|
||||||
|
{"rejected-without-reason.example.com", ""}
|
||||||
|
])
|
||||||
|
|
||||||
|
clear_config([:mrf_simple, :federated_timeline_removal], [
|
||||||
|
{"removed1.example.com", "spam"},
|
||||||
|
{"removed2.example.com", "more spam"}
|
||||||
|
])
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue