Merge remote-tracking branch 'upstream/develop' into aliases
This commit is contained in:
commit
cbce880076
690 changed files with 18698 additions and 9136 deletions
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Activity.Ir.TopicsTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Activity.Ir.Topics
|
||||
|
|
@ -97,6 +97,20 @@ defmodule Pleroma.Activity.Ir.TopicsTest do
|
|||
|
||||
refute Enum.member?(topics, "hashtag:2")
|
||||
end
|
||||
|
||||
test "non-local action produces public:remote topic", %{activity: activity} do
|
||||
activity = %{activity | local: false, actor: "https://lain.com/users/lain"}
|
||||
topics = Topics.get_activity_topics(activity)
|
||||
|
||||
assert Enum.member?(topics, "public:remote:lain.com")
|
||||
end
|
||||
|
||||
test "local action doesn't produce public:remote topic", %{activity: activity} do
|
||||
activity = %{activity | local: true, actor: "https://lain.com/users/lain"}
|
||||
topics = Topics.get_activity_topics(activity)
|
||||
|
||||
refute Enum.member?(topics, "public:remote:lain.com")
|
||||
end
|
||||
end
|
||||
|
||||
describe "public visibility create events with attachments" do
|
||||
|
|
@ -128,6 +142,13 @@ defmodule Pleroma.Activity.Ir.TopicsTest do
|
|||
|
||||
refute Enum.member?(topics, "public:local:media")
|
||||
end
|
||||
|
||||
test "non-local action produces public:remote:media topic", %{activity: activity} do
|
||||
activity = %{activity | local: false, actor: "https://lain.com/users/lain"}
|
||||
topics = Topics.get_activity_topics(activity)
|
||||
|
||||
assert Enum.member?(topics, "public:remote:media:lain.com")
|
||||
end
|
||||
end
|
||||
|
||||
describe "non-public visibility" do
|
||||
|
|
|
|||
45
test/pleroma/activity/search_test.exs
Normal file
45
test/pleroma/activity/search_test.exs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Activity.SearchTest do
|
||||
alias Pleroma.Activity.Search
|
||||
alias Pleroma.Web.CommonAPI
|
||||
import Pleroma.Factory
|
||||
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
test "it finds something" do
|
||||
user = insert(:user)
|
||||
{:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
|
||||
|
||||
[result] = Search.search(nil, "wednesday")
|
||||
|
||||
assert result.id == post.id
|
||||
end
|
||||
|
||||
test "using plainto_tsquery on postgres < 11" do
|
||||
old_version = :persistent_term.get({Pleroma.Repo, :postgres_version})
|
||||
:persistent_term.put({Pleroma.Repo, :postgres_version}, 10.0)
|
||||
on_exit(fn -> :persistent_term.put({Pleroma.Repo, :postgres_version}, old_version) end)
|
||||
|
||||
user = insert(:user)
|
||||
{:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
|
||||
{:ok, _post2} = CommonAPI.post(user, %{status: "it's wednesday my bros"})
|
||||
|
||||
# plainto doesn't understand complex queries
|
||||
assert [result] = Search.search(nil, "wednesday -dudes")
|
||||
|
||||
assert result.id == post.id
|
||||
end
|
||||
|
||||
test "using websearch_to_tsquery" do
|
||||
user = insert(:user)
|
||||
{:ok, _post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
|
||||
{:ok, other_post} = CommonAPI.post(user, %{status: "it's wednesday my bros"})
|
||||
|
||||
assert [result] = Search.search(nil, "wednesday -dudes")
|
||||
|
||||
assert result.id == other_post.id
|
||||
end
|
||||
end
|
||||
|
|
@ -197,6 +197,13 @@ defmodule Pleroma.ActivityTest do
|
|||
assert [%{id: ^id1, object: %Object{}}, %{id: ^id2, object: %Object{}}] = activities
|
||||
end
|
||||
|
||||
test "get_by_id_with_user_actor/1" do
|
||||
user = insert(:user)
|
||||
activity = insert(:note_activity, note: insert(:note, user: user))
|
||||
|
||||
assert Activity.get_by_id_with_user_actor(activity.id).user_actor == user
|
||||
end
|
||||
|
||||
test "get_by_id_with_object/1" do
|
||||
%{id: id} = insert(:note_activity)
|
||||
|
||||
|
|
@ -231,4 +238,20 @@ defmodule Pleroma.ActivityTest do
|
|||
|
||||
assert [%Activity{id: ^id1}, %Activity{id: ^id2}] = activities
|
||||
end
|
||||
|
||||
test "get_by_object_ap_id_with_object/1" do
|
||||
user = insert(:user)
|
||||
another = insert(:user)
|
||||
|
||||
{:ok, %{id: id, object: %{data: %{"id" => obj_id}}}} =
|
||||
Pleroma.Web.CommonAPI.post(user, %{status: "cofe"})
|
||||
|
||||
Pleroma.Web.CommonAPI.favorite(another, id)
|
||||
|
||||
assert obj_id
|
||||
|> Pleroma.Activity.Queries.by_object_id()
|
||||
|> Repo.aggregate(:count, :id) == 2
|
||||
|
||||
assert %{id: ^id} = Activity.get_by_object_ap_id_with_object(obj_id)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,6 +12,26 @@ defmodule Pleroma.ApplicationRequirementsTest do
|
|||
alias Pleroma.Config
|
||||
alias Pleroma.Repo
|
||||
|
||||
describe "check_repo_pool_size!/1" do
|
||||
test "raises if the pool size is unexpected" do
|
||||
clear_config([Pleroma.Repo, :pool_size], 11)
|
||||
clear_config([:dangerzone, :override_repo_pool_size], false)
|
||||
|
||||
assert_raise Pleroma.ApplicationRequirements.VerifyError,
|
||||
"Repo.pool_size different than recommended value.",
|
||||
fn ->
|
||||
capture_log(&Pleroma.ApplicationRequirements.verify!/0)
|
||||
end
|
||||
end
|
||||
|
||||
test "doesn't raise if the pool size is unexpected but the respective flag is set" do
|
||||
clear_config([Pleroma.Repo, :pool_size], 11)
|
||||
clear_config([:dangerzone, :override_repo_pool_size], true)
|
||||
|
||||
assert Pleroma.ApplicationRequirements.verify!() == :ok
|
||||
end
|
||||
end
|
||||
|
||||
describe "check_welcome_message_config!/1" do
|
||||
setup do: clear_config([:welcome])
|
||||
setup do: clear_config([Pleroma.Emails.Mailer])
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.BBS.HandlerTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.BBS.Handler
|
||||
alias Pleroma.Object
|
||||
|
|
@ -19,7 +19,7 @@ defmodule Pleroma.BBS.HandlerTest do
|
|||
user = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
||||
{:ok, user} = User.follow(user, followed)
|
||||
{:ok, user, followed} = User.follow(user, followed)
|
||||
|
||||
{:ok, _first} = CommonAPI.post(user, %{status: "hey"})
|
||||
{:ok, _second} = CommonAPI.post(followed, %{status: "hello"})
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.BookmarkTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Bookmark
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
|
|
|||
|
|
@ -80,7 +80,6 @@ defmodule Pleroma.CaptchaTest do
|
|||
|
||||
assert is_binary(answer)
|
||||
assert :ok = Captcha.validate(token, "63615261b77f5354fb8c4e4986477555", answer)
|
||||
Cachex.del(:used_captcha_cache, token)
|
||||
end
|
||||
|
||||
test "doesn't validate invalid answer" do
|
||||
|
|
|
|||
|
|
@ -73,7 +73,8 @@ defmodule Pleroma.ChatTest do
|
|||
other_user = insert(:user)
|
||||
|
||||
{:ok, chat} = Chat.bump_or_create(user.id, other_user.ap_id)
|
||||
:timer.sleep(1500)
|
||||
{:ok, chat} = time_travel(chat, -2)
|
||||
|
||||
{:ok, chat_two} = Chat.bump_or_create(user.id, other_user.ap_id)
|
||||
|
||||
assert chat.id == chat_two.id
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ defmodule Pleroma.Config.DeprecationWarningsTest do
|
|||
alias Pleroma.Config.DeprecationWarnings
|
||||
|
||||
test "check_old_mrf_config/0" do
|
||||
clear_config([:instance, :rewrite_policy], Pleroma.Web.ActivityPub.MRF.NoOpPolicy)
|
||||
clear_config([:instance, :rewrite_policy], [])
|
||||
clear_config([:instance, :mrf_transparency], true)
|
||||
clear_config([:instance, :mrf_transparency_exclusions], [])
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.ConfigTest do
|
||||
use ExUnit.Case
|
||||
use Pleroma.DataCase
|
||||
|
||||
test "get/1 with an atom" do
|
||||
assert Pleroma.Config.get(:instance) == Application.get_env(:pleroma, :instance)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Conversation.ParticipationTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Conversation
|
||||
alias Pleroma.Conversation.Participation
|
||||
|
|
@ -37,9 +37,8 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
|
||||
[%{read: true}] = Participation.for_user(user)
|
||||
[%{read: false} = participation] = Participation.for_user(other_user)
|
||||
|
||||
assert User.get_cached_by_id(user.id).unread_conversation_count == 0
|
||||
assert User.get_cached_by_id(other_user.id).unread_conversation_count == 1
|
||||
assert Participation.unread_count(user) == 0
|
||||
assert Participation.unread_count(other_user) == 1
|
||||
|
||||
{:ok, _} =
|
||||
CommonAPI.post(other_user, %{
|
||||
|
|
@ -54,8 +53,8 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
[%{read: false}] = Participation.for_user(user)
|
||||
[%{read: true}] = Participation.for_user(other_user)
|
||||
|
||||
assert User.get_cached_by_id(user.id).unread_conversation_count == 1
|
||||
assert User.get_cached_by_id(other_user.id).unread_conversation_count == 0
|
||||
assert Participation.unread_count(user) == 1
|
||||
assert Participation.unread_count(other_user) == 0
|
||||
end
|
||||
|
||||
test "for a new conversation, it sets the recipents of the participation" do
|
||||
|
|
@ -97,12 +96,11 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
{:ok, %Participation{} = participation} =
|
||||
Participation.create_for_user_and_conversation(user, conversation)
|
||||
|
||||
{:ok, participation} = time_travel(participation, -2)
|
||||
|
||||
assert participation.user_id == user.id
|
||||
assert participation.conversation_id == conversation.id
|
||||
|
||||
# Needed because updated_at is accurate down to a second
|
||||
:timer.sleep(1000)
|
||||
|
||||
# Creating again returns the same participation
|
||||
{:ok, %Participation{} = participation_two} =
|
||||
Participation.create_for_user_and_conversation(user, conversation)
|
||||
|
|
@ -264,7 +262,7 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
assert [%{read: false}, %{read: false}, %{read: false}, %{read: false}] =
|
||||
Participation.for_user(blocker)
|
||||
|
||||
assert User.get_cached_by_id(blocker.id).unread_conversation_count == 4
|
||||
assert Participation.unread_count(blocker) == 4
|
||||
|
||||
{:ok, _user_relationship} = User.block(blocker, blocked)
|
||||
|
||||
|
|
@ -272,15 +270,15 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
assert [%{read: true}, %{read: true}, %{read: true}, %{read: false}] =
|
||||
Participation.for_user(blocker)
|
||||
|
||||
assert User.get_cached_by_id(blocker.id).unread_conversation_count == 1
|
||||
assert Participation.unread_count(blocker) == 1
|
||||
|
||||
# The conversation is not marked as read for the blocked user
|
||||
assert [_, _, %{read: false}] = Participation.for_user(blocked)
|
||||
assert User.get_cached_by_id(blocked.id).unread_conversation_count == 1
|
||||
assert Participation.unread_count(blocker) == 1
|
||||
|
||||
# The conversation is not marked as read for the third user
|
||||
assert [%{read: false}, _, _] = Participation.for_user(third_user)
|
||||
assert User.get_cached_by_id(third_user.id).unread_conversation_count == 1
|
||||
assert Participation.unread_count(third_user) == 1
|
||||
end
|
||||
|
||||
test "the new conversation with the blocked user is not marked as unread " do
|
||||
|
|
@ -298,7 +296,7 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
})
|
||||
|
||||
assert [%{read: true}] = Participation.for_user(blocker)
|
||||
assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0
|
||||
assert Participation.unread_count(blocker) == 0
|
||||
|
||||
# When the blocked user is a recipient
|
||||
{:ok, _direct2} =
|
||||
|
|
@ -308,10 +306,10 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
})
|
||||
|
||||
assert [%{read: true}, %{read: true}] = Participation.for_user(blocker)
|
||||
assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0
|
||||
assert Participation.unread_count(blocker) == 0
|
||||
|
||||
assert [%{read: false}, _] = Participation.for_user(blocked)
|
||||
assert User.get_cached_by_id(blocked.id).unread_conversation_count == 1
|
||||
assert Participation.unread_count(blocked) == 1
|
||||
end
|
||||
|
||||
test "the conversation with the blocked user is not marked as unread on a reply" do
|
||||
|
|
@ -327,8 +325,8 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
|
||||
{:ok, _user_relationship} = User.block(blocker, blocked)
|
||||
assert [%{read: true}] = Participation.for_user(blocker)
|
||||
assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0
|
||||
|
||||
assert Participation.unread_count(blocker) == 0
|
||||
assert [blocked_participation] = Participation.for_user(blocked)
|
||||
|
||||
# When it's a reply from the blocked user
|
||||
|
|
@ -340,8 +338,8 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
})
|
||||
|
||||
assert [%{read: true}] = Participation.for_user(blocker)
|
||||
assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0
|
||||
|
||||
assert Participation.unread_count(blocker) == 0
|
||||
assert [third_user_participation] = Participation.for_user(third_user)
|
||||
|
||||
# When it's a reply from the third user
|
||||
|
|
@ -353,11 +351,12 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
})
|
||||
|
||||
assert [%{read: true}] = Participation.for_user(blocker)
|
||||
assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0
|
||||
assert Participation.unread_count(blocker) == 0
|
||||
|
||||
# Marked as unread for the blocked user
|
||||
assert [%{read: false}] = Participation.for_user(blocked)
|
||||
assert User.get_cached_by_id(blocked.id).unread_conversation_count == 1
|
||||
|
||||
assert Participation.unread_count(blocked) == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# Copyright © 2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
defmodule Pleroma.EarmarkRendererTest do
|
||||
use ExUnit.Case
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
test "Paragraph" do
|
||||
code = ~s[Hello\n\nWorld!]
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.DateTimeTest do
|
||||
alias Pleroma.EctoType.ActivityPub.ObjectValidators.DateTime
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
test "it validates an xsd:Datetime" do
|
||||
valid_strings = [
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectIDTest do
|
||||
alias Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectID
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
@uris [
|
||||
"http://lain.com/users/lain",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.RecipientsTest do
|
||||
alias Pleroma.EctoType.ActivityPub.ObjectValidators.Recipients
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
test "it asserts that all elements of the list are object ids" do
|
||||
list = ["https://lain.com/users/lain", "invalid"]
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.SafeTextTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.EctoType.ActivityPub.ObjectValidators.SafeText
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Emails.AdminEmailTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Emails.AdminEmail
|
||||
|
|
@ -19,8 +19,8 @@ defmodule Pleroma.Emails.AdminEmailTest do
|
|||
AdminEmail.report(to_user, reporter, account, [%{name: "Test", id: "12"}], "Test comment")
|
||||
|
||||
status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, "12")
|
||||
reporter_url = Helpers.user_feed_url(Pleroma.Web.Endpoint, :feed_redirect, reporter.id)
|
||||
account_url = Helpers.user_feed_url(Pleroma.Web.Endpoint, :feed_redirect, account.id)
|
||||
reporter_url = reporter.ap_id
|
||||
account_url = account.ap_id
|
||||
|
||||
assert res.to == [{to_user.name, to_user.email}]
|
||||
assert res.from == {config[:name], config[:notify_email]}
|
||||
|
|
@ -54,7 +54,7 @@ defmodule Pleroma.Emails.AdminEmailTest do
|
|||
|
||||
res = AdminEmail.new_unapproved_registration(to_user, account)
|
||||
|
||||
account_url = Helpers.user_feed_url(Pleroma.Web.Endpoint, :feed_redirect, account.id)
|
||||
account_url = account.ap_id
|
||||
|
||||
assert res.to == [{to_user.name, to_user.email}]
|
||||
assert res.from == {config[:name], config[:notify_email]}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Emails.UserEmailTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Emails.UserEmail
|
||||
alias Pleroma.Web.Endpoint
|
||||
|
|
@ -45,4 +45,15 @@ defmodule Pleroma.Emails.UserEmailTest do
|
|||
assert email.html_body =~
|
||||
Router.Helpers.confirm_email_url(Endpoint, :confirm_email, user.id, "conf-token")
|
||||
end
|
||||
|
||||
test "build approval pending email" do
|
||||
config = Pleroma.Config.get(:instance)
|
||||
user = insert(:user)
|
||||
email = UserEmail.approval_pending_email(user)
|
||||
|
||||
assert email.from == {config[:name], config[:notify_email]}
|
||||
assert email.to == [{user.name, user.email}]
|
||||
assert email.subject == "Your account is awaiting approval"
|
||||
assert email.html_body =~ "Awaiting Approval"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
defmodule Pleroma.Emoji.FormatterTest do
|
||||
alias Pleroma.Emoji.Formatter
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
describe "emojify" do
|
||||
test "it adds cool emoji" do
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Emoji.PackTest do
|
||||
use ExUnit.Case, async: true
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Emoji.Pack
|
||||
|
||||
@emoji_path Path.join(
|
||||
|
|
|
|||
|
|
@ -3,14 +3,28 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.EmojiTest do
|
||||
use ExUnit.Case
|
||||
use ExUnit.Case, async: true
|
||||
alias Pleroma.Emoji
|
||||
|
||||
describe "is_unicode_emoji?/1" do
|
||||
test "tells if a string is an unicode emoji" do
|
||||
refute Emoji.is_unicode_emoji?("X")
|
||||
assert Emoji.is_unicode_emoji?("☂")
|
||||
refute Emoji.is_unicode_emoji?("ね")
|
||||
|
||||
# Only accept fully-qualified (RGI) emoji
|
||||
# See http://www.unicode.org/reports/tr51/
|
||||
refute Emoji.is_unicode_emoji?("❤")
|
||||
refute Emoji.is_unicode_emoji?("☂")
|
||||
|
||||
assert Emoji.is_unicode_emoji?("🥺")
|
||||
assert Emoji.is_unicode_emoji?("🤰")
|
||||
assert Emoji.is_unicode_emoji?("❤️")
|
||||
assert Emoji.is_unicode_emoji?("🏳️⚧️")
|
||||
|
||||
# Additionally, we accept regional indicators.
|
||||
assert Emoji.is_unicode_emoji?("🇵")
|
||||
assert Emoji.is_unicode_emoji?("🇴")
|
||||
assert Emoji.is_unicode_emoji?("🇬")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.FilterTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.FollowingRelationshipTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.FollowingRelationship
|
||||
alias Pleroma.Web.ActivityPub.InternalFetchActor
|
||||
|
|
|
|||
|
|
@ -241,16 +241,14 @@ defmodule Pleroma.FormatterTest do
|
|||
"@@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme@archae.me and @o and @@@jimm"
|
||||
|
||||
o = insert(:user, %{nickname: "o"})
|
||||
jimm = insert(:user, %{nickname: "jimm"})
|
||||
gsimg = insert(:user, %{nickname: "gsimg"})
|
||||
_jimm = insert(:user, %{nickname: "jimm"})
|
||||
_gsimg = insert(:user, %{nickname: "gsimg"})
|
||||
archaeme = insert(:user, %{nickname: "archaeme"})
|
||||
archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
|
||||
|
||||
expected_mentions = [
|
||||
{"@archaeme", archaeme},
|
||||
{"@archaeme@archae.me", archaeme_remote},
|
||||
{"@gsimg", gsimg},
|
||||
{"@jimm", jimm},
|
||||
{"@o", o}
|
||||
]
|
||||
|
||||
|
|
|
|||
72
test/pleroma/frontend_test.exs
Normal file
72
test/pleroma/frontend_test.exs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.FrontendTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Frontend
|
||||
|
||||
@dir "test/frontend_static_test"
|
||||
|
||||
setup do
|
||||
File.mkdir_p!(@dir)
|
||||
clear_config([:instance, :static_dir], @dir)
|
||||
|
||||
on_exit(fn ->
|
||||
File.rm_rf(@dir)
|
||||
end)
|
||||
end
|
||||
|
||||
test "it downloads and unzips a known frontend" do
|
||||
clear_config([:frontends, :available], %{
|
||||
"pleroma" => %{
|
||||
"ref" => "fantasy",
|
||||
"name" => "pleroma",
|
||||
"build_url" => "http://gensokyo.2hu/builds/${ref}"
|
||||
}
|
||||
})
|
||||
|
||||
Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/builds/fantasy"} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend_dist.zip")}
|
||||
end)
|
||||
|
||||
Frontend.install("pleroma")
|
||||
|
||||
assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
|
||||
end
|
||||
|
||||
test "it also works given a file" do
|
||||
clear_config([:frontends, :available], %{
|
||||
"pleroma" => %{
|
||||
"ref" => "fantasy",
|
||||
"name" => "pleroma",
|
||||
"build_dir" => ""
|
||||
}
|
||||
})
|
||||
|
||||
folder = Path.join([@dir, "frontends", "pleroma", "fantasy"])
|
||||
previously_existing = Path.join([folder, "temp"])
|
||||
File.mkdir_p!(folder)
|
||||
File.write!(previously_existing, "yey")
|
||||
assert File.exists?(previously_existing)
|
||||
|
||||
Frontend.install("pleroma", file: "test/fixtures/tesla_mock/frontend.zip")
|
||||
|
||||
assert File.exists?(Path.join([folder, "test.txt"]))
|
||||
refute File.exists?(previously_existing)
|
||||
end
|
||||
|
||||
test "it downloads and unzips unknown frontends" do
|
||||
Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/madeup.zip"} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")}
|
||||
end)
|
||||
|
||||
Frontend.install("unknown",
|
||||
ref: "baka",
|
||||
build_url: "http://gensokyo.2hu/madeup.zip",
|
||||
build_dir: ""
|
||||
)
|
||||
|
||||
assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"]))
|
||||
end
|
||||
end
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.HealthcheckTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
alias Pleroma.Healthcheck
|
||||
|
||||
test "system_info/0" do
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ defmodule Pleroma.HTMLTest do
|
|||
alias Pleroma.HTML
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.CommonAPI
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.HTTP.AdapterHelper.GunTest do
|
||||
use ExUnit.Case, async: true
|
||||
use ExUnit.Case
|
||||
use Pleroma.Tests.Helpers
|
||||
|
||||
import Mox
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Instances.InstanceTest do
|
||||
alias Pleroma.Instances
|
||||
alias Pleroma.Instances.Instance
|
||||
alias Pleroma.Repo
|
||||
|
||||
|
|
@ -148,5 +149,13 @@ defmodule Pleroma.Instances.InstanceTest do
|
|||
)
|
||||
end) =~ "Instance.scrape_favicon(\"https://no-favicon.example.org/\") error: "
|
||||
end
|
||||
|
||||
test "Doesn't scrapes unreachable instances" do
|
||||
instance = insert(:instance, unreachable_since: Instances.reachability_datetime_threshold())
|
||||
url = "https://" <> instance.host
|
||||
|
||||
assert capture_log(fn -> assert nil == Instance.get_or_update_favicon(URI.parse(url)) end) =~
|
||||
"Instance.scrape_favicon(\"#{url}\") ignored unreachable host"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@ defmodule Pleroma.InstancesTest do
|
|||
assert Instances.reachable?(URI.parse(url).host)
|
||||
end
|
||||
|
||||
test "returns true on non-binary input" do
|
||||
assert Instances.reachable?(nil)
|
||||
assert Instances.reachable?(1)
|
||||
test "raises FunctionClauseError exception on non-binary input" do
|
||||
assert_raise FunctionClauseError, fn -> Instances.reachable?(nil) end
|
||||
assert_raise FunctionClauseError, fn -> Instances.reachable?(1) end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Integration.MastodonWebsocketTest do
|
||||
# Needs a streamer, needs to stay synchronous
|
||||
use Pleroma.DataCase
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
|
|
@ -49,6 +50,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
|
|||
test "allows public streams without authentication" do
|
||||
assert {:ok, _} = start_socket("?stream=public")
|
||||
assert {:ok, _} = start_socket("?stream=public:local")
|
||||
assert {:ok, _} = start_socket("?stream=public:remote&instance=lain.com")
|
||||
assert {:ok, _} = start_socket("?stream=hashtag&tag=lain")
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.KeysTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Keys
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
defmodule Pleroma.ListTest do
|
||||
alias Pleroma.Repo
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.MarkerTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
alias Pleroma.Marker
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.MFA.BackupCodesTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.MFA.BackupCodes
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.MFA.TOTPTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.MFA.TOTP
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.MFATest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.MFA
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.MigrationHelper.NotificationBackfillTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.MigrationHelper.NotificationBackfill
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ defmodule Pleroma.ModerationLogTest do
|
|||
alias Pleroma.Activity
|
||||
alias Pleroma.ModerationLog
|
||||
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
@ -182,11 +182,14 @@ defmodule Pleroma.ModerationLogTest do
|
|||
end
|
||||
|
||||
test "logging report update", %{moderator: moderator} do
|
||||
user = insert(:user)
|
||||
|
||||
report = %Activity{
|
||||
id: "9m9I1F4p8ftrTP6QTI",
|
||||
data: %{
|
||||
"type" => "Flag",
|
||||
"state" => "resolved"
|
||||
"state" => "resolved",
|
||||
"actor" => user.ap_id
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -194,35 +197,48 @@ defmodule Pleroma.ModerationLogTest do
|
|||
ModerationLog.insert_log(%{
|
||||
actor: moderator,
|
||||
action: "report_update",
|
||||
subject: report
|
||||
subject: report,
|
||||
subject_actor: user
|
||||
})
|
||||
|
||||
log = Repo.one(ModerationLog)
|
||||
|
||||
assert log.data["message"] ==
|
||||
"@#{moderator.nickname} updated report ##{report.id} with 'resolved' state"
|
||||
"@#{moderator.nickname} updated report ##{report.id} (on user @#{user.nickname}) with 'resolved' state"
|
||||
end
|
||||
|
||||
test "logging report response", %{moderator: moderator} do
|
||||
user = insert(:user)
|
||||
|
||||
report = %Activity{
|
||||
id: "9m9I1F4p8ftrTP6QTI",
|
||||
data: %{
|
||||
"type" => "Note"
|
||||
"type" => "Note",
|
||||
"actor" => user.ap_id
|
||||
}
|
||||
}
|
||||
|
||||
{:ok, _} =
|
||||
ModerationLog.insert_log(%{
|
||||
actor: moderator,
|
||||
action: "report_note",
|
||||
subject: report,
|
||||
text: "look at this"
|
||||
})
|
||||
attrs = %{
|
||||
actor: moderator,
|
||||
action: "report_note",
|
||||
subject: report,
|
||||
text: "look at this"
|
||||
}
|
||||
|
||||
log = Repo.one(ModerationLog)
|
||||
{:ok, log1} = ModerationLog.insert_log(attrs)
|
||||
log = Repo.get(ModerationLog, log1.id)
|
||||
|
||||
assert log.data["message"] ==
|
||||
"@#{moderator.nickname} added note 'look at this' to report ##{report.id}"
|
||||
|
||||
{:ok, log2} = ModerationLog.insert_log(Map.merge(attrs, %{subject_actor: user}))
|
||||
|
||||
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
|
||||
}"
|
||||
end
|
||||
|
||||
test "logging status sensitivity update", %{moderator: moderator} do
|
||||
|
|
|
|||
|
|
@ -32,6 +32,19 @@ defmodule Pleroma.NotificationTest do
|
|||
refute {:ok, [nil]} == Notification.create_notifications(activity)
|
||||
end
|
||||
|
||||
test "creates a notification for a report" do
|
||||
reporting_user = insert(:user)
|
||||
reported_user = insert(:user)
|
||||
{:ok, moderator_user} = insert(:user) |> User.admin_api_update(%{is_moderator: true})
|
||||
|
||||
{:ok, activity} = CommonAPI.report(reporting_user, %{account_id: reported_user.id})
|
||||
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
|
||||
assert notification.user_id == moderator_user.id
|
||||
assert notification.type == "pleroma:report"
|
||||
end
|
||||
|
||||
test "creates a notification for an emoji reaction" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
|
@ -229,7 +242,7 @@ defmodule Pleroma.NotificationTest do
|
|||
muter = insert(:user)
|
||||
muted = insert(:user)
|
||||
|
||||
{:ok, _user_relationships} = User.mute(muter, muted, false)
|
||||
{:ok, _user_relationships} = User.mute(muter, muted, %{notifications: false})
|
||||
|
||||
{:ok, activity} = CommonAPI.post(muted, %{status: "Hi @#{muter.nickname}"})
|
||||
|
||||
|
|
@ -400,7 +413,7 @@ defmodule Pleroma.NotificationTest do
|
|||
user = insert(:user, is_locked: true)
|
||||
follower = insert(:user)
|
||||
{:ok, _, _, _follow_activity} = CommonAPI.follow(follower, user)
|
||||
assert [notification] = Notification.for_user(user)
|
||||
assert [_notification] = Notification.for_user(user)
|
||||
{:ok, _follower} = CommonAPI.reject_follow_request(follower, user)
|
||||
assert [] = Notification.for_user(user)
|
||||
end
|
||||
|
|
@ -766,7 +779,7 @@ defmodule Pleroma.NotificationTest do
|
|||
other_user = insert(:user)
|
||||
|
||||
{:ok, other_user} = User.block_domain(other_user, blocked_domain)
|
||||
{:ok, other_user} = User.follow(other_user, user)
|
||||
{:ok, other_user, user} = User.follow(other_user, user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}!"})
|
||||
|
||||
|
|
@ -1015,7 +1028,7 @@ defmodule Pleroma.NotificationTest do
|
|||
|
||||
test "it returns notifications for muted user without notifications", %{user: user} do
|
||||
muted = insert(:user)
|
||||
{:ok, _user_relationships} = User.mute(user, muted, false)
|
||||
{:ok, _user_relationships} = User.mute(user, muted, %{notifications: false})
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(muted, %{status: "hey @#{user.nickname}"})
|
||||
|
||||
|
|
@ -1057,7 +1070,7 @@ defmodule Pleroma.NotificationTest do
|
|||
blocked = insert(:user, ap_id: "http://some-domain.com")
|
||||
|
||||
{:ok, user} = User.block_domain(user, "some-domain.com")
|
||||
{:ok, _} = User.follow(user, blocked)
|
||||
{:ok, _, _} = User.follow(user, blocked)
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(blocked, %{status: "hey @#{user.nickname}"})
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,17 @@ defmodule Pleroma.Object.FetcherTest do
|
|||
%{method: :get, url: "https://mastodon.example.org/users/userisgone404"} ->
|
||||
%Tesla.Env{status: 404}
|
||||
|
||||
%{
|
||||
method: :get,
|
||||
url:
|
||||
"https://patch.cx/media/03ca3c8b4ac3ddd08bf0f84be7885f2f88de0f709112131a22d83650819e36c2.json"
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
headers: [{"content-type", "application/json"}],
|
||||
body: File.read!("test/fixtures/spoofed-object.json")
|
||||
}
|
||||
|
||||
env ->
|
||||
apply(HttpRequestMock, :request, [env])
|
||||
end)
|
||||
|
|
@ -34,19 +45,22 @@ defmodule Pleroma.Object.FetcherTest do
|
|||
%{method: :get, url: "https://social.sakamoto.gq/notice/9wTkLEnuq47B25EehM"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/fetch_mocks/9wTkLEnuq47B25EehM.json")
|
||||
body: File.read!("test/fixtures/fetch_mocks/9wTkLEnuq47B25EehM.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
|
||||
%{method: :get, url: "https://social.sakamoto.gq/users/eal"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/fetch_mocks/eal.json")
|
||||
body: File.read!("test/fixtures/fetch_mocks/eal.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
|
||||
%{method: :get, url: "https://busshi.moe/users/tuxcrafting/statuses/104410921027210069"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/fetch_mocks/104410921027210069.json")
|
||||
body: File.read!("test/fixtures/fetch_mocks/104410921027210069.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
|
||||
%{method: :get, url: "https://busshi.moe/users/tuxcrafting"} ->
|
||||
|
|
@ -132,6 +146,13 @@ defmodule Pleroma.Object.FetcherTest do
|
|||
"http://mastodon.example.org/@admin/99541947525187367"
|
||||
)
|
||||
end
|
||||
|
||||
test "it does not fetch a spoofed object uploaded on an instance as an attachment" do
|
||||
assert {:error, _} =
|
||||
Fetcher.fetch_object_from_id(
|
||||
"https://patch.cx/media/03ca3c8b4ac3ddd08bf0f84be7885f2f88de0f709112131a22d83650819e36c2.json"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "implementation quirks" do
|
||||
|
|
|
|||
|
|
@ -281,7 +281,11 @@ defmodule Pleroma.ObjectTest do
|
|||
setup do
|
||||
mock(fn
|
||||
%{method: :get, url: "https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/poll_original.json")}
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/poll_original.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
|
||||
env ->
|
||||
apply(HttpRequestMock, :request, [env])
|
||||
|
|
@ -315,7 +319,8 @@ defmodule Pleroma.ObjectTest do
|
|||
|
||||
mock_modified.(%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/poll_modified.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/poll_modified.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
})
|
||||
|
||||
updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: -1)
|
||||
|
|
@ -359,7 +364,8 @@ defmodule Pleroma.ObjectTest do
|
|||
|
||||
mock_modified.(%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/poll_modified.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/poll_modified.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
})
|
||||
|
||||
updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: 100)
|
||||
|
|
@ -387,7 +393,8 @@ defmodule Pleroma.ObjectTest do
|
|||
|
||||
mock_modified.(%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/poll_modified.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/poll_modified.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
})
|
||||
|
||||
updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: -1)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.PaginationTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.RegistrationTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
defmodule Pleroma.Repo.Migrations.FixLegacyTagsTest do
|
||||
alias Pleroma.User
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
import Pleroma.Factory
|
||||
import Pleroma.Tests.Helpers
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Repo.Migrations.MoveWelcomeSettingsTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
import Pleroma.Factory
|
||||
import Pleroma.Tests.Helpers
|
||||
alias Pleroma.ConfigDB
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.RepoTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.User
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
defmodule Pleroma.ReportNoteTest do
|
||||
alias Pleroma.ReportNote
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
import Pleroma.Factory
|
||||
|
||||
test "create/3" do
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.ReverseProxyTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
use Pleroma.Web.ConnCase
|
||||
import ExUnit.CaptureLog
|
||||
import Mox
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.SafeJsonbSetTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
test "it doesn't wipe the object when asked to set the value to NULL" do
|
||||
assert %{rows: [[%{"key" => "value", "test" => nil}]]} =
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.StatsTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Upload.Filter.DedupeTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Upload
|
||||
alias Pleroma.Upload.Filter.Dedupe
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Upload.Filter.ExiftoolTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
alias Pleroma.Upload.Filter
|
||||
|
||||
test "apply exiftool filter" do
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Uploaders.LocalTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
alias Pleroma.Uploaders.Local
|
||||
|
||||
describe "get_file/1" do
|
||||
|
|
|
|||
244
test/pleroma/user/backup_test.exs
Normal file
244
test/pleroma/user/backup_test.exs
Normal file
|
|
@ -0,0 +1,244 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.User.BackupTest do
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
import Swoosh.TestAssertions
|
||||
|
||||
alias Pleroma.Bookmark
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User.Backup
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Workers.BackupWorker
|
||||
|
||||
setup do
|
||||
clear_config([Pleroma.Upload, :uploader])
|
||||
clear_config([Backup, :limit_days])
|
||||
clear_config([Pleroma.Emails.Mailer, :enabled], true)
|
||||
end
|
||||
|
||||
test "it requries enabled email" do
|
||||
Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
|
||||
user = insert(:user)
|
||||
assert {:error, "Backups require enabled email"} == Backup.create(user)
|
||||
end
|
||||
|
||||
test "it requries user's email" do
|
||||
user = insert(:user, %{email: nil})
|
||||
assert {:error, "Email is required"} == Backup.create(user)
|
||||
end
|
||||
|
||||
test "it creates a backup record and an Oban job" do
|
||||
%{id: user_id} = user = insert(:user)
|
||||
assert {:ok, %Oban.Job{args: args}} = Backup.create(user)
|
||||
assert_enqueued(worker: BackupWorker, args: args)
|
||||
|
||||
backup = Backup.get(args["backup_id"])
|
||||
assert %Backup{user_id: ^user_id, processed: false, file_size: 0} = backup
|
||||
end
|
||||
|
||||
test "it return an error if the export limit is over" do
|
||||
%{id: user_id} = user = insert(:user)
|
||||
limit_days = Pleroma.Config.get([Backup, :limit_days])
|
||||
assert {:ok, %Oban.Job{args: args}} = Backup.create(user)
|
||||
backup = Backup.get(args["backup_id"])
|
||||
assert %Backup{user_id: ^user_id, processed: false, file_size: 0} = backup
|
||||
|
||||
assert Backup.create(user) == {:error, "Last export was less than #{limit_days} days ago"}
|
||||
end
|
||||
|
||||
test "it process a backup record" do
|
||||
Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
|
||||
%{id: user_id} = user = insert(:user)
|
||||
|
||||
assert {:ok, %Oban.Job{args: %{"backup_id" => backup_id} = args}} = Backup.create(user)
|
||||
assert {:ok, backup} = perform_job(BackupWorker, args)
|
||||
assert backup.file_size > 0
|
||||
assert %Backup{id: ^backup_id, processed: true, user_id: ^user_id} = backup
|
||||
|
||||
delete_job_args = %{"op" => "delete", "backup_id" => backup_id}
|
||||
|
||||
assert_enqueued(worker: BackupWorker, args: delete_job_args)
|
||||
assert {:ok, backup} = perform_job(BackupWorker, delete_job_args)
|
||||
refute Backup.get(backup_id)
|
||||
|
||||
email = Pleroma.Emails.UserEmail.backup_is_ready_email(backup)
|
||||
|
||||
assert_email_sent(
|
||||
to: {user.name, user.email},
|
||||
html_body: email.html_body
|
||||
)
|
||||
end
|
||||
|
||||
test "it removes outdated backups after creating a fresh one" do
|
||||
Pleroma.Config.put([Backup, :limit_days], -1)
|
||||
Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
|
||||
user = insert(:user)
|
||||
|
||||
assert {:ok, job1} = Backup.create(user)
|
||||
|
||||
assert {:ok, %Backup{}} = ObanHelpers.perform(job1)
|
||||
assert {:ok, job2} = Backup.create(user)
|
||||
assert Pleroma.Repo.aggregate(Backup, :count) == 2
|
||||
assert {:ok, backup2} = ObanHelpers.perform(job2)
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert [^backup2] = Pleroma.Repo.all(Backup)
|
||||
end
|
||||
|
||||
test "it creates a zip archive with user data" do
|
||||
user = insert(:user, %{nickname: "cofe", name: "Cofe", ap_id: "http://cofe.io/users/cofe"})
|
||||
|
||||
{:ok, %{object: %{data: %{"id" => id1}}} = status1} =
|
||||
CommonAPI.post(user, %{status: "status1"})
|
||||
|
||||
{:ok, %{object: %{data: %{"id" => id2}}} = status2} =
|
||||
CommonAPI.post(user, %{status: "status2"})
|
||||
|
||||
{:ok, %{object: %{data: %{"id" => id3}}} = status3} =
|
||||
CommonAPI.post(user, %{status: "status3"})
|
||||
|
||||
CommonAPI.favorite(user, status1.id)
|
||||
CommonAPI.favorite(user, status2.id)
|
||||
|
||||
Bookmark.create(user.id, status2.id)
|
||||
Bookmark.create(user.id, status3.id)
|
||||
|
||||
assert {:ok, backup} = user |> Backup.new() |> Repo.insert()
|
||||
assert {:ok, path} = Backup.export(backup)
|
||||
assert {:ok, zipfile} = :zip.zip_open(String.to_charlist(path), [:memory])
|
||||
assert {:ok, {'actor.json', json}} = :zip.zip_get('actor.json', zipfile)
|
||||
|
||||
assert %{
|
||||
"@context" => [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"http://localhost:4001/schemas/litepub-0.1.jsonld",
|
||||
%{"@language" => "und"}
|
||||
],
|
||||
"bookmarks" => "bookmarks.json",
|
||||
"followers" => "http://cofe.io/users/cofe/followers",
|
||||
"following" => "http://cofe.io/users/cofe/following",
|
||||
"id" => "http://cofe.io/users/cofe",
|
||||
"inbox" => "http://cofe.io/users/cofe/inbox",
|
||||
"likes" => "likes.json",
|
||||
"name" => "Cofe",
|
||||
"outbox" => "http://cofe.io/users/cofe/outbox",
|
||||
"preferredUsername" => "cofe",
|
||||
"publicKey" => %{
|
||||
"id" => "http://cofe.io/users/cofe#main-key",
|
||||
"owner" => "http://cofe.io/users/cofe"
|
||||
},
|
||||
"type" => "Person",
|
||||
"url" => "http://cofe.io/users/cofe"
|
||||
} = Jason.decode!(json)
|
||||
|
||||
assert {:ok, {'outbox.json', json}} = :zip.zip_get('outbox.json', zipfile)
|
||||
|
||||
assert %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"id" => "outbox.json",
|
||||
"orderedItems" => [
|
||||
%{
|
||||
"object" => %{
|
||||
"actor" => "http://cofe.io/users/cofe",
|
||||
"content" => "status1",
|
||||
"type" => "Note"
|
||||
},
|
||||
"type" => "Create"
|
||||
},
|
||||
%{
|
||||
"object" => %{
|
||||
"actor" => "http://cofe.io/users/cofe",
|
||||
"content" => "status2"
|
||||
}
|
||||
},
|
||||
%{
|
||||
"actor" => "http://cofe.io/users/cofe",
|
||||
"object" => %{
|
||||
"content" => "status3"
|
||||
}
|
||||
}
|
||||
],
|
||||
"totalItems" => 3,
|
||||
"type" => "OrderedCollection"
|
||||
} = Jason.decode!(json)
|
||||
|
||||
assert {:ok, {'likes.json', json}} = :zip.zip_get('likes.json', zipfile)
|
||||
|
||||
assert %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"id" => "likes.json",
|
||||
"orderedItems" => [^id1, ^id2],
|
||||
"totalItems" => 2,
|
||||
"type" => "OrderedCollection"
|
||||
} = Jason.decode!(json)
|
||||
|
||||
assert {:ok, {'bookmarks.json', json}} = :zip.zip_get('bookmarks.json', zipfile)
|
||||
|
||||
assert %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"id" => "bookmarks.json",
|
||||
"orderedItems" => [^id2, ^id3],
|
||||
"totalItems" => 2,
|
||||
"type" => "OrderedCollection"
|
||||
} = Jason.decode!(json)
|
||||
|
||||
:zip.zip_close(zipfile)
|
||||
File.rm!(path)
|
||||
end
|
||||
|
||||
describe "it uploads and deletes a backup archive" do
|
||||
setup do
|
||||
clear_config(Pleroma.Uploaders.S3,
|
||||
bucket: "test_bucket",
|
||||
public_endpoint: "https://s3.amazonaws.com"
|
||||
)
|
||||
|
||||
clear_config([Pleroma.Upload, :uploader])
|
||||
|
||||
user = insert(:user, %{nickname: "cofe", name: "Cofe", ap_id: "http://cofe.io/users/cofe"})
|
||||
|
||||
{:ok, status1} = CommonAPI.post(user, %{status: "status1"})
|
||||
{:ok, status2} = CommonAPI.post(user, %{status: "status2"})
|
||||
{:ok, status3} = CommonAPI.post(user, %{status: "status3"})
|
||||
CommonAPI.favorite(user, status1.id)
|
||||
CommonAPI.favorite(user, status2.id)
|
||||
Bookmark.create(user.id, status2.id)
|
||||
Bookmark.create(user.id, status3.id)
|
||||
|
||||
assert {:ok, backup} = user |> Backup.new() |> Repo.insert()
|
||||
assert {:ok, path} = Backup.export(backup)
|
||||
|
||||
[path: path, backup: backup]
|
||||
end
|
||||
|
||||
test "S3", %{path: path, backup: backup} do
|
||||
Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3)
|
||||
|
||||
with_mock ExAws,
|
||||
request: fn
|
||||
%{http_method: :put} -> {:ok, :ok}
|
||||
%{http_method: :delete} -> {:ok, %{status_code: 204}}
|
||||
end do
|
||||
assert {:ok, %Pleroma.Upload{}} = Backup.upload(backup, path)
|
||||
assert {:ok, _backup} = Backup.delete(backup)
|
||||
end
|
||||
|
||||
with_mock ExAws, request: fn %{http_method: :delete} -> {:ok, %{status_code: 204}} end do
|
||||
end
|
||||
end
|
||||
|
||||
test "Local", %{path: path, backup: backup} do
|
||||
Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
|
||||
|
||||
assert {:ok, %Pleroma.Upload{}} = Backup.upload(backup, path)
|
||||
assert {:ok, _backup} = Backup.delete(backup)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -30,7 +30,7 @@ defmodule Pleroma.User.ImportTest do
|
|||
|
||||
assert {:ok, result} = ObanHelpers.perform(job)
|
||||
assert is_list(result)
|
||||
assert result == [user2, user3]
|
||||
assert result == [refresh_record(user2), refresh_record(user3)]
|
||||
assert User.following?(user1, user2)
|
||||
assert User.following?(user1, user3)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.User.NotificationSettingTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.User.NotificationSetting
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
defmodule Pleroma.UserRelationshipTest do
|
||||
alias Pleroma.UserRelationship
|
||||
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
|
|||
|
|
@ -65,12 +65,13 @@ defmodule Pleroma.UserSearchTest do
|
|||
assert found_user.id == user.id
|
||||
end
|
||||
|
||||
test "excludes users when discoverable is false" do
|
||||
insert(:user, %{nickname: "john 3000", discoverable: false})
|
||||
# Note: as in Mastodon, `is_discoverable` doesn't anyhow relate to user searchability
|
||||
test "includes non-discoverable users in results" do
|
||||
insert(:user, %{nickname: "john 3000", is_discoverable: false})
|
||||
insert(:user, %{nickname: "john 3001"})
|
||||
|
||||
users = User.search("john")
|
||||
assert Enum.count(users) == 1
|
||||
assert Enum.count(users) == 2
|
||||
end
|
||||
|
||||
test "excludes service actors from results" do
|
||||
|
|
@ -150,8 +151,8 @@ defmodule Pleroma.UserSearchTest do
|
|||
follower = insert(:user, %{name: "Doe"})
|
||||
friend = insert(:user, %{name: "Doe"})
|
||||
|
||||
{:ok, follower} = User.follow(follower, u1)
|
||||
{:ok, u1} = User.follow(u1, friend)
|
||||
{:ok, follower, u1} = User.follow(follower, u1)
|
||||
{:ok, u1, friend} = User.follow(u1, friend)
|
||||
|
||||
assert [friend.id, follower.id, u2.id] --
|
||||
Enum.map(User.search("doe", resolve: false, for_user: u1), & &1.id) == []
|
||||
|
|
@ -164,9 +165,9 @@ defmodule Pleroma.UserSearchTest do
|
|||
following_jimi = insert(:user, %{name: "Lizz Wright"})
|
||||
follower_lizz = insert(:user, %{name: "Jimi"})
|
||||
|
||||
{:ok, lizz} = User.follow(lizz, following_lizz)
|
||||
{:ok, _jimi} = User.follow(jimi, following_jimi)
|
||||
{:ok, _follower_lizz} = User.follow(follower_lizz, lizz)
|
||||
{:ok, lizz, following_lizz} = User.follow(lizz, following_lizz)
|
||||
{:ok, _jimi, _following_jimi} = User.follow(jimi, following_jimi)
|
||||
{:ok, _follower_lizz, _lizz} = User.follow(follower_lizz, lizz)
|
||||
|
||||
assert Enum.map(User.search("jimi", following: true, for_user: lizz), & &1.id) == [
|
||||
following_lizz.id
|
||||
|
|
|
|||
|
|
@ -233,7 +233,7 @@ defmodule Pleroma.UserTest do
|
|||
{:ok, _user_relationship} = User.block(user, blocked)
|
||||
{:ok, _user_relationship} = User.block(reverse_blocked, user)
|
||||
|
||||
{:ok, user} = User.follow(user, followed_zero)
|
||||
{:ok, user, followed_zero} = User.follow(user, followed_zero)
|
||||
|
||||
{:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked, reverse_blocked])
|
||||
|
||||
|
|
@ -262,7 +262,7 @@ defmodule Pleroma.UserTest do
|
|||
user = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
||||
{:ok, user} = User.follow(user, followed)
|
||||
{:ok, user, followed} = User.follow(user, followed)
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
followed = User.get_cached_by_ap_id(followed.ap_id)
|
||||
|
|
@ -302,7 +302,7 @@ defmodule Pleroma.UserTest do
|
|||
follower = insert(:user, is_locked: true)
|
||||
followed = insert(:user, is_locked: true)
|
||||
|
||||
{:ok, follower} = User.maybe_direct_follow(follower, followed)
|
||||
{:ok, follower, followed} = User.maybe_direct_follow(follower, followed)
|
||||
|
||||
refute User.following?(follower, followed)
|
||||
end
|
||||
|
|
@ -330,7 +330,7 @@ defmodule Pleroma.UserTest do
|
|||
following_address: "http://localhost:4001/users/fuser2/following"
|
||||
})
|
||||
|
||||
{:ok, user} = User.follow(user, followed, :follow_accept)
|
||||
{:ok, user, followed} = User.follow(user, followed, :follow_accept)
|
||||
|
||||
{:ok, user, _activity} = User.unfollow(user, followed)
|
||||
|
||||
|
|
@ -343,7 +343,7 @@ defmodule Pleroma.UserTest do
|
|||
followed = insert(:user)
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, user} = User.follow(user, followed, :follow_accept)
|
||||
{:ok, user, followed} = User.follow(user, followed, :follow_accept)
|
||||
|
||||
assert User.following(user) == [user.follower_address, followed.follower_address]
|
||||
|
||||
|
|
@ -388,6 +388,7 @@ defmodule Pleroma.UserTest do
|
|||
}
|
||||
|
||||
setup do: clear_config([:instance, :autofollowed_nicknames])
|
||||
setup do: clear_config([:instance, :autofollowing_nicknames])
|
||||
setup do: clear_config([:welcome])
|
||||
setup do: clear_config([:instance, :account_activation_required])
|
||||
|
||||
|
|
@ -408,6 +409,23 @@ defmodule Pleroma.UserTest do
|
|||
refute User.following?(registered_user, remote_user)
|
||||
end
|
||||
|
||||
test "it adds automatic followers for new registered accounts" do
|
||||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
Pleroma.Config.put([:instance, :autofollowing_nicknames], [
|
||||
user1.nickname,
|
||||
user2.nickname
|
||||
])
|
||||
|
||||
cng = User.register_changeset(%User{}, @full_user_data)
|
||||
|
||||
{:ok, registered_user} = User.register(cng)
|
||||
|
||||
assert User.following?(user1, registered_user)
|
||||
assert User.following?(user2, registered_user)
|
||||
end
|
||||
|
||||
test "it sends a welcome message if it is set" do
|
||||
welcome_user = insert(:user)
|
||||
Pleroma.Config.put([:welcome, :direct_message, :enabled], true)
|
||||
|
|
@ -517,6 +535,22 @@ defmodule Pleroma.UserTest do
|
|||
|> assert_email_sent()
|
||||
end
|
||||
|
||||
test "sends a pending approval email" do
|
||||
clear_config([:instance, :account_approval_required], true)
|
||||
|
||||
{:ok, user} =
|
||||
User.register_changeset(%User{}, @full_user_data)
|
||||
|> User.register()
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert_email_sent(
|
||||
from: Pleroma.Config.Helpers.sender(),
|
||||
to: {user.name, user.email},
|
||||
subject: "Your account is awaiting approval"
|
||||
)
|
||||
end
|
||||
|
||||
test "it requires an email, name, nickname and password, bio is optional when account_activation_required is enabled" do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
|
||||
|
|
@ -877,6 +911,13 @@ defmodule Pleroma.UserTest do
|
|||
refute cs.valid?
|
||||
end)
|
||||
end
|
||||
|
||||
test "it is invalid given a local user" do
|
||||
user = insert(:user)
|
||||
cs = User.remote_user_changeset(user, %{name: "tom from myspace"})
|
||||
|
||||
refute cs.valid?
|
||||
end
|
||||
end
|
||||
|
||||
describe "followers and friends" do
|
||||
|
|
@ -886,8 +927,8 @@ defmodule Pleroma.UserTest do
|
|||
follower_two = insert(:user)
|
||||
not_follower = insert(:user)
|
||||
|
||||
{:ok, follower_one} = User.follow(follower_one, user)
|
||||
{:ok, follower_two} = User.follow(follower_two, user)
|
||||
{:ok, follower_one, user} = User.follow(follower_one, user)
|
||||
{:ok, follower_two, user} = User.follow(follower_two, user)
|
||||
|
||||
res = User.get_followers(user)
|
||||
|
||||
|
|
@ -902,8 +943,8 @@ defmodule Pleroma.UserTest do
|
|||
followed_two = insert(:user)
|
||||
not_followed = insert(:user)
|
||||
|
||||
{:ok, user} = User.follow(user, followed_one)
|
||||
{:ok, user} = User.follow(user, followed_two)
|
||||
{:ok, user, followed_one} = User.follow(user, followed_one)
|
||||
{:ok, user, followed_two} = User.follow(user, followed_two)
|
||||
|
||||
res = User.get_friends(user)
|
||||
|
||||
|
|
@ -990,6 +1031,27 @@ defmodule Pleroma.UserTest do
|
|||
assert User.muted_notifications?(user, muted_user)
|
||||
end
|
||||
|
||||
test "expiring" do
|
||||
user = insert(:user)
|
||||
muted_user = insert(:user)
|
||||
|
||||
{:ok, _user_relationships} = User.mute(user, muted_user, %{expires_in: 60})
|
||||
assert User.mutes?(user, muted_user)
|
||||
|
||||
worker = Pleroma.Workers.MuteExpireWorker
|
||||
args = %{"op" => "unmute_user", "muter_id" => user.id, "mutee_id" => muted_user.id}
|
||||
|
||||
assert_enqueued(
|
||||
worker: worker,
|
||||
args: args
|
||||
)
|
||||
|
||||
assert :ok = perform_job(worker, args)
|
||||
|
||||
refute User.mutes?(user, muted_user)
|
||||
refute User.muted_notifications?(user, muted_user)
|
||||
end
|
||||
|
||||
test "it unmutes users" do
|
||||
user = insert(:user)
|
||||
muted_user = insert(:user)
|
||||
|
|
@ -1001,6 +1063,17 @@ defmodule Pleroma.UserTest do
|
|||
refute User.muted_notifications?(user, muted_user)
|
||||
end
|
||||
|
||||
test "it unmutes users by id" do
|
||||
user = insert(:user)
|
||||
muted_user = insert(:user)
|
||||
|
||||
{:ok, _user_relationships} = User.mute(user, muted_user)
|
||||
{:ok, _user_mute} = User.unmute(user.id, muted_user.id)
|
||||
|
||||
refute User.mutes?(user, muted_user)
|
||||
refute User.muted_notifications?(user, muted_user)
|
||||
end
|
||||
|
||||
test "it mutes user without notifications" do
|
||||
user = insert(:user)
|
||||
muted_user = insert(:user)
|
||||
|
|
@ -1008,7 +1081,7 @@ defmodule Pleroma.UserTest do
|
|||
refute User.mutes?(user, muted_user)
|
||||
refute User.muted_notifications?(user, muted_user)
|
||||
|
||||
{:ok, _user_relationships} = User.mute(user, muted_user, false)
|
||||
{:ok, _user_relationships} = User.mute(user, muted_user, %{notifications: false})
|
||||
|
||||
assert User.mutes?(user, muted_user)
|
||||
refute User.muted_notifications?(user, muted_user)
|
||||
|
|
@ -1041,8 +1114,8 @@ defmodule Pleroma.UserTest do
|
|||
blocker = insert(:user)
|
||||
blocked = insert(:user)
|
||||
|
||||
{:ok, blocker} = User.follow(blocker, blocked)
|
||||
{:ok, blocked} = User.follow(blocked, blocker)
|
||||
{:ok, blocker, blocked} = User.follow(blocker, blocked)
|
||||
{:ok, blocked, blocker} = User.follow(blocked, blocker)
|
||||
|
||||
assert User.following?(blocker, blocked)
|
||||
assert User.following?(blocked, blocker)
|
||||
|
|
@ -1060,7 +1133,7 @@ defmodule Pleroma.UserTest do
|
|||
blocker = insert(:user)
|
||||
blocked = insert(:user)
|
||||
|
||||
{:ok, blocker} = User.follow(blocker, blocked)
|
||||
{:ok, blocker, blocked} = User.follow(blocker, blocked)
|
||||
|
||||
assert User.following?(blocker, blocked)
|
||||
refute User.following?(blocked, blocker)
|
||||
|
|
@ -1078,7 +1151,7 @@ defmodule Pleroma.UserTest do
|
|||
blocker = insert(:user)
|
||||
blocked = insert(:user)
|
||||
|
||||
{:ok, blocked} = User.follow(blocked, blocker)
|
||||
{:ok, blocked, blocker} = User.follow(blocked, blocker)
|
||||
|
||||
refute User.following?(blocker, blocked)
|
||||
assert User.following?(blocked, blocker)
|
||||
|
|
@ -1176,7 +1249,7 @@ defmodule Pleroma.UserTest do
|
|||
good_eggo = insert(:user, %{ap_id: "https://meanies.social/user/cuteposter"})
|
||||
|
||||
{:ok, user} = User.block_domain(user, "meanies.social")
|
||||
{:ok, user} = User.follow(user, good_eggo)
|
||||
{:ok, user, good_eggo} = User.follow(user, good_eggo)
|
||||
|
||||
refute User.blocks?(user, good_eggo)
|
||||
end
|
||||
|
|
@ -1210,8 +1283,8 @@ defmodule Pleroma.UserTest do
|
|||
assert Enum.map([actor, addressed], & &1.ap_id) --
|
||||
Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == []
|
||||
|
||||
{:ok, user} = User.follow(user, actor)
|
||||
{:ok, _user_two} = User.follow(user_two, actor)
|
||||
{:ok, user, actor} = User.follow(user, actor)
|
||||
{:ok, _user_two, _actor} = User.follow(user_two, actor)
|
||||
recipients = User.get_recipients_from_activity(activity)
|
||||
assert length(recipients) == 3
|
||||
assert user in recipients
|
||||
|
|
@ -1232,8 +1305,8 @@ defmodule Pleroma.UserTest do
|
|||
assert Enum.map([actor, addressed], & &1.ap_id) --
|
||||
Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == []
|
||||
|
||||
{:ok, _actor} = User.follow(actor, user)
|
||||
{:ok, _actor} = User.follow(actor, user_two)
|
||||
{:ok, _actor, _user} = User.follow(actor, user)
|
||||
{:ok, _actor, _user_two} = User.follow(actor, user_two)
|
||||
recipients = User.get_recipients_from_activity(activity)
|
||||
assert length(recipients) == 2
|
||||
assert addressed in recipients
|
||||
|
|
@ -1254,7 +1327,7 @@ defmodule Pleroma.UserTest do
|
|||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
{:ok, user} = User.follow(user, user2)
|
||||
{:ok, user, user2} = User.follow(user, user2)
|
||||
{:ok, _user} = User.deactivate(user)
|
||||
|
||||
user2 = User.get_cached_by_id(user2.id)
|
||||
|
|
@ -1267,7 +1340,7 @@ defmodule Pleroma.UserTest do
|
|||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
{:ok, user2} = User.follow(user2, user)
|
||||
{:ok, user2, user} = User.follow(user2, user)
|
||||
assert user2.following_count == 1
|
||||
assert User.following_count(user2) == 1
|
||||
|
||||
|
|
@ -1285,7 +1358,7 @@ defmodule Pleroma.UserTest do
|
|||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
{:ok, user2} = User.follow(user2, user)
|
||||
{:ok, user2, user} = User.follow(user2, user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "hey @#{user2.nickname}"})
|
||||
|
||||
|
|
@ -1336,6 +1409,98 @@ defmodule Pleroma.UserTest do
|
|||
assert false == user.approval_pending
|
||||
end)
|
||||
end
|
||||
|
||||
test "it sends welcome email if it is set" do
|
||||
clear_config([:welcome, :email, :enabled], true)
|
||||
clear_config([:welcome, :email, :sender], "tester@test.me")
|
||||
|
||||
user = insert(:user, approval_pending: true)
|
||||
welcome_user = insert(:user, email: "tester@test.me")
|
||||
instance_name = Pleroma.Config.get([:instance, :name])
|
||||
|
||||
User.approve(user)
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert_email_sent(
|
||||
from: {instance_name, welcome_user.email},
|
||||
to: {user.name, user.email},
|
||||
html_body: "Welcome to #{instance_name}"
|
||||
)
|
||||
end
|
||||
|
||||
test "approving an approved user does not trigger post-register actions" do
|
||||
clear_config([:welcome, :email, :enabled], true)
|
||||
|
||||
user = insert(:user, approval_pending: false)
|
||||
User.approve(user)
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert_no_email_sent()
|
||||
end
|
||||
end
|
||||
|
||||
describe "confirm" do
|
||||
test "confirms a user" do
|
||||
user = insert(:user, confirmation_pending: true)
|
||||
assert true == user.confirmation_pending
|
||||
{:ok, user} = User.confirm(user)
|
||||
assert false == user.confirmation_pending
|
||||
end
|
||||
|
||||
test "confirms a list of users" do
|
||||
unconfirmed_users = [
|
||||
insert(:user, confirmation_pending: true),
|
||||
insert(:user, confirmation_pending: true),
|
||||
insert(:user, confirmation_pending: true)
|
||||
]
|
||||
|
||||
{:ok, users} = User.confirm(unconfirmed_users)
|
||||
|
||||
assert Enum.count(users) == 3
|
||||
|
||||
Enum.each(users, fn user ->
|
||||
assert false == user.confirmation_pending
|
||||
end)
|
||||
end
|
||||
|
||||
test "sends approval emails when `approval_pending: true`" do
|
||||
admin = insert(:user, is_admin: true)
|
||||
user = insert(:user, confirmation_pending: true, approval_pending: true)
|
||||
User.confirm(user)
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
user_email = Pleroma.Emails.UserEmail.approval_pending_email(user)
|
||||
admin_email = Pleroma.Emails.AdminEmail.new_unapproved_registration(admin, user)
|
||||
|
||||
notify_email = Pleroma.Config.get([:instance, :notify_email])
|
||||
instance_name = Pleroma.Config.get([:instance, :name])
|
||||
|
||||
# User approval email
|
||||
assert_email_sent(
|
||||
from: {instance_name, notify_email},
|
||||
to: {user.name, user.email},
|
||||
html_body: user_email.html_body
|
||||
)
|
||||
|
||||
# Admin email
|
||||
assert_email_sent(
|
||||
from: {instance_name, notify_email},
|
||||
to: {admin.name, admin.email},
|
||||
html_body: admin_email.html_body
|
||||
)
|
||||
end
|
||||
|
||||
test "confirming a confirmed user does not trigger post-register actions" do
|
||||
user = insert(:user, confirmation_pending: false, approval_pending: true)
|
||||
User.confirm(user)
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert_no_email_sent()
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete" do
|
||||
|
|
@ -1358,10 +1523,10 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
test "it deactivates a user, all follow relationships and all activities", %{user: user} do
|
||||
follower = insert(:user)
|
||||
{:ok, follower} = User.follow(follower, user)
|
||||
{:ok, follower, user} = User.follow(follower, user)
|
||||
|
||||
locked_user = insert(:user, name: "locked", is_locked: true)
|
||||
{:ok, _} = User.follow(user, locked_user, :follow_pending)
|
||||
{:ok, _, _} = User.follow(user, locked_user, :follow_pending)
|
||||
|
||||
object = insert(:note, user: user)
|
||||
activity = insert(:note_activity, user: user, note: object)
|
||||
|
|
@ -1467,7 +1632,7 @@ defmodule Pleroma.UserTest do
|
|||
pleroma_settings_store: %{"q" => "x"},
|
||||
fields: [%{"gg" => "qq"}],
|
||||
raw_fields: [%{"gg" => "qq"}],
|
||||
discoverable: true,
|
||||
is_discoverable: true,
|
||||
also_known_as: ["https://lol.olo/users/loll"]
|
||||
})
|
||||
|
||||
|
|
@ -1509,7 +1674,7 @@ defmodule Pleroma.UserTest do
|
|||
pleroma_settings_store: %{},
|
||||
fields: [],
|
||||
raw_fields: [],
|
||||
discoverable: false,
|
||||
is_discoverable: false,
|
||||
also_known_as: []
|
||||
} = user
|
||||
end
|
||||
|
|
@ -1719,9 +1884,9 @@ defmodule Pleroma.UserTest do
|
|||
follower2 = insert(:user)
|
||||
follower3 = insert(:user)
|
||||
|
||||
{:ok, follower} = User.follow(follower, user)
|
||||
{:ok, _follower2} = User.follow(follower2, user)
|
||||
{:ok, _follower3} = User.follow(follower3, user)
|
||||
{:ok, follower, user} = User.follow(follower, user)
|
||||
{:ok, _follower2, _user} = User.follow(follower2, user)
|
||||
{:ok, _follower3, _user} = User.follow(follower3, user)
|
||||
|
||||
{:ok, _user_relationship} = User.block(user, follower)
|
||||
user = refresh_record(user)
|
||||
|
|
@ -1832,24 +1997,6 @@ defmodule Pleroma.UserTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "toggle_confirmation/1" do
|
||||
test "if user is confirmed" do
|
||||
user = insert(:user, confirmation_pending: false)
|
||||
{:ok, user} = User.toggle_confirmation(user)
|
||||
|
||||
assert user.confirmation_pending
|
||||
assert user.confirmation_token
|
||||
end
|
||||
|
||||
test "if user is unconfirmed" do
|
||||
user = insert(:user, confirmation_pending: true, confirmation_token: "some token")
|
||||
{:ok, user} = User.toggle_confirmation(user)
|
||||
|
||||
refute user.confirmation_pending
|
||||
refute user.confirmation_token
|
||||
end
|
||||
end
|
||||
|
||||
describe "ensure_keys_present" do
|
||||
test "it creates keys for a user and stores them in info" do
|
||||
user = insert(:user)
|
||||
|
|
@ -1962,8 +2109,7 @@ defmodule Pleroma.UserTest do
|
|||
assert other_user.following_count == 0
|
||||
assert other_user.follower_count == 0
|
||||
|
||||
{:ok, user} = Pleroma.User.follow(user, other_user)
|
||||
other_user = Pleroma.User.get_by_id(other_user.id)
|
||||
{:ok, user, other_user} = Pleroma.User.follow(user, other_user)
|
||||
|
||||
assert user.following_count == 1
|
||||
assert other_user.follower_count == 1
|
||||
|
|
@ -1986,8 +2132,7 @@ defmodule Pleroma.UserTest do
|
|||
assert other_user.follower_count == 0
|
||||
|
||||
Pleroma.Config.put([:instance, :external_user_synchronization], true)
|
||||
{:ok, _user} = User.follow(user, other_user)
|
||||
other_user = User.get_by_id(other_user.id)
|
||||
{:ok, _user, other_user} = User.follow(user, other_user)
|
||||
|
||||
assert other_user.follower_count == 437
|
||||
end
|
||||
|
|
@ -2009,7 +2154,7 @@ defmodule Pleroma.UserTest do
|
|||
assert other_user.follower_count == 0
|
||||
|
||||
Pleroma.Config.put([:instance, :external_user_synchronization], true)
|
||||
{:ok, other_user} = User.follow(other_user, user)
|
||||
{:ok, other_user, _user} = User.follow(other_user, user)
|
||||
|
||||
assert other_user.following_count == 152
|
||||
end
|
||||
|
|
@ -2121,4 +2266,9 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
assert User.avatar_url(user, no_default: true) == nil
|
||||
end
|
||||
|
||||
test "get_host/1" do
|
||||
user = insert(:user, ap_id: "https://lain.com/users/lain", nickname: "lain")
|
||||
assert User.get_host(user) == "lain.com"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -156,21 +156,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
assert response == "Not found"
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
put_req_header(
|
||||
conn,
|
||||
"accept",
|
||||
"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
|
||||
)
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/users/#{user.nickname}.json", user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "mastodon compatibility routes" do
|
||||
|
|
@ -228,6 +213,23 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
end
|
||||
|
||||
describe "/objects/:uuid" do
|
||||
test "it doesn't return a local-only object", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
{:ok, post} = CommonAPI.post(user, %{status: "test", visibility: "local"})
|
||||
|
||||
assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post)
|
||||
|
||||
object = Object.normalize(post, false)
|
||||
uuid = String.split(object.data["id"], "/") |> List.last()
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> get("/objects/#{uuid}")
|
||||
|
||||
assert json_response(conn, 404)
|
||||
end
|
||||
|
||||
test "it returns a json representation of the object with accept application/json", %{
|
||||
conn: conn
|
||||
} do
|
||||
|
|
@ -338,21 +340,25 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
assert "Not found" == json_response(conn2, :not_found)
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
note = insert(:note)
|
||||
uuid = String.split(note.data["id"], "/") |> List.last()
|
||||
|
||||
conn = put_req_header(conn, "accept", "application/activity+json")
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/objects/#{uuid}", user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/activities/:uuid" do
|
||||
test "it doesn't return a local-only activity", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
{:ok, post} = CommonAPI.post(user, %{status: "test", visibility: "local"})
|
||||
|
||||
assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post)
|
||||
|
||||
uuid = String.split(post.data["id"], "/") |> List.last()
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> get("/activities/#{uuid}")
|
||||
|
||||
assert json_response(conn, 404)
|
||||
end
|
||||
|
||||
test "it returns a json representation of the activity", %{conn: conn} do
|
||||
activity = insert(:note_activity)
|
||||
uuid = String.split(activity.data["id"], "/") |> List.last()
|
||||
|
|
@ -421,23 +427,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
assert "Not found" == json_response(conn2, :not_found)
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
activity = insert(:note_activity)
|
||||
uuid = String.split(activity.data["id"], "/") |> List.last()
|
||||
|
||||
conn = put_req_header(conn, "accept", "application/activity+json")
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/activities/#{uuid}", user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/inbox" do
|
||||
test "it inserts an incoming activity into the database", %{conn: conn} do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Jason.decode!()
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -465,7 +459,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("actor", user.ap_id)
|
||||
|> put_in(["object", "attridbutedTo"], user.ap_id)
|
||||
|
||||
|
|
@ -482,7 +476,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
end
|
||||
|
||||
test "it clears `unreachable` federation status of the sender", %{conn: conn} do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Jason.decode!()
|
||||
|
||||
sender_url = data["actor"]
|
||||
Instances.set_consistently_unreachable(sender_url)
|
||||
|
|
@ -540,8 +534,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
test "without valid signature, " <>
|
||||
"it only accepts Create activities and requires enabled federation",
|
||||
%{conn: conn} do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
|
||||
non_create_data = File.read!("test/fixtures/mastodon-announce.json") |> Poison.decode!()
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Jason.decode!()
|
||||
non_create_data = File.read!("test/fixtures/mastodon-announce.json") |> Jason.decode!()
|
||||
|
||||
conn = put_req_header(conn, "content-type", "application/activity+json")
|
||||
|
||||
|
|
@ -570,7 +564,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
setup do
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|
||||
[data: data]
|
||||
end
|
||||
|
|
@ -681,7 +675,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
recipient = insert(:user)
|
||||
actor = insert(:user, %{ap_id: "http://mastodon.example.org/users/actor"})
|
||||
|
||||
{:ok, recipient} = User.follow(recipient, actor)
|
||||
{:ok, recipient, actor} = User.follow(recipient, actor)
|
||||
|
||||
object =
|
||||
data["object"]
|
||||
|
|
@ -753,7 +747,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/activitypub-client-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|
||||
object = Map.put(data["object"], "attributedTo", actor.ap_id)
|
||||
|
||||
|
|
@ -805,6 +799,142 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
assert json_response(ret_conn, 200)
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
test "forwarded report", %{conn: conn} do
|
||||
admin = insert(:user, is_admin: true)
|
||||
actor = insert(:user, local: false)
|
||||
remote_domain = URI.parse(actor.ap_id).host
|
||||
reported_user = insert(:user)
|
||||
|
||||
note = insert(:note_activity, user: reported_user)
|
||||
|
||||
data = %{
|
||||
"@context" => [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://#{remote_domain}/schemas/litepub-0.1.jsonld",
|
||||
%{
|
||||
"@language" => "und"
|
||||
}
|
||||
],
|
||||
"actor" => actor.ap_id,
|
||||
"cc" => [
|
||||
reported_user.ap_id
|
||||
],
|
||||
"content" => "test",
|
||||
"context" => "context",
|
||||
"id" => "http://#{remote_domain}/activities/02be56cf-35e3-46b4-b2c6-47ae08dfee9e",
|
||||
"nickname" => reported_user.nickname,
|
||||
"object" => [
|
||||
reported_user.ap_id,
|
||||
%{
|
||||
"actor" => %{
|
||||
"actor_type" => "Person",
|
||||
"approval_pending" => false,
|
||||
"avatar" => "",
|
||||
"confirmation_pending" => false,
|
||||
"deactivated" => false,
|
||||
"display_name" => "test user",
|
||||
"id" => reported_user.id,
|
||||
"local" => false,
|
||||
"nickname" => reported_user.nickname,
|
||||
"registration_reason" => nil,
|
||||
"roles" => %{
|
||||
"admin" => false,
|
||||
"moderator" => false
|
||||
},
|
||||
"tags" => [],
|
||||
"url" => reported_user.ap_id
|
||||
},
|
||||
"content" => "",
|
||||
"id" => note.data["id"],
|
||||
"published" => note.data["published"],
|
||||
"type" => "Note"
|
||||
}
|
||||
],
|
||||
"published" => note.data["published"],
|
||||
"state" => "open",
|
||||
"to" => [],
|
||||
"type" => "Flag"
|
||||
}
|
||||
|
||||
conn
|
||||
|> assign(:valid_signature, true)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{reported_user.nickname}/inbox", data)
|
||||
|> json_response(200)
|
||||
|
||||
ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
|
||||
|
||||
assert Pleroma.Repo.aggregate(Activity, :count, :id) == 2
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
Swoosh.TestAssertions.assert_email_sent(
|
||||
to: {admin.name, admin.email},
|
||||
html_body: ~r/Reported Account:/i
|
||||
)
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
test "forwarded report from mastodon", %{conn: conn} do
|
||||
admin = insert(:user, is_admin: true)
|
||||
actor = insert(:user, local: false)
|
||||
remote_domain = URI.parse(actor.ap_id).host
|
||||
remote_actor = "https://#{remote_domain}/actor"
|
||||
[reported_user, another] = insert_list(2, :user)
|
||||
|
||||
note = insert(:note_activity, user: reported_user)
|
||||
|
||||
Pleroma.Web.CommonAPI.favorite(another, note.id)
|
||||
|
||||
mock_json_body =
|
||||
"test/fixtures/mastodon/application_actor.json"
|
||||
|> File.read!()
|
||||
|> String.replace("{{DOMAIN}}", remote_domain)
|
||||
|
||||
Tesla.Mock.mock(fn %{url: ^remote_actor} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: mock_json_body,
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
end)
|
||||
|
||||
data = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"actor" => remote_actor,
|
||||
"content" => "test report",
|
||||
"id" => "https://#{remote_domain}/e3b12fd1-948c-446e-b93b-a5e67edbe1d8",
|
||||
"nickname" => reported_user.nickname,
|
||||
"object" => [
|
||||
reported_user.ap_id,
|
||||
note.data["object"]
|
||||
],
|
||||
"type" => "Flag"
|
||||
}
|
||||
|
||||
conn
|
||||
|> assign(:valid_signature, true)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{reported_user.nickname}/inbox", data)
|
||||
|> json_response(200)
|
||||
|
||||
ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
|
||||
|
||||
flag_activity = "Flag" |> Pleroma.Activity.Queries.by_type() |> Pleroma.Repo.one()
|
||||
reported_user_ap_id = reported_user.ap_id
|
||||
|
||||
[^reported_user_ap_id, flag_data] = flag_activity.data["object"]
|
||||
|
||||
Enum.each(~w(actor content id published type), &Map.has_key?(flag_data, &1))
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
Swoosh.TestAssertions.assert_email_sent(
|
||||
to: {admin.name, admin.email},
|
||||
html_body: ~r/#{note.data["object"]}/i
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /users/:nickname/outbox" do
|
||||
|
|
@ -893,15 +1023,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
assert response(conn, 200) =~ announce_activity.data["object"]
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
conn = put_req_header(conn, "accept", "application/activity+json")
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/users/#{user.nickname}/outbox", user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /users/:nickname/outbox (C2S)" do
|
||||
|
|
|
|||
|
|
@ -505,22 +505,22 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
|
||||
# public
|
||||
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, :visibility, "public"))
|
||||
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert object.data["repliesCount"] == 1
|
||||
|
||||
# unlisted
|
||||
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, :visibility, "unlisted"))
|
||||
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert object.data["repliesCount"] == 2
|
||||
|
||||
# private
|
||||
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, :visibility, "private"))
|
||||
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert object.data["repliesCount"] == 2
|
||||
|
||||
# direct
|
||||
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, :visibility, "direct"))
|
||||
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert object.data["repliesCount"] == 2
|
||||
end
|
||||
end
|
||||
|
|
@ -726,7 +726,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
domain_user = insert(:user, %{ap_id: "https://#{domain}/@pundit"})
|
||||
blocker = insert(:user)
|
||||
|
||||
{:ok, blocker} = User.follow(blocker, domain_user)
|
||||
{:ok, blocker, domain_user} = User.follow(blocker, domain_user)
|
||||
{:ok, blocker} = User.block_domain(blocker, domain)
|
||||
|
||||
assert User.following?(blocker, domain_user)
|
||||
|
|
@ -752,6 +752,22 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
refute repeat_activity in activities
|
||||
end
|
||||
|
||||
test "returns your own posts regardless of mute" do
|
||||
user = insert(:user)
|
||||
muted = insert(:user)
|
||||
|
||||
{:ok, muted_post} = CommonAPI.post(muted, %{status: "Im stupid"})
|
||||
|
||||
{:ok, reply} =
|
||||
CommonAPI.post(user, %{status: "I'm muting you", in_reply_to_status_id: muted_post.id})
|
||||
|
||||
{:ok, _} = User.mute(user, muted)
|
||||
|
||||
[activity] = ActivityPub.fetch_activities([], %{muting_user: user, skip_preload: true})
|
||||
|
||||
assert activity.id == reply.id
|
||||
end
|
||||
|
||||
test "doesn't return muted activities" do
|
||||
activity_one = insert(:note_activity)
|
||||
activity_two = insert(:note_activity)
|
||||
|
|
@ -837,7 +853,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
user = insert(:user)
|
||||
booster = insert(:user)
|
||||
|
||||
{:ok, user} = User.follow(user, booster)
|
||||
{:ok, user, booster} = User.follow(user, booster)
|
||||
|
||||
{:ok, announce} = CommonAPI.repeat(activity_three.id, booster)
|
||||
|
||||
|
|
@ -1142,13 +1158,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
user2 = insert(:user)
|
||||
user3 = insert(:user)
|
||||
|
||||
{:ok, user1} = User.follow(user1, user3)
|
||||
{:ok, user1, user3} = User.follow(user1, user3)
|
||||
assert User.following?(user1, user3)
|
||||
|
||||
{:ok, user2} = User.follow(user2, user3)
|
||||
{:ok, user2, user3} = User.follow(user2, user3)
|
||||
assert User.following?(user2, user3)
|
||||
|
||||
{:ok, user3} = User.follow(user3, user2)
|
||||
{:ok, user3, user2} = User.follow(user3, user2)
|
||||
assert User.following?(user3, user2)
|
||||
|
||||
{:ok, public_activity} = CommonAPI.post(user3, %{status: "hi 1"})
|
||||
|
|
@ -1282,6 +1298,31 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
|
||||
assert_called(Utils.maybe_federate(%{activity | data: new_data}))
|
||||
end
|
||||
|
||||
test_with_mock "reverts on error",
|
||||
%{
|
||||
reporter: reporter,
|
||||
context: context,
|
||||
target_account: target_account,
|
||||
reported_activity: reported_activity,
|
||||
content: content
|
||||
},
|
||||
Utils,
|
||||
[:passthrough],
|
||||
maybe_federate: fn _ -> {:error, :reverted} end do
|
||||
assert {:error, :reverted} =
|
||||
ActivityPub.flag(%{
|
||||
actor: reporter,
|
||||
context: context,
|
||||
account: target_account,
|
||||
statuses: [reported_activity],
|
||||
content: content
|
||||
})
|
||||
|
||||
assert Repo.aggregate(Activity, :count, :id) == 1
|
||||
assert Repo.aggregate(Object, :count, :id) == 2
|
||||
assert Repo.aggregate(Notification, :count, :id) == 0
|
||||
end
|
||||
end
|
||||
|
||||
test "fetch_activities/2 returns activities addressed to a list " do
|
||||
|
|
@ -1410,19 +1451,25 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
mock(fn env ->
|
||||
case env.url do
|
||||
"http://localhost:4001/users/masto_hidden_counters/following" ->
|
||||
json(%{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"id" => "http://localhost:4001/users/masto_hidden_counters/followers"
|
||||
})
|
||||
json(
|
||||
%{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"id" => "http://localhost:4001/users/masto_hidden_counters/followers"
|
||||
},
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
)
|
||||
|
||||
"http://localhost:4001/users/masto_hidden_counters/following?page=1" ->
|
||||
%Tesla.Env{status: 403, body: ""}
|
||||
|
||||
"http://localhost:4001/users/masto_hidden_counters/followers" ->
|
||||
json(%{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"id" => "http://localhost:4001/users/masto_hidden_counters/following"
|
||||
})
|
||||
json(
|
||||
%{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"id" => "http://localhost:4001/users/masto_hidden_counters/following"
|
||||
},
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
)
|
||||
|
||||
"http://localhost:4001/users/masto_hidden_counters/followers?page=1" ->
|
||||
%Tesla.Env{status: 403, body: ""}
|
||||
|
|
@ -1884,13 +1931,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
|
||||
defp public_messages(_) do
|
||||
[u1, u2, u3, u4] = insert_list(4, :user)
|
||||
{:ok, u1} = User.follow(u1, u2)
|
||||
{:ok, u2} = User.follow(u2, u1)
|
||||
{:ok, u1} = User.follow(u1, u4)
|
||||
{:ok, u4} = User.follow(u4, u1)
|
||||
{:ok, u1, u2} = User.follow(u1, u2)
|
||||
{:ok, u2, u1} = User.follow(u2, u1)
|
||||
{:ok, u1, u4} = User.follow(u1, u4)
|
||||
{:ok, u4, u1} = User.follow(u4, u1)
|
||||
|
||||
{:ok, u2} = User.follow(u2, u3)
|
||||
{:ok, u3} = User.follow(u3, u2)
|
||||
{:ok, u2, u3} = User.follow(u2, u3)
|
||||
{:ok, u3, u2} = User.follow(u3, u2)
|
||||
|
||||
{:ok, a1} = CommonAPI.post(u1, %{status: "Status"})
|
||||
|
||||
|
|
@ -1983,15 +2030,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
|
||||
defp private_messages(_) do
|
||||
[u1, u2, u3, u4] = insert_list(4, :user)
|
||||
{:ok, u1} = User.follow(u1, u2)
|
||||
{:ok, u2} = User.follow(u2, u1)
|
||||
{:ok, u1} = User.follow(u1, u3)
|
||||
{:ok, u3} = User.follow(u3, u1)
|
||||
{:ok, u1} = User.follow(u1, u4)
|
||||
{:ok, u4} = User.follow(u4, u1)
|
||||
{:ok, u1, u2} = User.follow(u1, u2)
|
||||
{:ok, u2, u1} = User.follow(u2, u1)
|
||||
{:ok, u1, u3} = User.follow(u1, u3)
|
||||
{:ok, u3, u1} = User.follow(u3, u1)
|
||||
{:ok, u1, u4} = User.follow(u1, u4)
|
||||
{:ok, u4, u1} = User.follow(u4, u1)
|
||||
|
||||
{:ok, u2} = User.follow(u2, u3)
|
||||
{:ok, u3} = User.follow(u3, u2)
|
||||
{:ok, u2, u3} = User.follow(u2, u3)
|
||||
{:ok, u3, u2} = User.follow(u3, u2)
|
||||
|
||||
{:ok, a1} = CommonAPI.post(u1, %{status: "Status", visibility: "private"})
|
||||
|
||||
|
|
@ -2257,4 +2304,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert length(activities) == 2
|
||||
end
|
||||
end
|
||||
|
||||
test "allow fetching of accounts with an empty string name field" do
|
||||
Tesla.Mock.mock(fn
|
||||
%{method: :get, url: "https://princess.cat/users/mewmew"} ->
|
||||
file = File.read!("test/fixtures/mewmew_no_name.json")
|
||||
%Tesla.Env{status: 200, body: file, headers: HttpRequestMock.activitypub_object_headers()}
|
||||
end)
|
||||
|
||||
{:ok, user} = ActivityPub.make_user_from_ap_id("https://princess.cat/users/mewmew")
|
||||
assert user.name == " "
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicyTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrependedTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.ForceBotUnlistedPolicyTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Web.ActivityPub.MRF.ForceBotUnlistedPolicy
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do
|
||||
use Pleroma.DataCase
|
||||
use ExUnit.Case
|
||||
use Pleroma.Tests.Helpers
|
||||
|
||||
alias Pleroma.HTTP
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy
|
||||
|
||||
import Mock
|
||||
|
|
@ -25,13 +25,13 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do
|
|||
setup do: clear_config([:media_proxy, :enabled], true)
|
||||
|
||||
test "it prefetches media proxy URIs" do
|
||||
Tesla.Mock.mock(fn %{method: :get, url: "http://example.com/image.jpg"} ->
|
||||
{:ok, %Tesla.Env{status: 200, body: ""}}
|
||||
end)
|
||||
|
||||
with_mock HTTP, get: fn _, _, _ -> {:ok, []} end do
|
||||
MediaProxyWarmingPolicy.filter(@message)
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
# Performing jobs which has been just enqueued
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert called(HTTP.get(:_, :_, :_))
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicyTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
alias Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicy
|
||||
|
||||
test "it clears content object" do
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkupTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
alias Pleroma.Web.ActivityPub.MRF.NormalizeMarkup
|
||||
|
||||
@html_sample """
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||
|
||||
defp get_old_message do
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
end
|
||||
|
||||
defp get_new_message do
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
|
|||
"type" => "Create"
|
||||
}
|
||||
|
||||
assert {:ok, message} = RejectNonPublic.filter(message)
|
||||
assert {:ok, _message} = RejectNonPublic.filter(message)
|
||||
end
|
||||
|
||||
test "it's allowed when cc address contain public address" do
|
||||
|
|
@ -34,7 +34,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
|
|||
"type" => "Create"
|
||||
}
|
||||
|
||||
assert {:ok, message} = RejectNonPublic.filter(message)
|
||||
assert {:ok, _message} = RejectNonPublic.filter(message)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
|
|||
}
|
||||
|
||||
Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], true)
|
||||
assert {:ok, message} = RejectNonPublic.filter(message)
|
||||
assert {:ok, _message} = RejectNonPublic.filter(message)
|
||||
end
|
||||
|
||||
test "it's rejected when addrer of message in the follower addresses of user and it disabled in config" do
|
||||
|
|
@ -80,7 +80,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
|
|||
}
|
||||
|
||||
Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], true)
|
||||
assert {:ok, message} = RejectNonPublic.filter(message)
|
||||
assert {:ok, _message} = RejectNonPublic.filter(message)
|
||||
end
|
||||
|
||||
test "it's reject when direct messages aren't allow" do
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Web.ActivityPub.MRF.TagPolicy
|
||||
|
|
@ -29,7 +29,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do
|
|||
actor = insert(:user, tags: ["mrf_tag:disable-remote-subscription"])
|
||||
follower = insert(:user, tags: ["mrf_tag:disable-remote-subscription"], local: true)
|
||||
message = %{"object" => actor.ap_id, "type" => "Follow", "actor" => follower.ap_id}
|
||||
assert {:ok, message} = TagPolicy.filter(message)
|
||||
assert {:ok, _message} = TagPolicy.filter(message)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -87,4 +87,20 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
{:ok, ^expected} = MRF.describe()
|
||||
end
|
||||
end
|
||||
|
||||
test "config_descriptions/0" do
|
||||
descriptions = MRF.config_descriptions()
|
||||
|
||||
good_mrf = Enum.find(descriptions, fn %{key: key} -> key == :good_mrf end)
|
||||
|
||||
assert good_mrf == %{
|
||||
key: :good_mrf,
|
||||
related_policy: "Fixtures.Modules.GoodMRF",
|
||||
label: "Good MRF",
|
||||
description: "Some description",
|
||||
group: :pleroma,
|
||||
tab: :mrf,
|
||||
type: :group
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.AcceptValidationTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidator
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnnounceValidationTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidatorTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidator
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
|
||||
|
|
@ -33,7 +33,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
|
|||
"http://mastodon.example.org/system/media_attachments/files/000/000/002/original/334ce029e7bfb920.jpg",
|
||||
"type" => "Document",
|
||||
"name" => nil,
|
||||
"mediaType" => "image/jpeg"
|
||||
"mediaType" => "image/jpeg",
|
||||
"blurhash" => "UD9jJz~VSbR#xT$~%KtQX9R,WAs9RjWBs:of"
|
||||
}
|
||||
|
||||
{:ok, attachment} =
|
||||
|
|
@ -50,6 +51,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
|
|||
] = attachment.url
|
||||
|
||||
assert attachment.mediaType == "image/jpeg"
|
||||
assert attachment.blurhash == "UD9jJz~VSbR#xT$~%KtQX9R,WAs9RjWBs:of"
|
||||
end
|
||||
|
||||
test "it handles our own uploads" do
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.BlockValidationTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidator
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidationTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.EmojiReactHandlingTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidator
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.FollowValidationTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidator
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.LikeValidationTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidator
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.LikeValidator
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.RejectValidationTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidator
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.UndoHandlingTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidator
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.UpdateHandlingTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidator
|
||||
|
|
|
|||
|
|
@ -3,14 +3,35 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
import Mock
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.ConfigMock
|
||||
alias Pleroma.Web.ActivityPub.ActivityPubMock
|
||||
alias Pleroma.Web.ActivityPub.MRFMock
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidatorMock
|
||||
alias Pleroma.Web.ActivityPub.SideEffectsMock
|
||||
alias Pleroma.Web.FederatorMock
|
||||
|
||||
setup :verify_on_exit!
|
||||
|
||||
describe "common_pipeline/2" do
|
||||
setup do
|
||||
clear_config([:instance, :federating], true)
|
||||
ObjectValidatorMock
|
||||
|> expect(:validate, fn o, m -> {:ok, o, m} end)
|
||||
|
||||
MRFMock
|
||||
|> expect(:pipeline_filter, fn o, m -> {:ok, o, m} end)
|
||||
|
||||
ActivityPubMock
|
||||
|> expect(:persist, fn o, m -> {:ok, o, m} end)
|
||||
|
||||
SideEffectsMock
|
||||
|> expect(:handle, fn o, m -> {:ok, o, m} end)
|
||||
|> expect(:handle_after_transaction, fn m -> m end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
|
|
@ -21,159 +42,53 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
|||
|
||||
activity_with_object = %{activity | data: Map.put(activity.data, "object", object)}
|
||||
|
||||
with_mocks([
|
||||
{Pleroma.Web.ActivityPub.ObjectValidator, [], [validate: fn o, m -> {:ok, o, m} end]},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.MRF,
|
||||
[],
|
||||
[pipeline_filter: fn o, m -> {:ok, o, m} end]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.ActivityPub,
|
||||
[],
|
||||
[persist: fn o, m -> {:ok, o, m} end]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.SideEffects,
|
||||
[],
|
||||
[
|
||||
handle: fn o, m -> {:ok, o, m} end,
|
||||
handle_after_transaction: fn m -> m end
|
||||
]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.Federator,
|
||||
[],
|
||||
[publish: fn _o -> :ok end]
|
||||
}
|
||||
]) do
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
FederatorMock
|
||||
|> expect(:publish, fn ^activity_with_object -> :ok end)
|
||||
|
||||
assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
|
||||
refute called(Pleroma.Web.Federator.publish(activity))
|
||||
assert_called(Pleroma.Web.Federator.publish(activity_with_object))
|
||||
end
|
||||
ConfigMock
|
||||
|> expect(:get, fn [:instance, :federating] -> true end)
|
||||
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(
|
||||
activity,
|
||||
meta
|
||||
)
|
||||
end
|
||||
|
||||
test "it goes through validation, filtering, persisting, side effects and federation for local activities" do
|
||||
activity = insert(:note_activity)
|
||||
meta = [local: true]
|
||||
|
||||
with_mocks([
|
||||
{Pleroma.Web.ActivityPub.ObjectValidator, [], [validate: fn o, m -> {:ok, o, m} end]},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.MRF,
|
||||
[],
|
||||
[pipeline_filter: fn o, m -> {:ok, o, m} end]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.ActivityPub,
|
||||
[],
|
||||
[persist: fn o, m -> {:ok, o, m} end]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.SideEffects,
|
||||
[],
|
||||
[
|
||||
handle: fn o, m -> {:ok, o, m} end,
|
||||
handle_after_transaction: fn m -> m end
|
||||
]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.Federator,
|
||||
[],
|
||||
[publish: fn _o -> :ok end]
|
||||
}
|
||||
]) do
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
FederatorMock
|
||||
|> expect(:publish, fn ^activity -> :ok end)
|
||||
|
||||
assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
|
||||
assert_called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
ConfigMock
|
||||
|> expect(:get, fn [:instance, :federating] -> true end)
|
||||
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
end
|
||||
|
||||
test "it goes through validation, filtering, persisting, side effects without federation for remote activities" do
|
||||
activity = insert(:note_activity)
|
||||
meta = [local: false]
|
||||
|
||||
with_mocks([
|
||||
{Pleroma.Web.ActivityPub.ObjectValidator, [], [validate: fn o, m -> {:ok, o, m} end]},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.MRF,
|
||||
[],
|
||||
[pipeline_filter: fn o, m -> {:ok, o, m} end]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.ActivityPub,
|
||||
[],
|
||||
[persist: fn o, m -> {:ok, o, m} end]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.SideEffects,
|
||||
[],
|
||||
[handle: fn o, m -> {:ok, o, m} end, handle_after_transaction: fn m -> m end]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.Federator,
|
||||
[],
|
||||
[]
|
||||
}
|
||||
]) do
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
ConfigMock
|
||||
|> expect(:get, fn [:instance, :federating] -> true end)
|
||||
|
||||
assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
|
||||
end
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
end
|
||||
|
||||
test "it goes through validation, filtering, persisting, side effects without federation for local activities if federation is deactivated" do
|
||||
clear_config([:instance, :federating], false)
|
||||
|
||||
activity = insert(:note_activity)
|
||||
meta = [local: true]
|
||||
|
||||
with_mocks([
|
||||
{Pleroma.Web.ActivityPub.ObjectValidator, [], [validate: fn o, m -> {:ok, o, m} end]},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.MRF,
|
||||
[],
|
||||
[pipeline_filter: fn o, m -> {:ok, o, m} end]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.ActivityPub,
|
||||
[],
|
||||
[persist: fn o, m -> {:ok, o, m} end]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.SideEffects,
|
||||
[],
|
||||
[handle: fn o, m -> {:ok, o, m} end, handle_after_transaction: fn m -> m end]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.Federator,
|
||||
[],
|
||||
[]
|
||||
}
|
||||
]) do
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
ConfigMock
|
||||
|> expect(:get, fn [:instance, :federating] -> false end)
|
||||
|
||||
assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
|
||||
end
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -281,8 +281,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
actor = insert(:user, follower_address: follower.ap_id)
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, _follower_one} = Pleroma.User.follow(follower, actor)
|
||||
actor = refresh_record(actor)
|
||||
{:ok, follower, actor} = Pleroma.User.follow(follower, actor)
|
||||
|
||||
note_activity =
|
||||
insert(:note_activity,
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
|
|||
)
|
||||
|
||||
Pleroma.Repo.delete(user)
|
||||
Cachex.clear(:user_cache)
|
||||
User.invalidate_cache(user)
|
||||
|
||||
assert {:ok, %Activity{} = activity} = Relay.unfollow(user_ap_id, %{force: true})
|
||||
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
|
||||
describe "update users" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
user = insert(:user, local: false)
|
||||
{:ok, update_data, []} = Builder.update(user, %{"id" => user.ap_id, "name" => "new name!"})
|
||||
{:ok, update, _meta} = ActivityPub.persist(update_data, local: true)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.Transmogrifier.AcceptHandlingTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
|
|
@ -15,14 +15,14 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AcceptHandlingTest do
|
|||
follower = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
||||
{:ok, follower} = User.follow(follower, followed)
|
||||
{:ok, follower, followed} = User.follow(follower, followed)
|
||||
assert User.following?(follower, followed) == true
|
||||
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|
||||
object =
|
||||
|
|
@ -52,7 +52,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AcceptHandlingTest do
|
|||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|> Map.put("object", follow_activity.data["id"])
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AcceptHandlingTest do
|
|||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|
||||
accept_data =
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnnounceHandlingTest do
|
|||
end
|
||||
|
||||
test "it works for incoming announces with actor being inlined (kroeg)" do
|
||||
data = File.read!("test/fixtures/kroeg-announce-with-inline-actor.json") |> Poison.decode!()
|
||||
data = File.read!("test/fixtures/kroeg-announce-with-inline-actor.json") |> Jason.decode!()
|
||||
|
||||
_user = insert(:user, local: false, ap_id: data["actor"]["id"])
|
||||
other_user = insert(:user)
|
||||
|
|
@ -55,12 +55,16 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnnounceHandlingTest do
|
|||
test "it works for incoming announces, fetching the announced object" do
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-announce.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", "http://mastodon.example.org/users/admin/statuses/99541947525187367")
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{method: :get} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/mastodon-note-object.json")}
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/mastodon-note-object.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
end)
|
||||
|
||||
_user = insert(:user, local: false, ap_id: data["actor"])
|
||||
|
|
@ -86,7 +90,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnnounceHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-announce.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|
||||
_user = insert(:user, local: false, ap_id: data["actor"])
|
||||
|
|
@ -109,7 +113,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnnounceHandlingTest do
|
|||
test "it works for incoming announces with an inlined activity" do
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-announce-private.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|
||||
_user =
|
||||
insert(:user,
|
||||
|
|
@ -140,11 +144,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnnounceHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/bogus-mastodon-announce.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|
||||
_user = insert(:user, local: false, ap_id: data["actor"])
|
||||
|
||||
assert {:error, e} = Transmogrifier.handle_incoming(data)
|
||||
assert {:error, _e} = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
|
||||
test "it does not clobber the addressing on announce activities" do
|
||||
|
|
@ -153,7 +157,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnnounceHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-announce.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", Object.normalize(activity).data["id"])
|
||||
|> Map.put("to", ["http://mastodon.example.org/users/admin/followers"])
|
||||
|> Map.put("cc", [])
|
||||
|
|
|
|||
|
|
@ -27,10 +27,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnswerHandlingTest do
|
|||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
assert object.data["repliesCount"] == nil
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-vote.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Kernel.put_in(["to"], user.ap_id)
|
||||
|> Kernel.put_in(["object", "inReplyTo"], object.data["id"])
|
||||
|> Kernel.put_in(["object", "to"], user.ap_id)
|
||||
|
|
@ -41,7 +42,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnswerHandlingTest do
|
|||
assert answer_object.data["inReplyTo"] == object.data["id"]
|
||||
|
||||
new_object = Object.get_by_ap_id(object.data["id"])
|
||||
assert new_object.data["replies_count"] == object.data["replies_count"]
|
||||
assert new_object.data["repliesCount"] == nil
|
||||
|
||||
assert Enum.any?(
|
||||
new_object.data["oneOf"],
|
||||
|
|
@ -65,7 +66,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnswerHandlingTest do
|
|||
# TODO: Replace with CommonAPI vote creation when implemented
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-vote.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Kernel.put_in(["to"], user.ap_id)
|
||||
|> Kernel.put_in(["object", "inReplyTo"], poll_object.data["id"])
|
||||
|> Kernel.put_in(["object", "to"], user.ap_id)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ArticleHandlingTest do
|
|||
|
||||
test "Pterotype (Wordpress Plugin) Article" do
|
||||
Tesla.Mock.mock(fn %{url: "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog"} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json")}
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
end)
|
||||
|
||||
data =
|
||||
|
|
@ -36,13 +40,15 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ArticleHandlingTest do
|
|||
%{url: "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
|
||||
%{url: "https://baptiste.gelez.xyz/@/BaptisteGelez"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
end)
|
||||
|
||||
|
|
@ -61,7 +67,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ArticleHandlingTest do
|
|||
Tesla.Mock.mock(fn %{url: "https://prismo.news/@mxb"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/https___prismo.news__mxb.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/https___prismo.news__mxb.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
end)
|
||||
|
||||
|
|
|
|||
|
|
@ -48,11 +48,12 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
|
|||
%{url: "https://channels.tests.funkwhale.audio/federation/actors/compositions"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/funkwhale_channel.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/funkwhale_channel.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
end)
|
||||
|
||||
data = File.read!("test/fixtures/tesla_mock/funkwhale_create_audio.json") |> Poison.decode!()
|
||||
data = File.read!("test/fixtures/tesla_mock/funkwhale_create_audio.json") |> Jason.decode!()
|
||||
|
||||
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
|
|
@ -69,6 +70,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
|
|||
"mediaType" => "audio/ogg",
|
||||
"type" => "Link",
|
||||
"name" => nil,
|
||||
"blurhash" => nil,
|
||||
"url" => [
|
||||
%{
|
||||
"href" =>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.Transmogrifier.BlockHandlingTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.User
|
||||
|
|
@ -16,7 +16,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.BlockHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-block-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
blocker = insert(:user, ap_id: data["actor"])
|
||||
|
|
@ -36,12 +36,12 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.BlockHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-block-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", blocked.ap_id)
|
||||
|> Map.put("actor", blocker.ap_id)
|
||||
|
||||
{:ok, blocker} = User.follow(blocker, blocked)
|
||||
{:ok, blocked} = User.follow(blocked, blocker)
|
||||
{:ok, blocker, blocked} = User.follow(blocker, blocked)
|
||||
{:ok, blocked, blocker} = User.follow(blocked, blocker)
|
||||
|
||||
assert User.following?(blocker, blocked)
|
||||
assert User.following?(blocked, blocker)
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ChatMessageTest do
|
|||
test "it rejects messages that don't contain content" do
|
||||
data =
|
||||
File.read!("test/fixtures/create-chat-message.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|
||||
object =
|
||||
data["object"]
|
||||
|
|
@ -79,7 +79,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ChatMessageTest do
|
|||
test "it rejects messages that don't concern local users" do
|
||||
data =
|
||||
File.read!("test/fixtures/create-chat-message.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|
||||
_author =
|
||||
insert(:user, ap_id: data["actor"], local: false, last_refreshed_at: DateTime.utc_now())
|
||||
|
|
@ -97,7 +97,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ChatMessageTest do
|
|||
test "it rejects messages where the `to` field of activity and object don't match" do
|
||||
data =
|
||||
File.read!("test/fixtures/create-chat-message.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|
||||
author = insert(:user, ap_id: data["actor"])
|
||||
_recipient = insert(:user, ap_id: List.first(data["to"]))
|
||||
|
|
@ -115,7 +115,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ChatMessageTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/create-chat-message.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("actor", "http://mastodon.example.org/users/admin")
|
||||
|> put_in(["object", "actor"], "http://mastodon.example.org/users/admin")
|
||||
|
||||
|
|
@ -127,7 +127,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ChatMessageTest do
|
|||
test "it doesn't work for deactivated users" do
|
||||
data =
|
||||
File.read!("test/fixtures/create-chat-message.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|
||||
_author =
|
||||
insert(:user,
|
||||
|
|
@ -145,7 +145,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ChatMessageTest do
|
|||
test "it inserts it and creates a chat" do
|
||||
data =
|
||||
File.read!("test/fixtures/create-chat-message.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|
||||
author =
|
||||
insert(:user, ap_id: data["actor"], local: false, last_refreshed_at: DateTime.utc_now())
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.DeleteHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-delete.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("actor", deleting_user.ap_id)
|
||||
|> put_in(["object", "id"], activity.data["object"])
|
||||
|
||||
|
|
@ -51,13 +51,14 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.DeleteHandlingTest do
|
|||
Object.normalize(activity.data["object"])
|
||||
|> Repo.delete()
|
||||
|
||||
# TODO: mock cachex
|
||||
Cachex.del(:object_cache, "object:#{object.data["id"]}")
|
||||
|
||||
deleting_user = insert(:user)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-delete.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("actor", deleting_user.ap_id)
|
||||
|> put_in(["object", "id"], activity.data["object"])
|
||||
|
||||
|
|
@ -78,7 +79,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.DeleteHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-delete.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("actor", ap_id)
|
||||
|> put_in(["object", "id"], activity.data["object"])
|
||||
|
||||
|
|
@ -91,7 +92,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.DeleteHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-delete-user.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|
||||
{:ok, _} = Transmogrifier.handle_incoming(data)
|
||||
ObanHelpers.perform_all()
|
||||
|
|
@ -104,7 +105,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.DeleteHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-delete-user.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("actor", ap_id)
|
||||
|
||||
assert match?({:error, _}, Transmogrifier.handle_incoming(data))
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.Transmogrifier.EmojiReactHandlingTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
|
|
@ -19,7 +19,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.EmojiReactHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/emoji-reaction.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|> Map.put("actor", other_user.ap_id)
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.EmojiReactHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/emoji-reaction-too-long.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|> Map.put("actor", other_user.ap_id)
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.EmojiReactHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/emoji-reaction-no-emoji.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|> Map.put("actor", other_user.ap_id)
|
||||
|
||||
|
|
|
|||
|
|
@ -13,13 +13,15 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.EventHandlingTest do
|
|||
%{url: "https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/mobilizon.org-event.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/mobilizon.org-event.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
|
||||
%{url: "https://mobilizon.org/@tcit"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/mobilizon.org-user.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/mobilizon.org-user.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
end)
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/osada-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
{:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
|
|
@ -47,7 +47,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
{:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
|
|
@ -69,7 +69,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
|
@ -100,7 +100,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
{:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
|
@ -116,7 +116,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("id", String.replace(data["id"], "2", "3"))
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
|
|
@ -142,7 +142,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
{:ok, %Activity{data: %{"id" => id}}} = Transmogrifier.handle_incoming(data)
|
||||
|
|
@ -157,7 +157,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
with_mock Pleroma.User, [:passthrough], follow: fn _, _, _ -> {:error, :testing} end do
|
||||
|
|
@ -174,7 +174,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/hubzilla-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|> Utils.normalize_params()
|
||||
|
||||
|
|
@ -192,7 +192,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.Transmogrifier.LikeHandlingTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
|
|
@ -18,7 +18,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.LikeHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-like.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|
||||
_actor = insert(:user, ap_id: data["actor"], local: false)
|
||||
|
|
@ -40,7 +40,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.LikeHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/misskey-like.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|
||||
_actor = insert(:user, ap_id: data["actor"], local: false)
|
||||
|
|
@ -61,7 +61,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.LikeHandlingTest do
|
|||
|
||||
data =
|
||||
File.read!("test/fixtures/misskey-like.json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|> Map.put("object", activity.data["object"])
|
||||
|> Map.put("_misskey_reaction", "⭐")
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue