Merge remote-tracking branch 'origin/develop' into fix-attachment-dimensions
This commit is contained in:
commit
2c96668a2c
3836 changed files with 4191 additions and 12264 deletions
|
|
@ -11,6 +11,183 @@ defmodule Pleroma.Config.DeprecationWarningsTest do
|
|||
alias Pleroma.Config
|
||||
alias Pleroma.Config.DeprecationWarnings
|
||||
|
||||
describe "simple policy tuples" do
|
||||
test "gives warning when there are still strings" do
|
||||
clear_config([:mrf_simple],
|
||||
media_removal: ["some.removal"],
|
||||
media_nsfw: ["some.nsfw"],
|
||||
federated_timeline_removal: ["some.tl.removal"],
|
||||
report_removal: ["some.report.removal"],
|
||||
reject: ["some.reject"],
|
||||
followers_only: ["some.followers.only"],
|
||||
accept: ["some.accept"],
|
||||
avatar_removal: ["some.avatar.removal"],
|
||||
banner_removal: ["some.banner.removal"],
|
||||
reject_deletes: ["some.reject.deletes"]
|
||||
)
|
||||
|
||||
assert capture_log(fn -> DeprecationWarnings.check_simple_policy_tuples() end) =~
|
||||
"""
|
||||
!!!DEPRECATION WARNING!!!
|
||||
Your config is using strings in the SimplePolicy configuration instead of tuples. They should work for now, but you are advised to change to the new configuration to prevent possible issues later:
|
||||
|
||||
```
|
||||
config :pleroma, :mrf_simple,
|
||||
media_removal: ["instance.tld"],
|
||||
media_nsfw: ["instance.tld"],
|
||||
federated_timeline_removal: ["instance.tld"],
|
||||
report_removal: ["instance.tld"],
|
||||
reject: ["instance.tld"],
|
||||
followers_only: ["instance.tld"],
|
||||
accept: ["instance.tld"],
|
||||
avatar_removal: ["instance.tld"],
|
||||
banner_removal: ["instance.tld"],
|
||||
reject_deletes: ["instance.tld"]
|
||||
```
|
||||
|
||||
Is now
|
||||
|
||||
|
||||
```
|
||||
config :pleroma, :mrf_simple,
|
||||
media_removal: [{"instance.tld", "Reason for media removal"}],
|
||||
media_nsfw: [{"instance.tld", "Reason for media nsfw"}],
|
||||
federated_timeline_removal: [{"instance.tld", "Reason for federated timeline removal"}],
|
||||
report_removal: [{"instance.tld", "Reason for report removal"}],
|
||||
reject: [{"instance.tld", "Reason for reject"}],
|
||||
followers_only: [{"instance.tld", "Reason for followers only"}],
|
||||
accept: [{"instance.tld", "Reason for accept"}],
|
||||
avatar_removal: [{"instance.tld", "Reason for avatar removal"}],
|
||||
banner_removal: [{"instance.tld", "Reason for banner removal"}],
|
||||
reject_deletes: [{"instance.tld", "Reason for reject deletes"}]
|
||||
```
|
||||
"""
|
||||
end
|
||||
|
||||
test "transforms config to tuples" do
|
||||
clear_config([:mrf_simple],
|
||||
media_removal: ["some.removal", {"some.other.instance", "Some reason"}]
|
||||
)
|
||||
|
||||
expected_config = [
|
||||
{:media_removal, [{"some.removal", ""}, {"some.other.instance", "Some reason"}]}
|
||||
]
|
||||
|
||||
capture_log(fn -> DeprecationWarnings.warn() end)
|
||||
|
||||
assert Config.get([:mrf_simple]) == expected_config
|
||||
end
|
||||
|
||||
test "doesn't give a warning with correct config" do
|
||||
clear_config([:mrf_simple],
|
||||
media_removal: [{"some.removal", ""}, {"some.other.instance", "Some reason"}]
|
||||
)
|
||||
|
||||
assert capture_log(fn -> DeprecationWarnings.check_simple_policy_tuples() end) == ""
|
||||
end
|
||||
end
|
||||
|
||||
describe "quarantined_instances tuples" do
|
||||
test "gives warning when there are still strings" do
|
||||
clear_config([:instance, :quarantined_instances], [
|
||||
{"domain.com", "some reason"},
|
||||
"somedomain.tld"
|
||||
])
|
||||
|
||||
assert capture_log(fn -> DeprecationWarnings.check_quarantined_instances_tuples() end) =~
|
||||
"""
|
||||
!!!DEPRECATION WARNING!!!
|
||||
Your config is using strings in the quarantined_instances configuration instead of tuples. They should work for now, but you are advised to change to the new configuration to prevent possible issues later:
|
||||
|
||||
```
|
||||
config :pleroma, :instance,
|
||||
quarantined_instances: ["instance.tld"]
|
||||
```
|
||||
|
||||
Is now
|
||||
|
||||
|
||||
```
|
||||
config :pleroma, :instance,
|
||||
quarantined_instances: [{"instance.tld", "Reason for quarantine"}]
|
||||
```
|
||||
"""
|
||||
end
|
||||
|
||||
test "transforms config to tuples" do
|
||||
clear_config([:instance, :quarantined_instances], [
|
||||
{"domain.com", "some reason"},
|
||||
"some.tld"
|
||||
])
|
||||
|
||||
expected_config = [{"domain.com", "some reason"}, {"some.tld", ""}]
|
||||
|
||||
capture_log(fn -> DeprecationWarnings.warn() end)
|
||||
|
||||
assert Config.get([:instance, :quarantined_instances]) == expected_config
|
||||
end
|
||||
|
||||
test "doesn't give a warning with correct config" do
|
||||
clear_config([:instance, :quarantined_instances], [
|
||||
{"domain.com", "some reason"},
|
||||
{"some.tld", ""}
|
||||
])
|
||||
|
||||
assert capture_log(fn -> DeprecationWarnings.check_quarantined_instances_tuples() end) == ""
|
||||
end
|
||||
end
|
||||
|
||||
describe "transparency_exclusions tuples" do
|
||||
test "gives warning when there are still strings" do
|
||||
clear_config([:mrf, :transparency_exclusions], [
|
||||
{"domain.com", "some reason"},
|
||||
"somedomain.tld"
|
||||
])
|
||||
|
||||
assert capture_log(fn -> DeprecationWarnings.check_transparency_exclusions_tuples() end) =~
|
||||
"""
|
||||
!!!DEPRECATION WARNING!!!
|
||||
Your config is using strings in the transparency_exclusions configuration instead of tuples. They should work for now, but you are advised to change to the new configuration to prevent possible issues later:
|
||||
|
||||
```
|
||||
config :pleroma, :mrf,
|
||||
transparency_exclusions: ["instance.tld"]
|
||||
```
|
||||
|
||||
Is now
|
||||
|
||||
|
||||
```
|
||||
config :pleroma, :mrf,
|
||||
transparency_exclusions: [{"instance.tld", "Reason to exlude transparency"}]
|
||||
```
|
||||
"""
|
||||
end
|
||||
|
||||
test "transforms config to tuples" do
|
||||
clear_config([:mrf, :transparency_exclusions], [
|
||||
{"domain.com", "some reason"},
|
||||
"some.tld"
|
||||
])
|
||||
|
||||
expected_config = [{"domain.com", "some reason"}, {"some.tld", ""}]
|
||||
|
||||
capture_log(fn -> DeprecationWarnings.warn() end)
|
||||
|
||||
assert Config.get([:mrf, :transparency_exclusions]) == expected_config
|
||||
end
|
||||
|
||||
test "doesn't give a warning with correct config" do
|
||||
clear_config([:mrf, :transparency_exclusions], [
|
||||
{"domain.com", "some reason"},
|
||||
{"some.tld", ""}
|
||||
])
|
||||
|
||||
assert capture_log(fn -> DeprecationWarnings.check_transparency_exclusions_tuples() end) ==
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
test "check_old_mrf_config/0" do
|
||||
clear_config([:instance, :rewrite_policy], [])
|
||||
clear_config([:instance, :mrf_transparency], true)
|
||||
|
|
|
|||
|
|
@ -27,11 +27,7 @@ defmodule Pleroma.Emails.AdminEmailTest do
|
|||
assert res.subject == "#{config[:name]} Report"
|
||||
|
||||
assert res.html_body ==
|
||||
"<p>Reported by: <a href=\"#{reporter_url}\">#{reporter.nickname}</a></p>\n<p>Reported Account: <a href=\"#{
|
||||
account_url
|
||||
}\">#{account.nickname}</a></p>\n<p>Comment: Test comment\n<p> Statuses:\n <ul>\n <li><a href=\"#{
|
||||
status_url
|
||||
}\">#{status_url}</li>\n </ul>\n</p>\n\n<p>\n<a href=\"http://localhost:4001/pleroma/admin/#/reports/index\">View Reports in AdminFE</a>\n"
|
||||
"<p>Reported by: <a href=\"#{reporter_url}\">#{reporter.nickname}</a></p>\n<p>Reported Account: <a href=\"#{account_url}\">#{account.nickname}</a></p>\n<p>Comment: Test comment\n<p> Statuses:\n <ul>\n <li><a href=\"#{status_url}\">#{status_url}</li>\n </ul>\n</p>\n\n<p>\n<a href=\"http://localhost:4001/pleroma/admin/#/reports/index\">View Reports in AdminFE</a>\n"
|
||||
end
|
||||
|
||||
test "it works when the reporter is a remote user without email" do
|
||||
|
|
|
|||
|
|
@ -151,13 +151,7 @@ defmodule Pleroma.FormatterTest do
|
|||
assert length(mentions) == 3
|
||||
|
||||
expected_text =
|
||||
~s(<span class="h-card"><a class="u-url mention" data-user="#{gsimg.id}" href="#{
|
||||
gsimg.ap_id
|
||||
}" rel="ugc">@<span>gsimg</span></a></span> According to <span class="h-card"><a class="u-url mention" data-user="#{
|
||||
archaeme.id
|
||||
}" href="#{"https://archeme/@archa_eme_"}" rel="ugc">@<span>archa_eme_</span></a></span>, that is @daggsy. Also hello <span class="h-card"><a class="u-url mention" data-user="#{
|
||||
archaeme_remote.id
|
||||
}" href="#{archaeme_remote.ap_id}" rel="ugc">@<span>archaeme</span></a></span>)
|
||||
~s(<span class="h-card"><a class="u-url mention" data-user="#{gsimg.id}" href="#{gsimg.ap_id}" rel="ugc">@<span>gsimg</span></a></span> According to <span class="h-card"><a class="u-url mention" data-user="#{archaeme.id}" href="#{"https://archeme/@archa_eme_"}" rel="ugc">@<span>archa_eme_</span></a></span>, that is @daggsy. Also hello <span class="h-card"><a class="u-url mention" data-user="#{archaeme_remote.id}" href="#{archaeme_remote.ap_id}" rel="ugc">@<span>archaeme</span></a></span>)
|
||||
|
||||
assert expected_text == text
|
||||
end
|
||||
|
|
@ -172,9 +166,7 @@ defmodule Pleroma.FormatterTest do
|
|||
assert length(mentions) == 1
|
||||
|
||||
expected_text =
|
||||
~s(<span class="h-card"><a class="u-url mention" data-user="#{mike.id}" href="#{
|
||||
mike.ap_id
|
||||
}" rel="ugc">@<span>mike</span></a></span> test)
|
||||
~s(<span class="h-card"><a class="u-url mention" data-user="#{mike.id}" href="#{mike.ap_id}" rel="ugc">@<span>mike</span></a></span> test)
|
||||
|
||||
assert expected_text == text
|
||||
end
|
||||
|
|
@ -210,13 +202,7 @@ defmodule Pleroma.FormatterTest do
|
|||
assert mentions == [{"@#{user.nickname}", user}, {"@#{other_user.nickname}", other_user}]
|
||||
|
||||
assert expected_text ==
|
||||
~s(<span class="h-card"><a class="u-url mention" data-user="#{user.id}" href="#{
|
||||
user.ap_id
|
||||
}" rel="ugc">@<span>#{user.nickname}</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{
|
||||
other_user.id
|
||||
}" href="#{other_user.ap_id}" rel="ugc">@<span>#{other_user.nickname}</span></a></span> hey dudes i hate <span class="h-card"><a class="u-url mention" data-user="#{
|
||||
third_user.id
|
||||
}" href="#{third_user.ap_id}" rel="ugc">@<span>#{third_user.nickname}</span></a></span>)
|
||||
~s(<span class="h-card"><a class="u-url mention" data-user="#{user.id}" href="#{user.ap_id}" rel="ugc">@<span>#{user.nickname}</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{other_user.id}" href="#{other_user.ap_id}" rel="ugc">@<span>#{other_user.nickname}</span></a></span> hey dudes i hate <span class="h-card"><a class="u-url mention" data-user="#{third_user.id}" href="#{third_user.ap_id}" rel="ugc">@<span>#{third_user.nickname}</span></a></span>)
|
||||
end
|
||||
|
||||
test "given the 'safe_mention' option, it will still work without any mention" do
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ defmodule Pleroma.Instances.InstanceTest do
|
|||
alias Pleroma.Instances
|
||||
alias Pleroma.Instances.Instance
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
use Pleroma.DataCase
|
||||
|
||||
|
|
@ -158,4 +160,33 @@ defmodule Pleroma.Instances.InstanceTest do
|
|||
"Instance.scrape_favicon(\"#{url}\") ignored unreachable host"
|
||||
end
|
||||
end
|
||||
|
||||
test "delete_users_and_activities/1 deletes remote instance users and activities" do
|
||||
[mario, luigi, _peach, wario] =
|
||||
users = [
|
||||
insert(:user, nickname: "mario@mushroom.kingdom", name: "Mario"),
|
||||
insert(:user, nickname: "luigi@mushroom.kingdom", name: "Luigi"),
|
||||
insert(:user, nickname: "peach@mushroom.kingdom", name: "Peach"),
|
||||
insert(:user, nickname: "wario@greedville.biz", name: "Wario")
|
||||
]
|
||||
|
||||
{:ok, post1} = CommonAPI.post(mario, %{status: "letsa go!"})
|
||||
{:ok, post2} = CommonAPI.post(luigi, %{status: "itsa me... luigi"})
|
||||
{:ok, post3} = CommonAPI.post(wario, %{status: "WHA-HA-HA!"})
|
||||
|
||||
{:ok, job} = Instance.delete_users_and_activities("mushroom.kingdom")
|
||||
:ok = ObanHelpers.perform(job)
|
||||
|
||||
[mario, luigi, peach, wario] = Repo.reload(users)
|
||||
|
||||
refute mario.is_active
|
||||
refute luigi.is_active
|
||||
refute peach.is_active
|
||||
refute peach.name == "Peach"
|
||||
|
||||
assert wario.is_active
|
||||
assert wario.name == "Wario"
|
||||
|
||||
assert [nil, nil, %{}] = Repo.reload([post1, post2, post3])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -236,9 +236,7 @@ defmodule Pleroma.ModerationLogTest do
|
|||
log = Repo.get(ModerationLog, log2.id)
|
||||
|
||||
assert log.data["message"] ==
|
||||
"@#{moderator.nickname} added note 'look at this' to report ##{report.id} on user @#{
|
||||
user.nickname
|
||||
}"
|
||||
"@#{moderator.nickname} added note 'look at this' to report ##{report.id} on user @#{user.nickname}"
|
||||
end
|
||||
|
||||
test "logging status sensitivity update", %{moderator: moderator} do
|
||||
|
|
|
|||
|
|
@ -129,6 +129,19 @@ defmodule Pleroma.NotificationTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "create_poll_notifications/1" do
|
||||
[user1, user2, user3, _, _] = insert_list(5, :user)
|
||||
question = insert(:question, user: user1)
|
||||
activity = insert(:question_activity, question: question)
|
||||
|
||||
{:ok, _, _} = CommonAPI.vote(user2, question, [0])
|
||||
{:ok, _, _} = CommonAPI.vote(user3, question, [1])
|
||||
|
||||
{:ok, notifications} = Notification.create_poll_notifications(activity)
|
||||
|
||||
assert [user2.id, user3.id, user1.id] == Enum.map(notifications, & &1.user_id)
|
||||
end
|
||||
|
||||
describe "CommonApi.post/2 notification-related functionality" do
|
||||
test_with_mock "creates but does NOT send notification to blocker user",
|
||||
Push,
|
||||
|
|
|
|||
|
|
@ -480,7 +480,7 @@ defmodule Pleroma.UserTest do
|
|||
)
|
||||
|
||||
test "it sends a welcome chat message when Simple policy applied to local instance" do
|
||||
clear_config([:mrf_simple, :media_nsfw], ["localhost"])
|
||||
clear_config([:mrf_simple, :media_nsfw], [{"localhost", ""}])
|
||||
|
||||
welcome_user = insert(:user)
|
||||
clear_config([:welcome, :chat_message, :enabled], true)
|
||||
|
|
@ -1649,7 +1649,6 @@ defmodule Pleroma.UserTest do
|
|||
ap_enabled: true,
|
||||
is_moderator: true,
|
||||
is_admin: true,
|
||||
mastofe_settings: %{"a" => "b"},
|
||||
mascot: %{"a" => "b"},
|
||||
emoji: %{"a" => "b"},
|
||||
pleroma_settings_store: %{"q" => "x"},
|
||||
|
|
@ -1691,7 +1690,6 @@ defmodule Pleroma.UserTest do
|
|||
ap_enabled: false,
|
||||
is_moderator: false,
|
||||
is_admin: false,
|
||||
mastofe_settings: nil,
|
||||
mascot: nil,
|
||||
emoji: %{},
|
||||
pleroma_settings_store: %{},
|
||||
|
|
@ -1888,9 +1886,7 @@ defmodule Pleroma.UserTest do
|
|||
bio = "A.k.a. @nick@domain.com"
|
||||
|
||||
expected_text =
|
||||
~s(A.k.a. <span class="h-card"><a class="u-url mention" data-user="#{remote_user.id}" href="#{
|
||||
remote_user.ap_id
|
||||
}" rel="ugc">@<span>nick@domain.com</span></a></span>)
|
||||
~s(A.k.a. <span class="h-card"><a class="u-url mention" data-user="#{remote_user.id}" href="#{remote_user.ap_id}" rel="ugc">@<span>nick@domain.com</span></a></span>)
|
||||
|
||||
assert expected_text == User.parse_bio(bio, user)
|
||||
end
|
||||
|
|
@ -2199,11 +2195,40 @@ defmodule Pleroma.UserTest do
|
|||
[user: insert(:user)]
|
||||
end
|
||||
|
||||
test "blank email returns error", %{user: user} do
|
||||
test "blank email returns error if we require an email on registration", %{user: user} do
|
||||
orig_account_activation_required =
|
||||
Pleroma.Config.get([:instance, :account_activation_required])
|
||||
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put(
|
||||
[:instance, :account_activation_required],
|
||||
orig_account_activation_required
|
||||
)
|
||||
end)
|
||||
|
||||
assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, "")
|
||||
assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, nil)
|
||||
end
|
||||
|
||||
test "blank email should be fine if we do not require an email on registration", %{user: user} do
|
||||
orig_account_activation_required =
|
||||
Pleroma.Config.get([:instance, :account_activation_required])
|
||||
|
||||
Pleroma.Config.put([:instance, :account_activation_required], false)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put(
|
||||
[:instance, :account_activation_required],
|
||||
orig_account_activation_required
|
||||
)
|
||||
end)
|
||||
|
||||
assert {:ok, %User{email: nil}} = User.change_email(user, "")
|
||||
assert {:ok, %User{email: nil}} = User.change_email(user, nil)
|
||||
end
|
||||
|
||||
test "non unique email returns error", %{user: user} do
|
||||
%{email: email} = insert(:user)
|
||||
|
||||
|
|
@ -2219,6 +2244,25 @@ defmodule Pleroma.UserTest do
|
|||
test "changes email", %{user: user} do
|
||||
assert {:ok, %User{email: "cofe@cofe.party"}} = User.change_email(user, "cofe@cofe.party")
|
||||
end
|
||||
|
||||
test "adds email", %{user: user} do
|
||||
orig_account_activation_required =
|
||||
Pleroma.Config.get([:instance, :account_activation_required])
|
||||
|
||||
Pleroma.Config.put([:instance, :account_activation_required], false)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put(
|
||||
[:instance, :account_activation_required],
|
||||
orig_account_activation_required
|
||||
)
|
||||
end)
|
||||
|
||||
assert {:ok, _} = User.change_email(user, "")
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
|
||||
assert {:ok, %User{email: "cofe2@cofe.party"}} = User.change_email(user, "cofe2@cofe.party")
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_cached_by_nickname_or_id" do
|
||||
|
|
@ -2366,13 +2410,16 @@ defmodule Pleroma.UserTest do
|
|||
test "active_user_count/1" do
|
||||
insert(:user)
|
||||
insert(:user, %{local: false})
|
||||
insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), weeks: -5)})
|
||||
insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), weeks: -3)})
|
||||
insert(:user, %{last_active_at: NaiveDateTime.utc_now()})
|
||||
insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), days: -15)})
|
||||
insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), weeks: -6)})
|
||||
insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), months: -7)})
|
||||
insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), years: -2)})
|
||||
|
||||
assert User.active_user_count() == 2
|
||||
assert User.active_user_count(6) == 3
|
||||
assert User.active_user_count(1) == 1
|
||||
assert User.active_user_count(180) == 3
|
||||
assert User.active_user_count(365) == 4
|
||||
assert User.active_user_count(1000) == 5
|
||||
end
|
||||
|
||||
describe "pins" do
|
||||
|
|
|
|||
|
|
@ -776,6 +776,32 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert Enum.member?(activities, activity_one)
|
||||
end
|
||||
|
||||
test "doesn't return activities from deactivated users" do
|
||||
_user = insert(:user)
|
||||
deactivated = insert(:user)
|
||||
active = insert(:user)
|
||||
{:ok, activity_one} = CommonAPI.post(deactivated, %{status: "hey!"})
|
||||
{:ok, activity_two} = CommonAPI.post(active, %{status: "yay!"})
|
||||
{:ok, _updated_user} = User.set_activation(deactivated, false)
|
||||
|
||||
activities = ActivityPub.fetch_activities([], %{})
|
||||
|
||||
refute Enum.member?(activities, activity_one)
|
||||
assert Enum.member?(activities, activity_two)
|
||||
end
|
||||
|
||||
test "always see your own posts even when they address people you block" do
|
||||
user = insert(:user)
|
||||
blockee = insert(:user)
|
||||
|
||||
{:ok, _} = User.block(user, blockee)
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "hey! @#{blockee.nickname}"})
|
||||
|
||||
activities = ActivityPub.fetch_activities([], %{blocking_user: user})
|
||||
|
||||
assert Enum.member?(activities, activity)
|
||||
end
|
||||
|
||||
test "doesn't return transitive interactions concerning blocked users" do
|
||||
blocker = insert(:user)
|
||||
blockee = insert(:user)
|
||||
|
|
@ -875,6 +901,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
refute repeat_activity in activities
|
||||
end
|
||||
|
||||
test "see your own posts even when they adress actors from blocked domains" do
|
||||
user = insert(:user)
|
||||
|
||||
domain = "dogwhistle.zone"
|
||||
domain_user = insert(:user, %{ap_id: "https://#{domain}/@pundit"})
|
||||
|
||||
{:ok, user} = User.block_domain(user, domain)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "hey! @#{domain_user.nickname}"})
|
||||
|
||||
activities = ActivityPub.fetch_activities([], %{blocking_user: user})
|
||||
|
||||
assert Enum.member?(activities, activity)
|
||||
end
|
||||
|
||||
test "does return activities from followed users on blocked domains" do
|
||||
domain = "meanies.social"
|
||||
domain_user = insert(:user, %{ap_id: "https://#{domain}/@pundit"})
|
||||
|
|
|
|||
48
test/pleroma/web/activity_pub/builder_test.exs
Normal file
48
test/pleroma/web/activity_pub/builder_test.exs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.BuilderTest do
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
alias Pleroma.Web.CommonAPI.ActivityDraft
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "note/1" do
|
||||
test "returns note data" do
|
||||
user = insert(:user)
|
||||
note = insert(:note)
|
||||
user2 = insert(:user)
|
||||
user3 = insert(:user)
|
||||
|
||||
draft = %ActivityDraft{
|
||||
user: user,
|
||||
to: [user2.ap_id],
|
||||
context: "2hu",
|
||||
content_html: "<h1>This is :moominmamma: note</h1>",
|
||||
in_reply_to: note.id,
|
||||
tags: [name: "jimm"],
|
||||
summary: "test summary",
|
||||
cc: [user3.ap_id],
|
||||
extra: %{"custom_tag" => "test"}
|
||||
}
|
||||
|
||||
expected = %{
|
||||
"actor" => user.ap_id,
|
||||
"attachment" => [],
|
||||
"cc" => [user3.ap_id],
|
||||
"content" => "<h1>This is :moominmamma: note</h1>",
|
||||
"context" => "2hu",
|
||||
"sensitive" => false,
|
||||
"summary" => "test summary",
|
||||
"tag" => ["jimm"],
|
||||
"to" => [user2.ap_id],
|
||||
"type" => "Note",
|
||||
"custom_tag" => "test"
|
||||
}
|
||||
|
||||
assert {:ok, ^expected, []} = Builder.note(draft)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -33,7 +33,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "has a matching host" do
|
||||
clear_config([:mrf_simple, :media_removal], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :media_removal], [{"remote.instance", "Some reason"}])
|
||||
media_message = build_media_message()
|
||||
local_message = build_local_message()
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "match with wildcard domain" do
|
||||
clear_config([:mrf_simple, :media_removal], ["*.remote.instance"])
|
||||
clear_config([:mrf_simple, :media_removal], [{"*.remote.instance", "Whatever reason"}])
|
||||
media_message = build_media_message()
|
||||
local_message = build_local_message()
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "has a matching host" do
|
||||
clear_config([:mrf_simple, :media_nsfw], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :media_nsfw], [{"remote.instance", "Whetever"}])
|
||||
media_message = build_media_message()
|
||||
local_message = build_local_message()
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "match with wildcard domain" do
|
||||
clear_config([:mrf_simple, :media_nsfw], ["*.remote.instance"])
|
||||
clear_config([:mrf_simple, :media_nsfw], [{"*.remote.instance", "yeah yeah"}])
|
||||
media_message = build_media_message()
|
||||
local_message = build_local_message()
|
||||
|
||||
|
|
@ -115,7 +115,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "has a matching host" do
|
||||
clear_config([:mrf_simple, :report_removal], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :report_removal], [{"remote.instance", "muh"}])
|
||||
report_message = build_report_message()
|
||||
local_message = build_local_message()
|
||||
|
||||
|
|
@ -124,7 +124,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "match with wildcard domain" do
|
||||
clear_config([:mrf_simple, :report_removal], ["*.remote.instance"])
|
||||
clear_config([:mrf_simple, :report_removal], [{"*.remote.instance", "suya"}])
|
||||
report_message = build_report_message()
|
||||
local_message = build_local_message()
|
||||
|
||||
|
|
@ -159,7 +159,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|> URI.parse()
|
||||
|> Map.fetch!(:host)
|
||||
|
||||
clear_config([:mrf_simple, :federated_timeline_removal], [ftl_message_actor_host])
|
||||
clear_config([:mrf_simple, :federated_timeline_removal], [{ftl_message_actor_host, "uwu"}])
|
||||
local_message = build_local_message()
|
||||
|
||||
assert {:ok, ftl_message} = SimplePolicy.filter(ftl_message)
|
||||
|
|
@ -180,7 +180,10 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|> URI.parse()
|
||||
|> Map.fetch!(:host)
|
||||
|
||||
clear_config([:mrf_simple, :federated_timeline_removal], ["*." <> ftl_message_actor_host])
|
||||
clear_config([:mrf_simple, :federated_timeline_removal], [
|
||||
{"*." <> ftl_message_actor_host, "owo"}
|
||||
])
|
||||
|
||||
local_message = build_local_message()
|
||||
|
||||
assert {:ok, ftl_message} = SimplePolicy.filter(ftl_message)
|
||||
|
|
@ -203,7 +206,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|
||||
ftl_message = Map.put(ftl_message, "cc", [])
|
||||
|
||||
clear_config([:mrf_simple, :federated_timeline_removal], [ftl_message_actor_host])
|
||||
clear_config([:mrf_simple, :federated_timeline_removal], [
|
||||
{ftl_message_actor_host, "spiderwaifu goes 88w88"}
|
||||
])
|
||||
|
||||
assert {:ok, ftl_message} = SimplePolicy.filter(ftl_message)
|
||||
refute "https://www.w3.org/ns/activitystreams#Public" in ftl_message["to"]
|
||||
|
|
@ -232,7 +237,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "activity has a matching host" do
|
||||
clear_config([:mrf_simple, :reject], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :reject], [{"remote.instance", ""}])
|
||||
|
||||
remote_message = build_remote_message()
|
||||
|
||||
|
|
@ -240,7 +245,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "activity matches with wildcard domain" do
|
||||
clear_config([:mrf_simple, :reject], ["*.remote.instance"])
|
||||
clear_config([:mrf_simple, :reject], [{"*.remote.instance", ""}])
|
||||
|
||||
remote_message = build_remote_message()
|
||||
|
||||
|
|
@ -248,7 +253,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "actor has a matching host" do
|
||||
clear_config([:mrf_simple, :reject], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :reject], [{"remote.instance", ""}])
|
||||
|
||||
remote_user = build_remote_user()
|
||||
|
||||
|
|
@ -256,7 +261,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "reject Announce when object would be rejected" do
|
||||
clear_config([:mrf_simple, :reject], ["blocked.tld"])
|
||||
clear_config([:mrf_simple, :reject], [{"blocked.tld", ""}])
|
||||
|
||||
announce = %{
|
||||
"type" => "Announce",
|
||||
|
|
@ -268,7 +273,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "reject by URI object" do
|
||||
clear_config([:mrf_simple, :reject], ["blocked.tld"])
|
||||
clear_config([:mrf_simple, :reject], [{"blocked.tld", ""}])
|
||||
|
||||
announce = %{
|
||||
"type" => "Announce",
|
||||
|
|
@ -322,7 +327,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
|> URI.parse()
|
||||
|> Map.fetch!(:host)
|
||||
|
||||
clear_config([: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"]
|
||||
|
|
@ -350,7 +355,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "is not empty but activity doesn't have a matching host" do
|
||||
clear_config([:mrf_simple, :accept], ["non.matching.remote"])
|
||||
clear_config([:mrf_simple, :accept], [{"non.matching.remote", ""}])
|
||||
|
||||
local_message = build_local_message()
|
||||
remote_message = build_remote_message()
|
||||
|
|
@ -360,7 +365,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "activity has a matching host" do
|
||||
clear_config([:mrf_simple, :accept], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :accept], [{"remote.instance", ""}])
|
||||
|
||||
local_message = build_local_message()
|
||||
remote_message = build_remote_message()
|
||||
|
|
@ -370,7 +375,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "activity matches with wildcard domain" do
|
||||
clear_config([:mrf_simple, :accept], ["*.remote.instance"])
|
||||
clear_config([:mrf_simple, :accept], [{"*.remote.instance", ""}])
|
||||
|
||||
local_message = build_local_message()
|
||||
remote_message = build_remote_message()
|
||||
|
|
@ -380,7 +385,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "actor has a matching host" do
|
||||
clear_config([:mrf_simple, :accept], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :accept], [{"remote.instance", ""}])
|
||||
|
||||
remote_user = build_remote_user()
|
||||
|
||||
|
|
@ -398,7 +403,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "is not empty but it doesn't have a matching host" do
|
||||
clear_config([:mrf_simple, :avatar_removal], ["non.matching.remote"])
|
||||
clear_config([:mrf_simple, :avatar_removal], [{"non.matching.remote", ""}])
|
||||
|
||||
remote_user = build_remote_user()
|
||||
|
||||
|
|
@ -406,7 +411,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "has a matching host" do
|
||||
clear_config([: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)
|
||||
|
|
@ -415,7 +420,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "match with wildcard domain" do
|
||||
clear_config([: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)
|
||||
|
|
@ -434,7 +439,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "is not empty but it doesn't have a matching host" do
|
||||
clear_config([:mrf_simple, :banner_removal], ["non.matching.remote"])
|
||||
clear_config([:mrf_simple, :banner_removal], [{"non.matching.remote", ""}])
|
||||
|
||||
remote_user = build_remote_user()
|
||||
|
||||
|
|
@ -442,7 +447,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "has a matching host" do
|
||||
clear_config([: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)
|
||||
|
|
@ -451,7 +456,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "match with wildcard domain" do
|
||||
clear_config([: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)
|
||||
|
|
@ -464,7 +469,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
setup do: clear_config([:mrf_simple, :reject_deletes], [])
|
||||
|
||||
test "it accepts deletions even from rejected servers" do
|
||||
clear_config([:mrf_simple, :reject], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :reject], [{"remote.instance", ""}])
|
||||
|
||||
deletion_message = build_remote_deletion_message()
|
||||
|
||||
|
|
@ -472,7 +477,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "it accepts deletions even from non-whitelisted servers" do
|
||||
clear_config([:mrf_simple, :accept], ["non.matching.remote"])
|
||||
clear_config([:mrf_simple, :accept], [{"non.matching.remote", ""}])
|
||||
|
||||
deletion_message = build_remote_deletion_message()
|
||||
|
||||
|
|
@ -481,10 +486,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: clear_config([: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
|
||||
clear_config([:mrf_simple, :reject], ["remote.instance"])
|
||||
clear_config([:mrf_simple, :reject], [{"remote.instance", ""}])
|
||||
|
||||
deletion_message = build_remote_deletion_message()
|
||||
|
||||
|
|
@ -492,7 +497,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
test "it accepts deletions even from non-whitelisted servers" do
|
||||
clear_config([:mrf_simple, :accept], ["non.matching.remote"])
|
||||
clear_config([:mrf_simple, :accept], [{"non.matching.remote", ""}])
|
||||
|
||||
deletion_message = build_remote_deletion_message()
|
||||
|
||||
|
|
@ -501,7 +506,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
describe "when :reject_deletes has a matching host" do
|
||||
setup do: clear_config([: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()
|
||||
|
|
@ -511,7 +516,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
|
||||
describe "when :reject_deletes match with wildcard domain" do
|
||||
setup do: clear_config([: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()
|
||||
|
|
|
|||
|
|
@ -9,11 +9,6 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do
|
|||
alias Pleroma.Emoji
|
||||
alias Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
setup do
|
||||
emoji_path = [:instance, :static_dir] |> Config.get() |> Path.join("emoji/stolen")
|
||||
|
||||
|
|
@ -49,6 +44,10 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do
|
|||
refute "firedfox" in installed()
|
||||
refute File.exists?(path)
|
||||
|
||||
Tesla.Mock.mock(fn %{method: :get, url: "https://example.org/emoji/firedfox.png"} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/image.jpg")}
|
||||
end)
|
||||
|
||||
clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 284_468)
|
||||
|
||||
assert {:ok, _message} = StealEmojiPolicy.filter(message)
|
||||
|
|
@ -78,6 +77,10 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do
|
|||
test "reject if size is above the limit", %{message: message} do
|
||||
refute "firedfox" in installed()
|
||||
|
||||
Tesla.Mock.mock(fn %{method: :get, url: "https://example.org/emoji/firedfox.png"} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/image.jpg")}
|
||||
end)
|
||||
|
||||
clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 50_000)
|
||||
|
||||
assert {:ok, _message} = StealEmojiPolicy.filter(message)
|
||||
|
|
|
|||
|
|
@ -63,6 +63,15 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "instance_list_from_tuples/1" do
|
||||
test "returns a list of instances from a list of {instance, reason} tuples" do
|
||||
list = [{"some.tld", "a reason"}, {"other.tld", "another reason"}]
|
||||
expected = ["some.tld", "other.tld"]
|
||||
|
||||
assert MRF.instance_list_from_tuples(list) == expected
|
||||
end
|
||||
end
|
||||
|
||||
describe "describe/0" do
|
||||
test "it works as expected with noop policy" do
|
||||
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.NoOpPolicy])
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
|
|||
test "validates for a basic object we build", %{valid_chat_message: valid_chat_message} do
|
||||
assert {:ok, object, _meta} = ObjectValidator.validate(valid_chat_message, [])
|
||||
|
||||
assert Map.put(valid_chat_message, "attachment", nil) == object
|
||||
assert valid_chat_message == object
|
||||
assert match?(%{"firefox" => _}, object["emoji"])
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -267,6 +267,80 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
end
|
||||
|
||||
describe "publish/2" do
|
||||
test_with_mock "doesn't publish a non-public activity to quarantined instances.",
|
||||
Pleroma.Web.Federator.Publisher,
|
||||
[:passthrough],
|
||||
[] do
|
||||
Config.put([:instance, :quarantined_instances], [{"domain.com", "some reason"}])
|
||||
|
||||
follower =
|
||||
insert(:user, %{
|
||||
local: false,
|
||||
inbox: "https://domain.com/users/nick1/inbox",
|
||||
ap_enabled: true
|
||||
})
|
||||
|
||||
actor = insert(:user, follower_address: follower.ap_id)
|
||||
|
||||
{:ok, follower, actor} = Pleroma.User.follow(follower, actor)
|
||||
actor = refresh_record(actor)
|
||||
|
||||
note_activity =
|
||||
insert(:followers_only_note_activity,
|
||||
user: actor,
|
||||
recipients: [follower.ap_id]
|
||||
)
|
||||
|
||||
res = Publisher.publish(actor, note_activity)
|
||||
|
||||
assert res == :ok
|
||||
|
||||
assert not called(
|
||||
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
|
||||
inbox: "https://domain.com/users/nick1/inbox",
|
||||
actor_id: actor.id,
|
||||
id: note_activity.data["id"]
|
||||
})
|
||||
)
|
||||
end
|
||||
|
||||
test_with_mock "Publishes a non-public activity to non-quarantined instances.",
|
||||
Pleroma.Web.Federator.Publisher,
|
||||
[:passthrough],
|
||||
[] do
|
||||
Config.put([:instance, :quarantined_instances], [{"somedomain.com", "some reason"}])
|
||||
|
||||
follower =
|
||||
insert(:user, %{
|
||||
local: false,
|
||||
inbox: "https://domain.com/users/nick1/inbox",
|
||||
ap_enabled: true
|
||||
})
|
||||
|
||||
actor = insert(:user, follower_address: follower.ap_id)
|
||||
|
||||
{:ok, follower, actor} = Pleroma.User.follow(follower, actor)
|
||||
actor = refresh_record(actor)
|
||||
|
||||
note_activity =
|
||||
insert(:followers_only_note_activity,
|
||||
user: actor,
|
||||
recipients: [follower.ap_id]
|
||||
)
|
||||
|
||||
res = Publisher.publish(actor, note_activity)
|
||||
|
||||
assert res == :ok
|
||||
|
||||
assert called(
|
||||
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
|
||||
inbox: "https://domain.com/users/nick1/inbox",
|
||||
actor_id: actor.id,
|
||||
id: note_activity.data["id"]
|
||||
})
|
||||
)
|
||||
end
|
||||
|
||||
test_with_mock "publishes an activity with BCC to all relevant peers.",
|
||||
Pleroma.Web.Federator.Publisher,
|
||||
[:passthrough],
|
||||
|
|
|
|||
|
|
@ -157,6 +157,30 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "Question objects" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
question = build(:question, user: user)
|
||||
question_activity = build(:question_activity, question: question)
|
||||
activity_data = Map.put(question_activity.data, "object", question.data["id"])
|
||||
meta = [object_data: question.data, local: false]
|
||||
|
||||
{:ok, activity, meta} = ActivityPub.persist(activity_data, meta)
|
||||
|
||||
%{activity: activity, meta: meta}
|
||||
end
|
||||
|
||||
test "enqueues the poll end", %{activity: activity, meta: meta} do
|
||||
{:ok, activity, meta} = SideEffects.handle(activity, meta)
|
||||
|
||||
assert_enqueued(
|
||||
worker: Pleroma.Workers.PollWorker,
|
||||
args: %{op: "poll_end", activity_id: activity.id},
|
||||
scheduled_at: NaiveDateTime.from_iso8601!(meta[:object_data]["closed"])
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete users with confirmation pending" do
|
||||
setup do
|
||||
user = insert(:user, is_confirmed: false)
|
||||
|
|
|
|||
|
|
@ -67,7 +67,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AddRemoveHandlingTest do
|
|||
"target" => "https://example.com/users/lain/collections/featured",
|
||||
"type" => "Add",
|
||||
"to" => [Pleroma.Constants.as_public()],
|
||||
"cc" => ["https://example.com/users/lain/followers"]
|
||||
"cc" => ["https://example.com/users/lain/followers"],
|
||||
"bcc" => [],
|
||||
"bto" => []
|
||||
}
|
||||
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||
|
|
@ -82,7 +84,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AddRemoveHandlingTest do
|
|||
"target" => "https://example.com/users/lain/collections/featured",
|
||||
"type" => "Remove",
|
||||
"to" => [Pleroma.Constants.as_public()],
|
||||
"cc" => ["https://example.com/users/lain/followers"]
|
||||
"cc" => ["https://example.com/users/lain/followers"],
|
||||
"bcc" => [],
|
||||
"bto" => []
|
||||
}
|
||||
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(remove)
|
||||
|
|
@ -161,7 +165,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AddRemoveHandlingTest do
|
|||
"target" => "https://#{host}/users/#{user.nickname}/collections/featured",
|
||||
"type" => "Add",
|
||||
"to" => [Pleroma.Constants.as_public()],
|
||||
"cc" => ["https://#{host}/users/#{user.nickname}/followers"]
|
||||
"cc" => ["https://#{host}/users/#{user.nickname}/followers"],
|
||||
"bcc" => [],
|
||||
"bto" => []
|
||||
}
|
||||
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||
|
|
|
|||
|
|
@ -73,16 +73,12 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
|
|||
%{
|
||||
"mediaType" => "audio/ogg",
|
||||
"type" => "Link",
|
||||
"name" => nil,
|
||||
"blurhash" => nil,
|
||||
"url" => [
|
||||
%{
|
||||
"href" =>
|
||||
"https://channels.tests.funkwhale.audio/api/v1/listen/3901e5d8-0445-49d5-9711-e096cf32e515/?upload=42342395-0208-4fee-a38d-259a6dae0871&download=false",
|
||||
"mediaType" => "audio/ogg",
|
||||
"type" => "Link",
|
||||
"width" => nil,
|
||||
"height" => nil
|
||||
"type" => "Link"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,8 +53,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
|
|||
%{
|
||||
"type" => "Link",
|
||||
"mediaType" => "video/mp4",
|
||||
"name" => nil,
|
||||
"blurhash" => nil,
|
||||
"url" => [
|
||||
%{
|
||||
"href" =>
|
||||
|
|
@ -78,8 +76,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
|
|||
%{
|
||||
"type" => "Link",
|
||||
"mediaType" => "video/mp4",
|
||||
"name" => nil,
|
||||
"blurhash" => nil,
|
||||
"url" => [
|
||||
%{
|
||||
"href" =>
|
||||
|
|
@ -110,8 +106,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
|
|||
%{
|
||||
"type" => "Link",
|
||||
"mediaType" => "video/mp4",
|
||||
"name" => nil,
|
||||
"blurhash" => nil,
|
||||
"url" => [
|
||||
%{
|
||||
"href" =>
|
||||
|
|
|
|||
|
|
@ -267,9 +267,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} revoked admin role from @#{user_one.nickname}, @#{
|
||||
user_two.nickname
|
||||
}"
|
||||
"@#{admin.nickname} revoked admin role from @#{user_one.nickname}, @#{user_two.nickname}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -800,40 +798,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "instances" do
|
||||
test "GET /instances/:instance/statuses", %{conn: conn} do
|
||||
user = insert(:user, local: false, ap_id: "https://archae.me/users/archaeme")
|
||||
user2 = insert(:user, local: false, ap_id: "https://test.com/users/test")
|
||||
insert_pair(:note_activity, user: user)
|
||||
activity = insert(:note_activity, user: user2)
|
||||
|
||||
%{"total" => 2, "activities" => activities} =
|
||||
conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
|
||||
|
||||
assert length(activities) == 2
|
||||
|
||||
%{"total" => 1, "activities" => [_]} =
|
||||
conn |> get("/api/pleroma/admin/instances/test.com/statuses") |> json_response(200)
|
||||
|
||||
%{"total" => 0, "activities" => []} =
|
||||
conn |> get("/api/pleroma/admin/instances/nonexistent.com/statuses") |> json_response(200)
|
||||
|
||||
CommonAPI.repeat(activity.id, user)
|
||||
|
||||
%{"total" => 2, "activities" => activities} =
|
||||
conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
|
||||
|
||||
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
|
||||
|
||||
describe "PATCH /confirm_email" do
|
||||
test "it confirms emails of two users", %{conn: conn, admin: admin} do
|
||||
[first_user, second_user] = insert_pair(:user, is_confirmed: false)
|
||||
|
|
@ -860,9 +824,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} confirmed email for users: @#{first_user.nickname}, @#{
|
||||
second_user.nickname
|
||||
}"
|
||||
"@#{admin.nickname} confirmed email for users: @#{first_user.nickname}, @#{second_user.nickname}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -883,9 +845,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} re-sent confirmation email for users: @#{first_user.nickname}, @#{
|
||||
second_user.nickname
|
||||
}"
|
||||
"@#{admin.nickname} re-sent confirmation email for users: @#{first_user.nickname}, @#{second_user.nickname}"
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,80 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.AdminAPI.InstanceControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
setup do
|
||||
admin = insert(:user, is_admin: true)
|
||||
token = insert(:oauth_admin_token, user: admin)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> assign(:token, token)
|
||||
|
||||
{:ok, %{admin: admin, token: token, conn: conn}}
|
||||
end
|
||||
|
||||
test "GET /instances/:instance/statuses", %{conn: conn} do
|
||||
user = insert(:user, local: false, ap_id: "https://archae.me/users/archaeme")
|
||||
user2 = insert(:user, local: false, ap_id: "https://test.com/users/test")
|
||||
insert_pair(:note_activity, user: user)
|
||||
activity = insert(:note_activity, user: user2)
|
||||
|
||||
%{"total" => 2, "activities" => activities} =
|
||||
conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
|
||||
|
||||
assert length(activities) == 2
|
||||
|
||||
%{"total" => 1, "activities" => [_]} =
|
||||
conn |> get("/api/pleroma/admin/instances/test.com/statuses") |> json_response(200)
|
||||
|
||||
%{"total" => 0, "activities" => []} =
|
||||
conn |> get("/api/pleroma/admin/instances/nonexistent.com/statuses") |> json_response(200)
|
||||
|
||||
CommonAPI.repeat(activity.id, user)
|
||||
|
||||
%{"total" => 2, "activities" => activities} =
|
||||
conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
|
||||
|
||||
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
|
||||
|
||||
test "DELETE /instances/:instance", %{conn: conn} do
|
||||
user = insert(:user, nickname: "lain@lain.com")
|
||||
post = insert(:note_activity, user: user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> delete("/api/pleroma/admin/instances/lain.com")
|
||||
|> json_response(200)
|
||||
|
||||
[:ok] = ObanHelpers.perform_all()
|
||||
|
||||
assert response == "lain.com"
|
||||
refute Repo.reload(user).is_active
|
||||
refute Repo.reload(post)
|
||||
end
|
||||
end
|
||||
|
|
@ -47,30 +47,34 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
|
|||
assert response["page_size"] == 2
|
||||
assert response["count"] == 5
|
||||
|
||||
assert response["urls"] == [
|
||||
"http://localhost:4001/media/fb1f4d.jpg",
|
||||
"http://localhost:4001/media/a688346.jpg"
|
||||
]
|
||||
results = response["urls"]
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/media_proxy_caches?page_size=2&page=2")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response["urls"] == [
|
||||
"http://localhost:4001/media/gb1f44.jpg",
|
||||
"http://localhost:4001/media/tb13f47.jpg"
|
||||
]
|
||||
|
||||
assert response["page_size"] == 2
|
||||
assert response["count"] == 5
|
||||
|
||||
results = results ++ response["urls"]
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/media_proxy_caches?page_size=2&page=3")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response["urls"] == ["http://localhost:4001/media/wb1f46.jpg"]
|
||||
results = results ++ response["urls"]
|
||||
|
||||
assert results |> Enum.sort() ==
|
||||
[
|
||||
"http://localhost:4001/media/wb1f46.jpg",
|
||||
"http://localhost:4001/media/gb1f44.jpg",
|
||||
"http://localhost:4001/media/tb13f47.jpg",
|
||||
"http://localhost:4001/media/fb1f4d.jpg",
|
||||
"http://localhost:4001/media/a688346.jpg"
|
||||
]
|
||||
|> Enum.sort()
|
||||
end
|
||||
|
||||
test "search banned MediaProxy URLs", %{conn: conn} do
|
||||
|
|
@ -88,9 +92,9 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
|
|||
|> get("/api/pleroma/admin/media_proxy_caches?page_size=2&query=F44")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response["urls"] == [
|
||||
"http://localhost:4001/media/gb1f44.jpg",
|
||||
"http://localhost:4001/media/ff44b1f4d.jpg"
|
||||
assert response["urls"] |> Enum.sort() == [
|
||||
"http://localhost:4001/media/ff44b1f4d.jpg",
|
||||
"http://localhost:4001/media/gb1f44.jpg"
|
||||
]
|
||||
|
||||
assert response["page_size"] == 2
|
||||
|
|
|
|||
|
|
@ -204,9 +204,7 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
|
|||
"@#{admin.nickname} updated report ##{id} (on user @#{activity.user_actor.nickname}) with 'resolved' state"
|
||||
|
||||
assert ModerationLog.get_log_entry_message(second_log_entry) ==
|
||||
"@#{admin.nickname} updated report ##{second_report_id} (on user @#{
|
||||
second_activity.user_actor.nickname
|
||||
}) with 'closed' state"
|
||||
"@#{admin.nickname} updated report ##{second_report_id} (on user @#{second_activity.user_actor.nickname}) with 'closed' state"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -305,7 +303,7 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
|
|||
|> get("/api/pleroma/admin/reports")
|
||||
|
||||
assert json_response(conn, :forbidden) ==
|
||||
%{"error" => "User is not an admin."}
|
||||
%{"error" => "User is not a staff member."}
|
||||
end
|
||||
|
||||
test "returns 403 when requested by anonymous" do
|
||||
|
|
|
|||
|
|
@ -160,11 +160,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
{output, _, _} = Utils.format_input(text, "text/markdown")
|
||||
|
||||
assert output ==
|
||||
~s(<p><strong>hello world</strong></p><p><em>another <span class="h-card"><a class="u-url mention" data-user="#{
|
||||
user.id
|
||||
}" href="http://foo.com/user__test" rel="ugc">@<span>user__test</span></a></span> and <span class="h-card"><a class="u-url mention" data-user="#{
|
||||
user.id
|
||||
}" href="http://foo.com/user__test" rel="ugc">@<span>user__test</span></a></span> <a href="http://google.com" rel="ugc">google.com</a> paragraph</em></p>)
|
||||
~s(<p><strong>hello world</strong></p><p><em>another <span class="h-card"><a class="u-url mention" data-user="#{user.id}" href="http://foo.com/user__test" rel="ugc">@<span>user__test</span></a></span> and <span class="h-card"><a class="u-url mention" data-user="#{user.id}" href="http://foo.com/user__test" rel="ugc">@<span>user__test</span></a></span> <a href="http://google.com" rel="ugc">google.com</a> paragraph</em></p>)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -201,11 +197,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
{result, _, []} = Utils.format_input(code, "text/markdown")
|
||||
|
||||
assert result ==
|
||||
~s[<p><span class="h-card"><a class="u-url mention" data-user="#{mario.id}" href="#{
|
||||
mario.ap_id
|
||||
}" rel="ugc">@<span>mario</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{
|
||||
luigi.id
|
||||
}" href="#{luigi.ap_id}" rel="ugc">@<span>luigi</span></a></span> yo what’s up?</p>]
|
||||
~s[<p><span class="h-card"><a class="u-url mention" data-user="#{mario.id}" href="#{mario.ap_id}" rel="ugc">@<span>mario</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{luigi.id}" href="#{luigi.ap_id}" rel="ugc">@<span>luigi</span></a></span> yo what’s up?</p>]
|
||||
end
|
||||
|
||||
test "remote mentions" do
|
||||
|
|
@ -216,11 +208,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
{result, _, []} = Utils.format_input(code, "text/markdown")
|
||||
|
||||
assert result ==
|
||||
~s[<p><span class="h-card"><a class="u-url mention" data-user="#{mario.id}" href="#{
|
||||
mario.ap_id
|
||||
}" rel="ugc">@<span>mario</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{
|
||||
luigi.id
|
||||
}" href="#{luigi.ap_id}" rel="ugc">@<span>luigi</span></a></span> yo what’s up?</p>]
|
||||
~s[<p><span class="h-card"><a class="u-url mention" data-user="#{mario.id}" href="#{mario.ap_id}" rel="ugc">@<span>mario</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{luigi.id}" href="#{luigi.ap_id}" rel="ugc">@<span>luigi</span></a></span> yo what’s up?</p>]
|
||||
end
|
||||
|
||||
test "raw HTML" do
|
||||
|
|
@ -681,41 +669,6 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "make_note_data/1" do
|
||||
test "returns note data" do
|
||||
user = insert(:user)
|
||||
note = insert(:note)
|
||||
user2 = insert(:user)
|
||||
user3 = insert(:user)
|
||||
|
||||
draft = %ActivityDraft{
|
||||
user: user,
|
||||
to: [user2.ap_id],
|
||||
context: "2hu",
|
||||
content_html: "<h1>This is :moominmamma: note</h1>",
|
||||
in_reply_to: note.id,
|
||||
tags: [name: "jimm"],
|
||||
summary: "test summary",
|
||||
cc: [user3.ap_id],
|
||||
extra: %{"custom_tag" => "test"}
|
||||
}
|
||||
|
||||
assert Utils.make_note_data(draft) == %{
|
||||
"actor" => user.ap_id,
|
||||
"attachment" => [],
|
||||
"cc" => [user3.ap_id],
|
||||
"content" => "<h1>This is :moominmamma: note</h1>",
|
||||
"context" => "2hu",
|
||||
"sensitive" => false,
|
||||
"summary" => "test summary",
|
||||
"tag" => ["jimm"],
|
||||
"to" => [user2.ap_id],
|
||||
"type" => "Note",
|
||||
"custom_tag" => "test"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe "maybe_add_attachments/3" do
|
||||
test "returns parsed results when attachment_links is false" do
|
||||
assert Utils.maybe_add_attachments(
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
alias Pleroma.Web.ActivityPub.Visibility
|
||||
alias Pleroma.Web.AdminAPI.AccountView
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Workers.PollWorker
|
||||
|
||||
import Pleroma.Factory
|
||||
import Mock
|
||||
|
|
@ -48,6 +49,12 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
assert object.data["type"] == "Question"
|
||||
assert object.data["oneOf"] |> length() == 2
|
||||
|
||||
assert_enqueued(
|
||||
worker: PollWorker,
|
||||
args: %{op: "poll_end", activity_id: activity.id},
|
||||
scheduled_at: NaiveDateTime.from_iso8601!(object.data["closed"])
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -202,9 +209,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
assert object.data["content"] ==
|
||||
"<a href=\"https://example.org\" rel=\"ugc\">https://example.org</a> is the site of <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{
|
||||
other_user.id
|
||||
}\" href=\"#{other_user.ap_id}\" rel=\"ugc\">@<span>#{other_user.nickname}</span></a></span> <a class=\"hashtag\" data-tag=\"2hu\" href=\"http://localhost:4001/tag/2hu\">#2hu</a>"
|
||||
"<a href=\"https://example.org\" rel=\"ugc\">https://example.org</a> is the site of <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{other_user.id}\" href=\"#{other_user.ap_id}\" rel=\"ugc\">@<span>#{other_user.nickname}</span></a></span> <a class=\"hashtag\" data-tag=\"2hu\" href=\"http://localhost:4001/tag/2hu\">#2hu</a>"
|
||||
end
|
||||
|
||||
test "it posts a chat message" do
|
||||
|
|
|
|||
|
|
@ -196,13 +196,26 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
).resp_body
|
||||
end
|
||||
|
||||
test "with html format, it returns error when user is not found", %{conn: conn} do
|
||||
test "with html format, it falls back to frontend when user is remote", %{conn: conn} do
|
||||
user = insert(:user, local: false)
|
||||
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "test"})
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/users/#{user.nickname}")
|
||||
|> response(200)
|
||||
|
||||
assert response =~ "</html>"
|
||||
end
|
||||
|
||||
test "with html format, it falls back to frontend when user is not found", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> get("/users/jimm")
|
||||
|> json_response(404)
|
||||
|> response(200)
|
||||
|
||||
assert response == %{"error" => "Not found"}
|
||||
assert response =~ "</html>"
|
||||
end
|
||||
|
||||
test "with non-html / non-json format, it redirects to user feed in atom format", %{
|
||||
|
|
|
|||
|
|
@ -709,9 +709,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert [%{"id" => ^follower2_id}, %{"id" => ^follower1_id}] =
|
||||
conn
|
||||
|> get(
|
||||
"/api/v1/accounts/#{user.id}/followers?id=#{user.id}&limit=20&max_id=#{
|
||||
follower3_id
|
||||
}"
|
||||
"/api/v1/accounts/#{user.id}/followers?id=#{user.id}&limit=20&max_id=#{follower3_id}"
|
||||
)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,159 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.AuthControllerTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
|
||||
import Pleroma.Factory
|
||||
import Swoosh.TestAssertions
|
||||
|
||||
describe "GET /web/login" do
|
||||
setup %{conn: conn} do
|
||||
session_opts = [
|
||||
store: :cookie,
|
||||
key: "_test",
|
||||
signing_salt: "cooldude"
|
||||
]
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> Plug.Session.call(Plug.Session.init(session_opts))
|
||||
|> fetch_session()
|
||||
|
||||
test_path = "/web/statuses/test"
|
||||
%{conn: conn, path: test_path}
|
||||
end
|
||||
|
||||
test "redirects to the saved path after log in", %{conn: conn, path: path} do
|
||||
app = insert(:oauth_app, client_name: "Mastodon-Local", redirect_uris: ".")
|
||||
auth = insert(:oauth_authorization, app: app)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_session(:return_to, path)
|
||||
|> get("/web/login", %{code: auth.token})
|
||||
|
||||
assert conn.status == 302
|
||||
assert redirected_to(conn) =~ path
|
||||
end
|
||||
|
||||
test "redirects to the getting-started page when referer is not present", %{conn: conn} do
|
||||
app = insert(:oauth_app, client_name: "Mastodon-Local", redirect_uris: ".")
|
||||
auth = insert(:oauth_authorization, app: app)
|
||||
|
||||
conn = get(conn, "/web/login", %{code: auth.token})
|
||||
|
||||
assert conn.status == 302
|
||||
assert redirected_to(conn) =~ "/web/getting-started"
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /auth/password, with valid parameters" do
|
||||
setup %{conn: conn} do
|
||||
user = insert(:user)
|
||||
conn = post(conn, "/auth/password?email=#{user.email}")
|
||||
%{conn: conn, user: user}
|
||||
end
|
||||
|
||||
test "it returns 204", %{conn: conn} do
|
||||
assert empty_json_response(conn)
|
||||
end
|
||||
|
||||
test "it creates a PasswordResetToken record for user", %{user: user} do
|
||||
token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
|
||||
assert token_record
|
||||
end
|
||||
|
||||
test "it sends an email to user", %{user: user} do
|
||||
ObanHelpers.perform_all()
|
||||
token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
|
||||
|
||||
email = Pleroma.Emails.UserEmail.password_reset_email(user, token_record.token)
|
||||
notify_email = Config.get([:instance, :notify_email])
|
||||
instance_name = Config.get([:instance, :name])
|
||||
|
||||
assert_email_sent(
|
||||
from: {instance_name, notify_email},
|
||||
to: {user.name, user.email},
|
||||
html_body: email.html_body
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /auth/password, with nickname" do
|
||||
test "it returns 204", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
assert conn
|
||||
|> post("/auth/password?nickname=#{user.nickname}")
|
||||
|> empty_json_response()
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
|
||||
|
||||
email = Pleroma.Emails.UserEmail.password_reset_email(user, token_record.token)
|
||||
notify_email = Config.get([:instance, :notify_email])
|
||||
instance_name = Config.get([:instance, :name])
|
||||
|
||||
assert_email_sent(
|
||||
from: {instance_name, notify_email},
|
||||
to: {user.name, user.email},
|
||||
html_body: email.html_body
|
||||
)
|
||||
end
|
||||
|
||||
test "it doesn't fail when a user has no email", %{conn: conn} do
|
||||
user = insert(:user, %{email: nil})
|
||||
|
||||
assert conn
|
||||
|> post("/auth/password?nickname=#{user.nickname}")
|
||||
|> empty_json_response()
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /auth/password, with invalid parameters" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
{:ok, user: user}
|
||||
end
|
||||
|
||||
test "it returns 204 when user is not found", %{conn: conn, user: user} do
|
||||
conn = post(conn, "/auth/password?email=nonexisting_#{user.email}")
|
||||
|
||||
assert empty_json_response(conn)
|
||||
end
|
||||
|
||||
test "it returns 204 when user is not local", %{conn: conn, user: user} do
|
||||
{:ok, user} = Repo.update(Ecto.Changeset.change(user, local: false))
|
||||
conn = post(conn, "/auth/password?email=#{user.email}")
|
||||
|
||||
assert empty_json_response(conn)
|
||||
end
|
||||
|
||||
test "it returns 204 when user is deactivated", %{conn: conn, user: user} do
|
||||
{:ok, user} = Repo.update(Ecto.Changeset.change(user, is_active: false, local: true))
|
||||
conn = post(conn, "/auth/password?email=#{user.email}")
|
||||
|
||||
assert empty_json_response(conn)
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE /auth/sign_out" do
|
||||
test "redirect to root page", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> delete("/auth/sign_out")
|
||||
|
||||
assert conn.status == 302
|
||||
assert redirected_to(conn) == "/"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -44,9 +44,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|> get("/api/v1/notifications")
|
||||
|
||||
expected_response =
|
||||
"hi <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{user.id}\" href=\"#{
|
||||
user.ap_id
|
||||
}\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
|
||||
"hi <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{user.id}\" href=\"#{user.ap_id}\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
|
||||
|
||||
assert [%{"status" => %{"content" => response}} | _rest] =
|
||||
json_response_and_validate_schema(conn, 200)
|
||||
|
|
@ -103,6 +101,25 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
assert [_] = result
|
||||
end
|
||||
|
||||
test "excludes mentions from blockers when blockers_visible is false" do
|
||||
clear_config([:activitypub, :blockers_visible], false)
|
||||
|
||||
%{user: user, conn: conn} = oauth_access(["read:notifications"])
|
||||
blocker = insert(:user)
|
||||
|
||||
{:ok, _} = CommonAPI.block(blocker, user)
|
||||
{:ok, activity} = CommonAPI.post(blocker, %{status: "hi @#{user.nickname}"})
|
||||
|
||||
{:ok, [_notification]} = Notification.create_notifications(activity)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications")
|
||||
|
||||
assert [] == json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "getting a single notification" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:notifications"])
|
||||
other_user = insert(:user)
|
||||
|
|
@ -114,9 +131,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
conn = get(conn, "/api/v1/notifications/#{notification.id}")
|
||||
|
||||
expected_response =
|
||||
"hi <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{user.id}\" href=\"#{
|
||||
user.ap_id
|
||||
}\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
|
||||
"hi <span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{user.id}\" href=\"#{user.ap_id}\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
|
||||
|
||||
assert %{"status" => %{"content" => response}} = json_response_and_validate_schema(conn, 200)
|
||||
assert response == expected_response
|
||||
|
|
|
|||
|
|
@ -125,13 +125,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
results =
|
||||
conn
|
||||
|> get(
|
||||
"/api/v2/search?#{
|
||||
URI.encode_query(%{
|
||||
q:
|
||||
"https://www.washingtonpost.com/sports/2020/06/10/" <>
|
||||
"nascar-ban-display-confederate-flag-all-events-properties/"
|
||||
})
|
||||
}"
|
||||
"/api/v2/search?#{URI.encode_query(%{q: "https://www.washingtonpost.com/sports/2020/06/10/" <> "nascar-ban-display-confederate-flag-all-events-properties/"})}"
|
||||
)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
|
|
@ -156,9 +150,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
results =
|
||||
conn
|
||||
|> get(
|
||||
"/api/v2/search?#{
|
||||
URI.encode_query(%{q: "#some #text #with #hashtags", limit: 2, offset: 1})
|
||||
}"
|
||||
"/api/v2/search?#{URI.encode_query(%{q: "#some #text #with #hashtags", limit: 2, offset: 1})}"
|
||||
)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Workers.ScheduledActivityWorker
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
@ -705,11 +706,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert {:ok, %{id: activity_id}} =
|
||||
perform_job(Pleroma.Workers.ScheduledActivityWorker, %{
|
||||
perform_job(ScheduledActivityWorker, %{
|
||||
activity_id: scheduled_id
|
||||
})
|
||||
|
||||
assert Repo.all(Oban.Job) == []
|
||||
refute_enqueued(worker: ScheduledActivityWorker)
|
||||
|
||||
object =
|
||||
Activity
|
||||
|
|
|
|||
|
|
@ -273,6 +273,24 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
[%{"id" => ^reply_from_me}, %{"id" => ^activity_id}] = response
|
||||
end
|
||||
|
||||
test "doesn't return posts from users who blocked you when :blockers_visible is disabled" do
|
||||
clear_config([:activitypub, :blockers_visible], false)
|
||||
|
||||
%{conn: conn, user: blockee} = oauth_access(["read:statuses"])
|
||||
blocker = insert(:user)
|
||||
{:ok, _} = User.block(blocker, blockee)
|
||||
|
||||
conn = assign(conn, :user, blockee)
|
||||
|
||||
{:ok, _} = CommonAPI.post(blocker, %{status: "hey!"})
|
||||
|
||||
response =
|
||||
get(conn, "/api/v1/timelines/public")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert length(response) == 0
|
||||
end
|
||||
|
||||
test "doesn't return replies if follow is posting with users from blocked domain" do
|
||||
%{conn: conn, user: blocker} = oauth_access(["read:statuses"])
|
||||
friend = insert(:user)
|
||||
|
|
|
|||
|
|
@ -1,85 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.MastoFEControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.User
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do: clear_config([:instance, :public])
|
||||
|
||||
test "put settings", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> assign(:token, insert(:oauth_token, user: user, scopes: ["write:accounts"]))
|
||||
|> put("/api/web/settings", %{"data" => %{"programming" => "socks"}})
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
assert user.mastofe_settings == %{"programming" => "socks"}
|
||||
end
|
||||
|
||||
describe "index/2 redirections" do
|
||||
setup %{conn: conn} do
|
||||
session_opts = [
|
||||
store: :cookie,
|
||||
key: "_test",
|
||||
signing_salt: "cooldude"
|
||||
]
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> Plug.Session.call(Plug.Session.init(session_opts))
|
||||
|> fetch_session()
|
||||
|
||||
test_path = "/web/statuses/test"
|
||||
%{conn: conn, path: test_path}
|
||||
end
|
||||
|
||||
test "redirects not logged-in users to the login page", %{conn: conn, path: path} do
|
||||
conn = get(conn, path)
|
||||
|
||||
assert conn.status == 302
|
||||
assert redirected_to(conn) == "/web/login"
|
||||
end
|
||||
|
||||
test "redirects not logged-in users to the login page on private instances", %{
|
||||
conn: conn,
|
||||
path: path
|
||||
} do
|
||||
clear_config([:instance, :public], false)
|
||||
|
||||
conn = get(conn, path)
|
||||
|
||||
assert conn.status == 302
|
||||
assert redirected_to(conn) == "/web/login"
|
||||
end
|
||||
|
||||
test "does not redirect logged in users to the login page", %{conn: conn, path: path} do
|
||||
{:ok, app} = Pleroma.Web.MastodonAPI.AuthController.local_mastofe_app()
|
||||
token = insert(:oauth_token, app: app, scopes: ["read"])
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, token.user)
|
||||
|> assign(:token, token)
|
||||
|> get(path)
|
||||
|
||||
assert conn.status == 200
|
||||
end
|
||||
|
||||
test "saves referer path to session", %{conn: conn, path: path} do
|
||||
conn = get(conn, path)
|
||||
return_to = Plug.Conn.get_session(conn, :return_to)
|
||||
|
||||
assert return_to == path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -35,8 +35,8 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
|||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{
|
||||
"pleroma_settings_store" => %{
|
||||
masto_fe: %{
|
||||
theme: "bla"
|
||||
soapbox_fe: %{
|
||||
themeMode: "bla"
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -46,7 +46,7 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
|||
assert user_data["pleroma"]["settings_store"] ==
|
||||
%{
|
||||
"pleroma_fe" => %{"theme" => "bla"},
|
||||
"masto_fe" => %{"theme" => "bla"}
|
||||
"soapbox_fe" => %{"themeMode" => "bla"}
|
||||
}
|
||||
|
||||
user = Repo.get(User, user_data["id"])
|
||||
|
|
@ -60,8 +60,8 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
|||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{
|
||||
"pleroma_settings_store" => %{
|
||||
masto_fe: %{
|
||||
theme: "blub"
|
||||
soapbox_fe: %{
|
||||
themeMode: "blub"
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -71,7 +71,7 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
|||
assert user_data["pleroma"]["settings_store"] ==
|
||||
%{
|
||||
"pleroma_fe" => %{"theme" => "bla"},
|
||||
"masto_fe" => %{"theme" => "blub"}
|
||||
"soapbox_fe" => %{"themeMode" => "blub"}
|
||||
}
|
||||
|
||||
assert_called(Pleroma.Web.Federator.publish(:_))
|
||||
|
|
@ -88,9 +88,7 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
|||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
|
||||
assert user_data["note"] ==
|
||||
~s(I drink <a class="hashtag" data-tag="cofe" href="http://localhost:4001/tag/cofe">#cofe</a> with <span class="h-card"><a class="u-url mention" data-user="#{
|
||||
user2.id
|
||||
}" href="#{user2.ap_id}" rel="ugc">@<span>#{user2.nickname}</span></a></span><br/><br/>suya..)
|
||||
~s(I drink <a class="hashtag" data-tag="cofe" href="http://localhost:4001/tag/cofe">#cofe</a> with <span class="h-card"><a class="u-url mention" data-user="#{user2.id}" href="#{user2.ap_id}" rel="ugc">@<span>#{user2.nickname}</span></a></span><br/><br/>suya..)
|
||||
|
||||
assert user_data["source"]["note"] == raw_bio
|
||||
|
||||
|
|
|
|||
|
|
@ -196,6 +196,27 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
test_notifications_rendering([notification], user, [expected])
|
||||
end
|
||||
|
||||
test "Poll notification" do
|
||||
user = insert(:user)
|
||||
activity = insert(:question_activity, user: user)
|
||||
{:ok, [notification]} = Notification.create_poll_notifications(activity)
|
||||
|
||||
expected = %{
|
||||
id: to_string(notification.id),
|
||||
pleroma: %{is_seen: false, is_muted: false},
|
||||
type: "poll",
|
||||
account:
|
||||
AccountView.render("show.json", %{
|
||||
user: user,
|
||||
for: user
|
||||
}),
|
||||
status: StatusView.render("show.json", %{activity: activity, for: user}),
|
||||
created_at: Utils.to_masto_date(notification.inserted_at)
|
||||
}
|
||||
|
||||
test_notifications_rendering([notification], user, [expected])
|
||||
end
|
||||
|
||||
test "Report notification" do
|
||||
reporting_user = insert(:user)
|
||||
reported_user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -81,9 +81,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
|||
missing_dependencies = Pleroma.Helpers.MediaHelper.missing_dependencies()
|
||||
|
||||
assert missing_dependencies == [],
|
||||
"Error: missing dependencies (please refer to `docs/installation`): #{
|
||||
inspect(missing_dependencies)
|
||||
}"
|
||||
"Error: missing dependencies (please refer to `docs/installation`): #{inspect(missing_dependencies)}"
|
||||
end
|
||||
|
||||
setup do
|
||||
|
|
|
|||
|
|
@ -150,37 +150,127 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||
)
|
||||
end
|
||||
|
||||
test "it shows MRF transparency data if enabled", %{conn: conn} do
|
||||
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
|
||||
clear_config([:mrf, :transparency], true)
|
||||
describe "Quarantined instances" do
|
||||
setup do
|
||||
clear_config([:mrf, :transparency], true)
|
||||
quarantined_instances = [{"example.com", "reason to quarantine"}]
|
||||
clear_config([:instance, :quarantined_instances], quarantined_instances)
|
||||
end
|
||||
|
||||
simple_config = %{"reject" => ["example.com"]}
|
||||
clear_config(:mrf_simple, simple_config)
|
||||
test "shows quarantined instances data if enabled", %{conn: conn} do
|
||||
expected_config = ["example.com"]
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/nodeinfo/2.1.json")
|
||||
|> json_response(:ok)
|
||||
response =
|
||||
conn
|
||||
|> get("/nodeinfo/2.1.json")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert response["metadata"]["federation"]["mrf_simple"] == simple_config
|
||||
assert response["metadata"]["federation"]["quarantined_instances"] == expected_config
|
||||
end
|
||||
|
||||
test "shows extra information in the quarantined_info field for relevant entries", %{
|
||||
conn: conn
|
||||
} do
|
||||
clear_config([:mrf, :transparency], true)
|
||||
|
||||
expected_config = %{
|
||||
"quarantined_instances" => %{
|
||||
"example.com" => %{"reason" => "reason to quarantine"}
|
||||
}
|
||||
}
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/nodeinfo/2.1.json")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert response["metadata"]["federation"]["quarantined_instances_info"] == expected_config
|
||||
end
|
||||
end
|
||||
|
||||
test "it performs exclusions from MRF transparency data if configured", %{conn: conn} do
|
||||
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
|
||||
clear_config([:mrf, :transparency], true)
|
||||
clear_config([:mrf, :transparency_exclusions], ["other.site"])
|
||||
describe "MRF SimplePolicy" do
|
||||
setup do
|
||||
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
|
||||
clear_config([:mrf, :transparency], true)
|
||||
end
|
||||
|
||||
simple_config = %{"reject" => ["example.com", "other.site"]}
|
||||
clear_config(:mrf_simple, simple_config)
|
||||
test "shows MRF transparency data if enabled", %{conn: conn} do
|
||||
simple_config = %{"reject" => [{"example.com", ""}]}
|
||||
clear_config(:mrf_simple, simple_config)
|
||||
|
||||
expected_config = %{"reject" => ["example.com"]}
|
||||
expected_config = %{"reject" => ["example.com"]}
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/nodeinfo/2.1.json")
|
||||
|> json_response(:ok)
|
||||
response =
|
||||
conn
|
||||
|> get("/nodeinfo/2.1.json")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert response["metadata"]["federation"]["mrf_simple"] == expected_config
|
||||
assert response["metadata"]["federation"]["exclusions"] == true
|
||||
assert response["metadata"]["federation"]["mrf_simple"] == expected_config
|
||||
end
|
||||
|
||||
test "performs exclusions from MRF transparency data if configured", %{conn: conn} do
|
||||
clear_config([:mrf, :transparency_exclusions], [
|
||||
{"other.site", "We don't want them to know"}
|
||||
])
|
||||
|
||||
simple_config = %{"reject" => [{"example.com", ""}, {"other.site", ""}]}
|
||||
clear_config(:mrf_simple, simple_config)
|
||||
|
||||
expected_config = %{"reject" => ["example.com"]}
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/nodeinfo/2.1.json")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert response["metadata"]["federation"]["mrf_simple"] == expected_config
|
||||
assert response["metadata"]["federation"]["exclusions"] == true
|
||||
end
|
||||
|
||||
test "shows extra information in the mrf_simple_info field for relevant entries", %{
|
||||
conn: conn
|
||||
} do
|
||||
simple_config = %{
|
||||
media_removal: [{"no.media", "LEEWWWDD >//<"}],
|
||||
media_nsfw: [],
|
||||
federated_timeline_removal: [{"no.ftl", ""}],
|
||||
report_removal: [],
|
||||
reject: [
|
||||
{"example.instance", "Some reason"},
|
||||
{"uwu.owo", "awoo to much"},
|
||||
{"no.reason", ""}
|
||||
],
|
||||
followers_only: [],
|
||||
accept: [],
|
||||
avatar_removal: [],
|
||||
banner_removal: [],
|
||||
reject_deletes: [
|
||||
{"peak.me", "I want to peak at what they don't want me to see, eheh"}
|
||||
]
|
||||
}
|
||||
|
||||
clear_config(:mrf_simple, simple_config)
|
||||
|
||||
clear_config([:mrf, :transparency_exclusions], [
|
||||
{"peak.me", "I don't want them to know"}
|
||||
])
|
||||
|
||||
expected_config = %{
|
||||
"media_removal" => %{
|
||||
"no.media" => %{"reason" => "LEEWWWDD >//<"}
|
||||
},
|
||||
"reject" => %{
|
||||
"example.instance" => %{"reason" => "Some reason"},
|
||||
"uwu.owo" => %{"reason" => "awoo to much"}
|
||||
}
|
||||
}
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/nodeinfo/2.1.json")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert response["metadata"]["federation"]["mrf_simple_info"] == expected_config
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -174,9 +174,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
response =
|
||||
conn
|
||||
|> get(
|
||||
"/api/v1/pleroma/accounts/#{user.id}/favourites?since_id=#{third_activity.id}&max_id=#{
|
||||
seventh_activity.id
|
||||
}"
|
||||
"/api/v1/pleroma/accounts/#{user.id}/favourites?since_id=#{third_activity.id}&max_id=#{seventh_activity.id}"
|
||||
)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
|
|
|
|||
|
|
@ -94,9 +94,7 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
|||
"internal",
|
||||
".well-known",
|
||||
"nodeinfo",
|
||||
"web",
|
||||
"auth",
|
||||
"embed",
|
||||
"proxy",
|
||||
"test",
|
||||
"user_exists",
|
||||
|
|
|
|||
47
test/pleroma/web/plugs/user_is_staff_plug_test.exs
Normal file
47
test/pleroma/web/plugs/user_is_staff_plug_test.exs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# 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.UserIsStaffPlugTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
alias Pleroma.Web.Plugs.UserIsStaffPlug
|
||||
import Pleroma.Factory
|
||||
|
||||
test "accepts a user that is an admin" do
|
||||
user = insert(:user, is_admin: true)
|
||||
|
||||
conn = assign(build_conn(), :user, user)
|
||||
|
||||
ret_conn = UserIsStaffPlug.call(conn, %{})
|
||||
|
||||
assert conn == ret_conn
|
||||
end
|
||||
|
||||
test "accepts a user that is a moderator" do
|
||||
user = insert(:user, is_moderator: true)
|
||||
|
||||
conn = assign(build_conn(), :user, user)
|
||||
|
||||
ret_conn = UserIsStaffPlug.call(conn, %{})
|
||||
|
||||
assert conn == ret_conn
|
||||
end
|
||||
|
||||
test "denies a user that isn't a staff member" do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> UserIsStaffPlug.call(%{})
|
||||
|
||||
assert conn.status == 403
|
||||
end
|
||||
|
||||
test "denies when a user isn't set" do
|
||||
conn = UserIsStaffPlug.call(build_conn(), %{})
|
||||
|
||||
assert conn.status == 403
|
||||
end
|
||||
end
|
||||
|
|
@ -66,9 +66,7 @@ defmodule Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrlTest do
|
|||
end
|
||||
|
||||
defp construct_s3_url(timestamp, valid_till) do
|
||||
"https://pleroma.s3.ap-southeast-1.amazonaws.com/sachin%20%281%29%20_a%20-%25%2Aasdasd%20BNN%20bnnn%20.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIBLWWK6RGDQXDLJQ%2F20190716%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=#{
|
||||
timestamp
|
||||
}&X-Amz-Expires=#{valid_till}&X-Amz-Signature=04ffd6b98634f4b1bbabc62e0fac4879093cd54a6eed24fe8eb38e8369526bbf&X-Amz-SignedHeaders=host"
|
||||
"https://pleroma.s3.ap-southeast-1.amazonaws.com/sachin%20%281%29%20_a%20-%25%2Aasdasd%20BNN%20bnnn%20.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIBLWWK6RGDQXDLJQ%2F20190716%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=#{timestamp}&X-Amz-Expires=#{valid_till}&X-Amz-Signature=04ffd6b98634f4b1bbabc62e0fac4879093cd54a6eed24fe8eb38e8369526bbf&X-Amz-SignedHeaders=host"
|
||||
end
|
||||
|
||||
defp construct_metadata(timestamp, valid_till, url) do
|
||||
|
|
|
|||
|
|
@ -5,10 +5,14 @@
|
|||
defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.PasswordResetToken
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.OAuth.Token
|
||||
import Pleroma.Factory
|
||||
import Swoosh.TestAssertions
|
||||
|
||||
describe "GET /api/pleroma/password_reset/token" do
|
||||
test "it returns error when token invalid", %{conn: conn} do
|
||||
|
|
@ -116,4 +120,94 @@ defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do
|
|||
assert User.get_by_id(user.id).password_reset_pending == false
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /auth/password, with valid parameters" do
|
||||
setup %{conn: conn} do
|
||||
user = insert(:user)
|
||||
conn = post(conn, "/auth/password?email=#{user.email}")
|
||||
%{conn: conn, user: user}
|
||||
end
|
||||
|
||||
test "it returns 204", %{conn: conn} do
|
||||
assert empty_json_response(conn)
|
||||
end
|
||||
|
||||
test "it creates a PasswordResetToken record for user", %{user: user} do
|
||||
token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
|
||||
assert token_record
|
||||
end
|
||||
|
||||
test "it sends an email to user", %{user: user} do
|
||||
ObanHelpers.perform_all()
|
||||
token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
|
||||
|
||||
email = Pleroma.Emails.UserEmail.password_reset_email(user, token_record.token)
|
||||
notify_email = Config.get([:instance, :notify_email])
|
||||
instance_name = Config.get([:instance, :name])
|
||||
|
||||
assert_email_sent(
|
||||
from: {instance_name, notify_email},
|
||||
to: {user.name, user.email},
|
||||
html_body: email.html_body
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /auth/password, with nickname" do
|
||||
test "it returns 204", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
assert conn
|
||||
|> post("/auth/password?nickname=#{user.nickname}")
|
||||
|> empty_json_response()
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
|
||||
|
||||
email = Pleroma.Emails.UserEmail.password_reset_email(user, token_record.token)
|
||||
notify_email = Config.get([:instance, :notify_email])
|
||||
instance_name = Config.get([:instance, :name])
|
||||
|
||||
assert_email_sent(
|
||||
from: {instance_name, notify_email},
|
||||
to: {user.name, user.email},
|
||||
html_body: email.html_body
|
||||
)
|
||||
end
|
||||
|
||||
test "it doesn't fail when a user has no email", %{conn: conn} do
|
||||
user = insert(:user, %{email: nil})
|
||||
|
||||
assert conn
|
||||
|> post("/auth/password?nickname=#{user.nickname}")
|
||||
|> empty_json_response()
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /auth/password, with invalid parameters" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
{:ok, user: user}
|
||||
end
|
||||
|
||||
test "it returns 204 when user is not found", %{conn: conn, user: user} do
|
||||
conn = post(conn, "/auth/password?email=nonexisting_#{user.email}")
|
||||
|
||||
assert empty_json_response(conn)
|
||||
end
|
||||
|
||||
test "it returns 204 when user is not local", %{conn: conn, user: user} do
|
||||
{:ok, user} = Repo.update(Ecto.Changeset.change(user, local: false))
|
||||
conn = post(conn, "/auth/password?email=#{user.email}")
|
||||
|
||||
assert empty_json_response(conn)
|
||||
end
|
||||
|
||||
test "it returns 204 when user is deactivated", %{conn: conn, user: user} do
|
||||
{:ok, user} = Repo.update(Ecto.Changeset.change(user, is_active: false, local: true))
|
||||
conn = post(conn, "/auth/password?email=#{user.email}")
|
||||
|
||||
assert empty_json_response(conn)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -139,9 +139,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
{:ok, user2} = TwitterAPI.register_user(data2)
|
||||
|
||||
expected_text =
|
||||
~s(<span class="h-card"><a class="u-url mention" data-user="#{user1.id}" href="#{
|
||||
user1.ap_id
|
||||
}" rel="ugc">@<span>john</span></a></span> test)
|
||||
~s(<span class="h-card"><a class="u-url mention" data-user="#{user1.id}" href="#{user1.ap_id}" rel="ugc">@<span>john</span></a></span> test)
|
||||
|
||||
assert user2.bio == expected_text
|
||||
end
|
||||
|
|
|
|||
|
|
@ -26,11 +26,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
test "it updates notification settings", %{user: user, conn: conn} do
|
||||
conn
|
||||
|> put(
|
||||
"/api/pleroma/notification_settings?#{
|
||||
URI.encode_query(%{
|
||||
block_from_strangers: true
|
||||
})
|
||||
}"
|
||||
"/api/pleroma/notification_settings?#{URI.encode_query(%{block_from_strangers: true})}"
|
||||
)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
|
|
@ -45,11 +41,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
test "it updates notification settings to enable hiding contents", %{user: user, conn: conn} do
|
||||
conn
|
||||
|> put(
|
||||
"/api/pleroma/notification_settings?#{
|
||||
URI.encode_query(%{
|
||||
hide_notification_contents: 1
|
||||
})
|
||||
}"
|
||||
"/api/pleroma/notification_settings?#{URI.encode_query(%{hide_notification_contents: 1})}"
|
||||
)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
|
|
@ -302,9 +294,22 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
assert %{"error" => "Missing field: email."} = json_response_and_validate_schema(conn, 400)
|
||||
end
|
||||
|
||||
test "with proper permissions, valid password and blank email", %{
|
||||
conn: conn
|
||||
} do
|
||||
test "with proper permissions, valid password and blank email, when instance requires user email",
|
||||
%{
|
||||
conn: conn
|
||||
} do
|
||||
orig_account_activation_required =
|
||||
Pleroma.Config.get([:instance, :account_activation_required])
|
||||
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put(
|
||||
[:instance, :account_activation_required],
|
||||
orig_account_activation_required
|
||||
)
|
||||
end)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|
|
@ -313,6 +318,30 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
assert json_response_and_validate_schema(conn, 200) == %{"error" => "Email can't be blank."}
|
||||
end
|
||||
|
||||
test "with proper permissions, valid password and blank email, when instance does not require user email",
|
||||
%{
|
||||
conn: conn
|
||||
} do
|
||||
orig_account_activation_required =
|
||||
Pleroma.Config.get([:instance, :account_activation_required])
|
||||
|
||||
Pleroma.Config.put([:instance, :account_activation_required], false)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put(
|
||||
[:instance, :account_activation_required],
|
||||
orig_account_activation_required
|
||||
)
|
||||
end)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> post("/api/pleroma/change_email", %{password: "test", email: ""})
|
||||
|
||||
assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"}
|
||||
end
|
||||
|
||||
test "with proper permissions, valid password and non unique email", %{
|
||||
conn: conn
|
||||
} do
|
||||
|
|
|
|||
|
|
@ -24,9 +24,7 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
|
|||
assert response.status == 200
|
||||
|
||||
assert response.resp_body ==
|
||||
~s(<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" template="#{
|
||||
Pleroma.Web.Endpoint.url()
|
||||
}/.well-known/webfinger?resource={uri}" type="application/xrd+xml" /></XRD>)
|
||||
~s(<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" template="#{Pleroma.Web.Endpoint.url()}/.well-known/webfinger?resource={uri}" type="application/xrd+xml" /></XRD>)
|
||||
end
|
||||
|
||||
test "Webfinger JRD" do
|
||||
|
|
|
|||
|
|
@ -29,9 +29,7 @@ defmodule Pleroma.Tests.ApiSpecHelpers do
|
|||
end)
|
||||
|
||||
flunk(
|
||||
"Value does not conform to schema #{schema.title}: #{Enum.join(errors, "\n")}\n#{
|
||||
inspect(value)
|
||||
}"
|
||||
"Value does not conform to schema #{schema.title}: #{Enum.join(errors, "\n")}\n#{inspect(value)}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -102,9 +102,7 @@ defmodule Pleroma.Web.ConnCase do
|
|||
end)
|
||||
|
||||
flunk(
|
||||
"Response does not conform to schema of #{op_id} operation: #{
|
||||
Enum.join(errors, "\n")
|
||||
}\n#{inspect(json)}"
|
||||
"Response does not conform to schema of #{op_id} operation: #{Enum.join(errors, "\n")}\n#{inspect(json)}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -142,6 +142,11 @@ defmodule Pleroma.Factory do
|
|||
}
|
||||
end
|
||||
|
||||
def followers_only_note_factory(attrs \\ %{}) do
|
||||
%Pleroma.Object{data: data} = note_factory(attrs)
|
||||
%Pleroma.Object{data: Map.merge(data, %{"to" => [data["actor"] <> "/followers"]})}
|
||||
end
|
||||
|
||||
def audio_factory(attrs \\ %{}) do
|
||||
text = sequence(:text, &"lain radio episode #{&1}")
|
||||
|
||||
|
|
@ -208,6 +213,38 @@ defmodule Pleroma.Factory do
|
|||
}
|
||||
end
|
||||
|
||||
def question_factory(attrs \\ %{}) do
|
||||
user = attrs[:user] || insert(:user)
|
||||
|
||||
data = %{
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
|
||||
"type" => "Question",
|
||||
"actor" => user.ap_id,
|
||||
"attributedTo" => user.ap_id,
|
||||
"attachment" => [],
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"cc" => [user.follower_address],
|
||||
"context" => Pleroma.Web.ActivityPub.Utils.generate_context_id(),
|
||||
"closed" => DateTime.utc_now() |> DateTime.add(86_400) |> DateTime.to_iso8601(),
|
||||
"oneOf" => [
|
||||
%{
|
||||
"type" => "Note",
|
||||
"name" => "chocolate",
|
||||
"replies" => %{"totalItems" => 0, "type" => "Collection"}
|
||||
},
|
||||
%{
|
||||
"type" => "Note",
|
||||
"name" => "vanilla",
|
||||
"replies" => %{"totalItems" => 0, "type" => "Collection"}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
%Pleroma.Object{
|
||||
data: merge_attributes(data, Map.get(attrs, :data, %{}))
|
||||
}
|
||||
end
|
||||
|
||||
def direct_note_activity_factory do
|
||||
dm = insert(:direct_note)
|
||||
|
||||
|
|
@ -267,6 +304,33 @@ defmodule Pleroma.Factory do
|
|||
|> Map.merge(attrs)
|
||||
end
|
||||
|
||||
def followers_only_note_activity_factory(attrs \\ %{}) do
|
||||
user = attrs[:user] || insert(:user)
|
||||
note = insert(:followers_only_note, user: user)
|
||||
|
||||
data_attrs = attrs[:data_attrs] || %{}
|
||||
attrs = Map.drop(attrs, [:user, :note, :data_attrs])
|
||||
|
||||
data =
|
||||
%{
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||
"type" => "Create",
|
||||
"actor" => note.data["actor"],
|
||||
"to" => note.data["to"],
|
||||
"object" => note.data,
|
||||
"published" => DateTime.utc_now() |> DateTime.to_iso8601(),
|
||||
"context" => note.data["context"]
|
||||
}
|
||||
|> Map.merge(data_attrs)
|
||||
|
||||
%Pleroma.Activity{
|
||||
data: data,
|
||||
actor: data["actor"],
|
||||
recipients: data["to"]
|
||||
}
|
||||
|> Map.merge(attrs)
|
||||
end
|
||||
|
||||
def note_activity_factory(attrs \\ %{}) do
|
||||
user = attrs[:user] || insert(:user)
|
||||
note = attrs[:note] || insert(:note, user: user)
|
||||
|
|
@ -396,6 +460,33 @@ defmodule Pleroma.Factory do
|
|||
}
|
||||
end
|
||||
|
||||
def question_activity_factory(attrs \\ %{}) do
|
||||
user = attrs[:user] || insert(:user)
|
||||
question = attrs[:question] || insert(:question, user: user)
|
||||
|
||||
data_attrs = attrs[:data_attrs] || %{}
|
||||
attrs = Map.drop(attrs, [:user, :question, :data_attrs])
|
||||
|
||||
data =
|
||||
%{
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||
"type" => "Create",
|
||||
"actor" => question.data["actor"],
|
||||
"to" => question.data["to"],
|
||||
"object" => question.data["id"],
|
||||
"published" => DateTime.utc_now() |> DateTime.to_iso8601(),
|
||||
"context" => question.data["context"]
|
||||
}
|
||||
|> Map.merge(data_attrs)
|
||||
|
||||
%Pleroma.Activity{
|
||||
data: data,
|
||||
actor: data["actor"],
|
||||
recipients: data["to"]
|
||||
}
|
||||
|> Map.merge(attrs)
|
||||
end
|
||||
|
||||
def oauth_app_factory do
|
||||
%Pleroma.Web.OAuth.App{
|
||||
client_name: sequence(:client_name, &"Some client #{&1}"),
|
||||
|
|
|
|||
|
|
@ -1313,9 +1313,7 @@ defmodule HttpRequestMock do
|
|||
|
||||
def get(url, query, body, headers) do
|
||||
{:error,
|
||||
"Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{
|
||||
inspect(headers)
|
||||
}"}
|
||||
"Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"}
|
||||
end
|
||||
|
||||
# POST Requests
|
||||
|
|
@ -1381,9 +1379,7 @@ defmodule HttpRequestMock do
|
|||
|
||||
def post(url, query, body, headers) do
|
||||
{:error,
|
||||
"Mock response not implemented for POST #{inspect(url)}, #{query}, #{inspect(body)}, #{
|
||||
inspect(headers)
|
||||
}"}
|
||||
"Mock response not implemented for POST #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"}
|
||||
end
|
||||
|
||||
# Most of the rich media mocks are missing HEAD requests, so we just return 404.
|
||||
|
|
@ -1398,8 +1394,6 @@ defmodule HttpRequestMock do
|
|||
|
||||
def head(url, query, body, headers) do
|
||||
{:error,
|
||||
"Mock response not implemented for HEAD #{inspect(url)}, #{query}, #{inspect(body)}, #{
|
||||
inspect(headers)
|
||||
}"}
|
||||
"Mock response not implemented for HEAD #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue