Merge remote-tracking branch 'origin/develop' into apps-api-endpoint
This commit is contained in:
commit
f5c3d45120
3865 changed files with 4840 additions and 12084 deletions
|
|
@ -82,6 +82,7 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
on_exit(fn -> Restarter.Pleroma.refresh() end)
|
||||
end
|
||||
|
||||
@tag :erratic
|
||||
test "don't restart if no reboot time settings were changed" do
|
||||
clear_config(:emoji)
|
||||
insert(:config, key: :emoji, value: [groups: [a: 1, b: 2]])
|
||||
|
|
@ -92,18 +93,21 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
)
|
||||
end
|
||||
|
||||
@tag :erratic
|
||||
test "on reboot time key" do
|
||||
clear_config(:shout)
|
||||
insert(:config, key: :shout, value: [enabled: false])
|
||||
assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
|
||||
end
|
||||
|
||||
@tag :erratic
|
||||
test "on reboot time subkey" do
|
||||
clear_config(Pleroma.Captcha)
|
||||
insert(:config, key: Pleroma.Captcha, value: [seconds_valid: 60])
|
||||
assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
|
||||
end
|
||||
|
||||
@tag :erratic
|
||||
test "don't restart pleroma on reboot time key and subkey if there is false flag" do
|
||||
clear_config(:shout)
|
||||
clear_config(Pleroma.Captcha)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ defmodule Pleroma.Docs.GeneratorTest do
|
|||
key: :filters,
|
||||
type: {:list, :module},
|
||||
description: "",
|
||||
suggestions: {:list_behaviour_implementations, Pleroma.Web.ActivityPub.MRF}
|
||||
suggestions: {:list_behaviour_implementations, Pleroma.Web.ActivityPub.MRF.Policy}
|
||||
},
|
||||
%{
|
||||
key: Pleroma.Upload,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ defmodule Pleroma.Gun.ConnectionPoolTest do
|
|||
end
|
||||
end
|
||||
|
||||
@tag :erratic
|
||||
test "connection limit is respected with concurrent requests" do
|
||||
clear_config([:connections_pool, :max_connections]) do
|
||||
clear_config([:connections_pool, :max_connections], 1)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -34,4 +34,14 @@ defmodule Pleroma.User.QueryTest do
|
|||
assert %{internal: true} |> Query.build() |> Repo.aggregate(:count) == 2
|
||||
end
|
||||
end
|
||||
|
||||
test "is_suggested param" do
|
||||
_user1 = insert(:user, is_suggested: false)
|
||||
user2 = insert(:user, is_suggested: true)
|
||||
|
||||
assert [^user2] =
|
||||
%{is_suggested: true}
|
||||
|> User.Query.build()
|
||||
|> Repo.all()
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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: %{},
|
||||
|
|
@ -1720,6 +1718,38 @@ defmodule Pleroma.UserTest do
|
|||
assert user.banner == %{}
|
||||
end
|
||||
|
||||
describe "set_suggestion" do
|
||||
test "suggests a user" do
|
||||
user = insert(:user, is_suggested: false)
|
||||
refute user.is_suggested
|
||||
{:ok, user} = User.set_suggestion(user, true)
|
||||
assert user.is_suggested
|
||||
end
|
||||
|
||||
test "suggests a list of users" do
|
||||
unsuggested_users = [
|
||||
insert(:user, is_suggested: false),
|
||||
insert(:user, is_suggested: false),
|
||||
insert(:user, is_suggested: false)
|
||||
]
|
||||
|
||||
{:ok, users} = User.set_suggestion(unsuggested_users, true)
|
||||
|
||||
assert Enum.count(users) == 3
|
||||
|
||||
Enum.each(users, fn user ->
|
||||
assert user.is_suggested
|
||||
end)
|
||||
end
|
||||
|
||||
test "unsuggests a user" do
|
||||
user = insert(:user, is_suggested: true)
|
||||
assert user.is_suggested
|
||||
{:ok, user} = User.set_suggestion(user, false)
|
||||
refute user.is_suggested
|
||||
end
|
||||
end
|
||||
|
||||
test "get_public_key_for_ap_id fetches a user that's not in the db" do
|
||||
assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
|
||||
end
|
||||
|
|
@ -1888,9 +1918,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 +2227,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 +2276,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 +2442,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"})
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -105,5 +105,37 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
|
|||
|
||||
assert attachment.mediaType == "image/jpeg"
|
||||
end
|
||||
|
||||
test "it transforms image dimentions to our internal format" do
|
||||
attachment = %{
|
||||
"type" => "Document",
|
||||
"name" => "Hello world",
|
||||
"url" => "https://media.example.tld/1.jpg",
|
||||
"width" => 880,
|
||||
"height" => 960,
|
||||
"mediaType" => "image/jpeg",
|
||||
"blurhash" => "eTKL26+HDjcEIBVl;ds+K6t301W.t7nit7y1E,R:v}ai4nXSt7V@of"
|
||||
}
|
||||
|
||||
expected = %AttachmentValidator{
|
||||
type: "Document",
|
||||
name: "Hello world",
|
||||
mediaType: "image/jpeg",
|
||||
blurhash: "eTKL26+HDjcEIBVl;ds+K6t301W.t7nit7y1E,R:v}ai4nXSt7V@of",
|
||||
url: [
|
||||
%AttachmentValidator.UrlObjectValidator{
|
||||
type: "Link",
|
||||
mediaType: "image/jpeg",
|
||||
href: "https://media.example.tld/1.jpg",
|
||||
width: 880,
|
||||
height: 960
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
{:ok, ^expected} =
|
||||
AttachmentValidator.cast_and_validate(attachment)
|
||||
|> Ecto.Changeset.apply_action(:insert)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -88,6 +88,16 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
assert User.blocks?(user, blocked)
|
||||
end
|
||||
|
||||
test "it updates following relationship", %{user: user, blocked: blocked, block: block} do
|
||||
{:ok, _, _} = SideEffects.handle(block)
|
||||
|
||||
refute Pleroma.FollowingRelationship.get(user, blocked)
|
||||
assert User.get_follow_state(user, blocked) == nil
|
||||
assert User.get_follow_state(blocked, user) == nil
|
||||
assert User.get_follow_state(user, blocked, nil) == nil
|
||||
assert User.get_follow_state(blocked, user, nil) == nil
|
||||
end
|
||||
|
||||
test "it blocks but does not unfollow if the relevant setting is set", %{
|
||||
user: user,
|
||||
blocked: blocked,
|
||||
|
|
@ -542,4 +552,74 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "removing a follower" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(user, followed)
|
||||
|
||||
{:ok, reject_data, []} = Builder.reject(followed, follow_activity)
|
||||
{:ok, reject, _meta} = ActivityPub.persist(reject_data, local: true)
|
||||
|
||||
%{user: user, followed: followed, reject: reject}
|
||||
end
|
||||
|
||||
test "", %{user: user, followed: followed, reject: reject} do
|
||||
assert User.following?(user, followed)
|
||||
assert Pleroma.FollowingRelationship.get(user, followed)
|
||||
|
||||
{:ok, _, _} = SideEffects.handle(reject)
|
||||
|
||||
refute User.following?(user, followed)
|
||||
refute Pleroma.FollowingRelationship.get(user, followed)
|
||||
assert User.get_follow_state(user, followed) == nil
|
||||
assert User.get_follow_state(user, followed, nil) == nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "removing a follower from remote" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
followed = insert(:user, local: false)
|
||||
|
||||
# Mock a local-to-remote follow
|
||||
{:ok, follow_data, []} = Builder.follow(user, followed)
|
||||
|
||||
follow_data =
|
||||
follow_data
|
||||
|> Map.put("state", "accept")
|
||||
|
||||
{:ok, follow, _meta} = ActivityPub.persist(follow_data, local: true)
|
||||
{:ok, _, _} = SideEffects.handle(follow)
|
||||
|
||||
# Mock a remote-to-local accept
|
||||
{:ok, accept_data, _} = Builder.accept(followed, follow)
|
||||
{:ok, accept, _} = ActivityPub.persist(accept_data, local: false)
|
||||
{:ok, _, _} = SideEffects.handle(accept)
|
||||
|
||||
# Mock a remote-to-local reject
|
||||
{:ok, reject_data, []} = Builder.reject(followed, follow)
|
||||
{:ok, reject, _meta} = ActivityPub.persist(reject_data, local: false)
|
||||
|
||||
%{user: user, followed: followed, reject: reject}
|
||||
end
|
||||
|
||||
test "", %{user: user, followed: followed, reject: reject} do
|
||||
assert User.following?(user, followed)
|
||||
assert Pleroma.FollowingRelationship.get(user, followed)
|
||||
|
||||
{:ok, _, _} = SideEffects.handle(reject)
|
||||
|
||||
refute User.following?(user, followed)
|
||||
refute Pleroma.FollowingRelationship.get(user, followed)
|
||||
|
||||
assert Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(user, followed).data["state"] ==
|
||||
"reject"
|
||||
|
||||
assert User.get_follow_state(user, followed) == nil
|
||||
assert User.get_follow_state(user, followed, nil) == nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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,16 +53,13 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
|
|||
%{
|
||||
"type" => "Link",
|
||||
"mediaType" => "video/mp4",
|
||||
"name" => nil,
|
||||
"blurhash" => nil,
|
||||
"url" => [
|
||||
%{
|
||||
"href" =>
|
||||
"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link",
|
||||
"width" => nil,
|
||||
"height" => nil
|
||||
"width" => 480
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -78,16 +75,13 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
|
|||
%{
|
||||
"type" => "Link",
|
||||
"mediaType" => "video/mp4",
|
||||
"name" => nil,
|
||||
"blurhash" => nil,
|
||||
"url" => [
|
||||
%{
|
||||
"href" =>
|
||||
"https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link",
|
||||
"width" => nil,
|
||||
"height" => nil
|
||||
"height" => 1080
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -110,16 +104,13 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
|
|||
%{
|
||||
"type" => "Link",
|
||||
"mediaType" => "video/mp4",
|
||||
"name" => nil,
|
||||
"blurhash" => nil,
|
||||
"url" => [
|
||||
%{
|
||||
"href" =>
|
||||
"https://peertube.stream/static/streaming-playlists/hls/abece3c3-b9c6-47f4-8040-f3eed8c602e6/abece3c3-b9c6-47f4-8040-f3eed8c602e6-1080-fragmented.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link",
|
||||
"width" => nil,
|
||||
"height" => nil
|
||||
"height" => 1080
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -524,4 +524,44 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "fix_attachments/1" do
|
||||
test "puts dimensions into attachment url field" do
|
||||
object = %{
|
||||
"attachment" => [
|
||||
%{
|
||||
"type" => "Document",
|
||||
"name" => "Hello world",
|
||||
"url" => "https://media.example.tld/1.jpg",
|
||||
"width" => 880,
|
||||
"height" => 960,
|
||||
"mediaType" => "image/jpeg",
|
||||
"blurhash" => "eTKL26+HDjcEIBVl;ds+K6t301W.t7nit7y1E,R:v}ai4nXSt7V@of"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
expected = %{
|
||||
"attachment" => [
|
||||
%{
|
||||
"type" => "Document",
|
||||
"name" => "Hello world",
|
||||
"url" => [
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mediaType" => "image/jpeg",
|
||||
"href" => "https://media.example.tld/1.jpg",
|
||||
"width" => 880,
|
||||
"height" => 960
|
||||
}
|
||||
],
|
||||
"mediaType" => "image/jpeg",
|
||||
"blurhash" => "eTKL26+HDjcEIBVl;ds+K6t301W.t7nit7y1E,R:v}ai4nXSt7V@of"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
assert Transmogrifier.fix_attachments(object) == expected
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -213,6 +213,20 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
assert refresh_record(follow_activity).data["state"] == "accept"
|
||||
assert refresh_record(follow_activity_two).data["state"] == "accept"
|
||||
end
|
||||
|
||||
test "also updates the state of accepted follows" do
|
||||
user = insert(:user)
|
||||
follower = insert(:user)
|
||||
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, user)
|
||||
{:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user)
|
||||
|
||||
{:ok, follow_activity_two} =
|
||||
Utils.update_follow_state_for_all(follow_activity_two, "reject")
|
||||
|
||||
assert refresh_record(follow_activity).data["state"] == "reject"
|
||||
assert refresh_record(follow_activity_two).data["state"] == "reject"
|
||||
end
|
||||
end
|
||||
|
||||
describe "update_follow_state/2" do
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -873,6 +873,56 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
"@#{admin.nickname} approved users: @#{user_one.nickname}, @#{user_two.nickname}"
|
||||
end
|
||||
|
||||
test "PATCH /api/pleroma/admin/users/suggest", %{admin: admin, conn: conn} do
|
||||
user1 = insert(:user, is_suggested: false)
|
||||
user2 = insert(:user, is_suggested: false)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> patch(
|
||||
"/api/pleroma/admin/users/suggest",
|
||||
%{nicknames: [user1.nickname, user2.nickname]}
|
||||
)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert Enum.map(response["users"], & &1["is_suggested"]) == [true, true]
|
||||
[user1, user2] = Repo.reload!([user1, user2])
|
||||
|
||||
assert user1.is_suggested
|
||||
assert user2.is_suggested
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} added suggested users: @#{user1.nickname}, @#{user2.nickname}"
|
||||
end
|
||||
|
||||
test "PATCH /api/pleroma/admin/users/unsuggest", %{admin: admin, conn: conn} do
|
||||
user1 = insert(:user, is_suggested: true)
|
||||
user2 = insert(:user, is_suggested: true)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> patch(
|
||||
"/api/pleroma/admin/users/unsuggest",
|
||||
%{nicknames: [user1.nickname, user2.nickname]}
|
||||
)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert Enum.map(response["users"], & &1["is_suggested"]) == [false, false]
|
||||
[user1, user2] = Repo.reload!([user1, user2])
|
||||
|
||||
refute user1.is_suggested
|
||||
refute user2.is_suggested
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} removed suggested users: @#{user1.nickname}, @#{user2.nickname}"
|
||||
end
|
||||
|
||||
test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation", %{admin: admin, conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -906,6 +956,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
||||
"is_confirmed" => true,
|
||||
"is_approved" => true,
|
||||
"is_suggested" => false,
|
||||
"url" => user.ap_id,
|
||||
"registration_reason" => nil,
|
||||
"actor_type" => "Person",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -209,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", %{
|
||||
|
|
|
|||
17
test/pleroma/web/manifest_controller_test.exs
Normal file
17
test/pleroma/web/manifest_controller_test.exs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ManifestControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
setup do
|
||||
clear_config([:instance, :name], "Manifest Test")
|
||||
clear_config([:manifest, :theme_color], "#ff0000")
|
||||
end
|
||||
|
||||
test "manifest.json", %{conn: conn} do
|
||||
conn = get(conn, "/manifest.json")
|
||||
assert %{"name" => "Manifest Test", "theme_color" => "#ff0000"} = json_response(conn, 200)
|
||||
end
|
||||
end
|
||||
|
|
@ -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)
|
||||
|
||||
|
|
@ -924,6 +922,27 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "following with subscription and unsubscribing" do
|
||||
%{conn: conn} = oauth_access(["follow"])
|
||||
followed = insert(:user)
|
||||
|
||||
ret_conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/accounts/#{followed.id}/follow", %{notify: true})
|
||||
|
||||
assert %{"id" => _id, "subscribing" => true} =
|
||||
json_response_and_validate_schema(ret_conn, 200)
|
||||
|
||||
ret_conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/accounts/#{followed.id}/follow", %{notify: false})
|
||||
|
||||
assert %{"id" => _id, "subscribing" => false} =
|
||||
json_response_and_validate_schema(ret_conn, 200)
|
||||
end
|
||||
|
||||
test "following / unfollowing errors", %{user: user, conn: conn} do
|
||||
# self follow
|
||||
conn_res = post(conn, "/api/v1/accounts/#{user.id}/follow")
|
||||
|
|
@ -1778,4 +1797,21 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
assert [%{"id" => ^id2}] = result
|
||||
end
|
||||
|
||||
test "create a note on a user" do
|
||||
%{conn: conn} = oauth_access(["write:accounts", "read:follows"])
|
||||
other_user = insert(:user)
|
||||
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/accounts/#{other_user.id}/note", %{
|
||||
"comment" => "Example note"
|
||||
})
|
||||
|
||||
assert [%{"note" => "Example note"}] =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> get("/api/v1/accounts/relationships?id=#{other_user.id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.DirectoryControllerTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
alias Pleroma.Web.CommonAPI
|
||||
import Pleroma.Factory
|
||||
|
||||
test "GET /api/v1/directory with :profile_directory disabled returns empty array", %{conn: conn} do
|
||||
clear_config([:instance, :profile_directory], false)
|
||||
|
||||
insert(:user, is_discoverable: true)
|
||||
insert(:user, is_discoverable: true)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/directory")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert result == []
|
||||
end
|
||||
|
||||
test "GET /api/v1/directory returns discoverable users only", %{conn: conn} do
|
||||
%{id: user_id} = insert(:user, is_discoverable: true)
|
||||
insert(:user, is_discoverable: false)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/directory")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"id" => ^user_id}] = result
|
||||
end
|
||||
|
||||
test "GET /api/v1/directory returns users sorted by most recent statuses", %{conn: conn} do
|
||||
insert(:user, is_discoverable: true)
|
||||
%{id: user_id} = user = insert(:user, is_discoverable: true)
|
||||
insert(:user, is_discoverable: true)
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(user, %{status: "yay i'm discoverable"})
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/directory?order=active")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"id" => ^user_id} | _tail] = result
|
||||
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)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,11 @@
|
|||
|
||||
defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
alias Pleroma.UserRelationship
|
||||
alias Pleroma.Web.CommonAPI
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do: oauth_access(["read"])
|
||||
setup do: oauth_access(["read", "write"])
|
||||
|
||||
test "returns empty result", %{conn: conn} do
|
||||
res =
|
||||
|
|
@ -15,4 +18,66 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do
|
|||
|
||||
assert res == []
|
||||
end
|
||||
|
||||
test "returns v2 suggestions", %{conn: conn} do
|
||||
%{id: user_id} = insert(:user, is_suggested: true)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> get("/api/v2/suggestions")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"source" => "staff", "account" => %{"id" => ^user_id}}] = res
|
||||
end
|
||||
|
||||
test "returns v2 suggestions excluding dismissed accounts", %{conn: conn} do
|
||||
%{id: user_id} = insert(:user, is_suggested: true)
|
||||
|
||||
conn
|
||||
|> delete("/api/v1/suggestions/#{user_id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> get("/api/v2/suggestions")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [] = res
|
||||
end
|
||||
|
||||
test "returns v2 suggestions excluding blocked accounts", %{conn: conn, user: blocker} do
|
||||
blocked = insert(:user, is_suggested: true)
|
||||
{:ok, _} = CommonAPI.block(blocker, blocked)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> get("/api/v2/suggestions")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [] = res
|
||||
end
|
||||
|
||||
test "returns v2 suggestions excluding followed accounts", %{conn: conn, user: follower} do
|
||||
followed = insert(:user, is_suggested: true)
|
||||
{:ok, _, _, _} = CommonAPI.follow(follower, followed)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> get("/api/v2/suggestions")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [] = res
|
||||
end
|
||||
|
||||
test "dismiss suggestion", %{conn: conn, user: source} do
|
||||
target = insert(:user, is_suggested: true)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> delete("/api/v1/suggestions/#{target.id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert res == %{}
|
||||
assert UserRelationship.exists?(:suggestion_dismiss, source, target)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
fields: []
|
||||
},
|
||||
fqn: "shp@shitposter.club",
|
||||
last_status_at: nil,
|
||||
pleroma: %{
|
||||
ap_id: user.ap_id,
|
||||
also_known_as: ["https://shitposter.zone/users/shp"],
|
||||
|
|
@ -83,6 +84,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
tags: [],
|
||||
is_admin: false,
|
||||
is_moderator: false,
|
||||
is_suggested: false,
|
||||
hide_favorites: true,
|
||||
hide_followers: false,
|
||||
hide_follows: false,
|
||||
|
|
@ -174,6 +176,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
fields: []
|
||||
},
|
||||
fqn: "shp@shitposter.club",
|
||||
last_status_at: nil,
|
||||
pleroma: %{
|
||||
ap_id: user.ap_id,
|
||||
also_known_as: [],
|
||||
|
|
@ -183,6 +186,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
tags: [],
|
||||
is_admin: false,
|
||||
is_moderator: false,
|
||||
is_suggested: false,
|
||||
hide_favorites: true,
|
||||
hide_followers: false,
|
||||
hide_follows: false,
|
||||
|
|
@ -268,10 +272,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
muting: false,
|
||||
muting_notifications: false,
|
||||
subscribing: false,
|
||||
notifying: false,
|
||||
requested: false,
|
||||
domain_blocking: false,
|
||||
showing_reblogs: true,
|
||||
endorsed: false
|
||||
endorsed: false,
|
||||
note: ""
|
||||
}
|
||||
|
||||
test "represent a relationship for the following and followed user" do
|
||||
|
|
@ -293,6 +299,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
muting: true,
|
||||
muting_notifications: true,
|
||||
subscribing: true,
|
||||
notifying: true,
|
||||
showing_reblogs: false,
|
||||
id: to_string(other_user.id)
|
||||
}
|
||||
|
|
|
|||
34
test/pleroma/web/mastodon_api/views/suggestion_view_test.exs
Normal file
34
test/pleroma/web/mastodon_api/views/suggestion_view_test.exs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# 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.SuggestionViewTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Web.MastodonAPI.SuggestionView, as: View
|
||||
|
||||
test "show.json" do
|
||||
user = insert(:user, is_suggested: true)
|
||||
json = View.render("show.json", %{user: user, source: :staff, skip_visibility_check: true})
|
||||
|
||||
assert json.source == :staff
|
||||
assert json.account.id == user.id
|
||||
end
|
||||
|
||||
test "index.json" do
|
||||
user1 = insert(:user, is_suggested: true)
|
||||
user2 = insert(:user, is_suggested: true)
|
||||
user3 = insert(:user, is_suggested: true)
|
||||
|
||||
[suggestion1, suggestion2, suggestion3] =
|
||||
View.render("index.json", %{
|
||||
users: [user1, user2, user3],
|
||||
source: :staff,
|
||||
skip_visibility_check: true
|
||||
})
|
||||
|
||||
assert suggestion1.source == :staff
|
||||
assert suggestion2.account.id == user2.id
|
||||
assert suggestion3.account.url == user3.ap_id
|
||||
end
|
||||
end
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -343,4 +343,54 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
|> response(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "notice compatibility routes" do
|
||||
test "Soapbox FE", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
note_activity = insert(:note_activity, user: user)
|
||||
|
||||
resp =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/@#{user.nickname}/posts/#{note_activity.id}")
|
||||
|> response(200)
|
||||
|
||||
expected =
|
||||
"<meta content=\"#{Endpoint.url()}/notice/#{note_activity.id}\" property=\"og:url\">"
|
||||
|
||||
assert resp =~ expected
|
||||
end
|
||||
|
||||
test "Mastodon", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
note_activity = insert(:note_activity, user: user)
|
||||
|
||||
resp =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/@#{user.nickname}/#{note_activity.id}")
|
||||
|> response(200)
|
||||
|
||||
expected =
|
||||
"<meta content=\"#{Endpoint.url()}/notice/#{note_activity.id}\" property=\"og:url\">"
|
||||
|
||||
assert resp =~ expected
|
||||
end
|
||||
|
||||
test "Twitter", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
note_activity = insert(:note_activity, user: user)
|
||||
|
||||
resp =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/#{user.nickname}/status/#{note_activity.id}")
|
||||
|> response(200)
|
||||
|
||||
expected =
|
||||
"<meta content=\"#{Endpoint.url()}/notice/#{note_activity.id}\" property=\"og:url\">"
|
||||
|
||||
assert resp =~ expected
|
||||
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)
|
||||
|
||||
|
|
|
|||
60
test/pleroma/web/plugs/ensure_staff_privileged_plug_test.exs
Normal file
60
test/pleroma/web/plugs/ensure_staff_privileged_plug_test.exs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
# 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.EnsureStaffPrivilegedPlugTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
alias Pleroma.Web.Plugs.EnsureStaffPrivilegedPlug
|
||||
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 = EnsureStaffPrivilegedPlug.call(conn, %{})
|
||||
|
||||
assert conn == ret_conn
|
||||
end
|
||||
|
||||
test "accepts a user that is a moderator when :privileged_staff is enabled" do
|
||||
clear_config([:instance, :privileged_staff], true)
|
||||
user = insert(:user, is_moderator: true)
|
||||
|
||||
conn = assign(build_conn(), :user, user)
|
||||
|
||||
ret_conn = EnsureStaffPrivilegedPlug.call(conn, %{})
|
||||
|
||||
assert conn == ret_conn
|
||||
end
|
||||
|
||||
test "denies a user that is a moderator when :privileged_staff is disabled" do
|
||||
clear_config([:instance, :privileged_staff], false)
|
||||
user = insert(:user, is_moderator: true)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> EnsureStaffPrivilegedPlug.call(%{})
|
||||
|
||||
assert conn.status == 403
|
||||
end
|
||||
|
||||
test "denies a user that isn't a staff member" do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> EnsureStaffPrivilegedPlug.call(%{})
|
||||
|
||||
assert conn.status == 403
|
||||
end
|
||||
|
||||
test "denies when a user isn't set" do
|
||||
conn = EnsureStaffPrivilegedPlug.call(build_conn(), %{})
|
||||
|
||||
assert conn.status == 403
|
||||
end
|
||||
end
|
||||
|
|
@ -86,6 +86,8 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
|||
"objects",
|
||||
"activities",
|
||||
"notice",
|
||||
"@:nickname",
|
||||
":nickname",
|
||||
"users",
|
||||
"tags",
|
||||
"mailer",
|
||||
|
|
@ -94,10 +96,10 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
|||
"internal",
|
||||
".well-known",
|
||||
"nodeinfo",
|
||||
"web",
|
||||
"manifest.json",
|
||||
"auth",
|
||||
"embed",
|
||||
"proxy",
|
||||
"phoenix",
|
||||
"test",
|
||||
"user_exists",
|
||||
"check_password"
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
|
|||
refute RateLimiter.disabled?(build_conn())
|
||||
end
|
||||
|
||||
@tag :erratic
|
||||
test "it restricts based on config values" do
|
||||
limiter_name = :test_plug_opts
|
||||
scale = 80
|
||||
|
|
@ -137,6 +138,7 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
|
|||
end
|
||||
|
||||
describe "unauthenticated users" do
|
||||
@tag :erratic
|
||||
test "are restricted based on remote IP" do
|
||||
limiter_name = :test_unauthenticated
|
||||
clear_config([:rate_limit, limiter_name], [{1000, 5}, {1, 10}])
|
||||
|
|
@ -174,6 +176,7 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
@tag :erratic
|
||||
test "can have limits separate from unauthenticated connections" do
|
||||
limiter_name = :test_authenticated1
|
||||
|
||||
|
|
@ -199,6 +202,7 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
|
|||
assert conn.halted
|
||||
end
|
||||
|
||||
@tag :erratic
|
||||
test "different users are counted independently" do
|
||||
limiter_name = :test_authenticated2
|
||||
clear_config([:rate_limit, limiter_name], [{1, 10}, {1000, 5}])
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -444,7 +473,10 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|
||||
test "with proper permissions and wrong or missing password", %{conn: conn} do
|
||||
for params <- [%{"password" => "hi"}, %{}] do
|
||||
ret_conn = post(conn, "/api/pleroma/delete_account", params)
|
||||
ret_conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/delete_account", params)
|
||||
|
||||
assert json_response_and_validate_schema(ret_conn, 200) == %{
|
||||
"error" => "Invalid password."
|
||||
|
|
@ -452,8 +484,28 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "with proper permissions and valid password", %{conn: conn, user: user} do
|
||||
conn = post(conn, "/api/pleroma/delete_account?password=test")
|
||||
test "with proper permissions and valid password (URL query)", %{conn: conn, user: user} do
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/delete_account?password=test")
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"}
|
||||
|
||||
user = User.get_by_id(user.id)
|
||||
refute user.is_active
|
||||
assert user.name == nil
|
||||
assert user.bio == ""
|
||||
assert user.password_hash == nil
|
||||
end
|
||||
|
||||
test "with proper permissions and valid password (JSON body)", %{conn: conn, user: user} do
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/delete_account", %{password: "test"})
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue