Merge remote-tracking branch 'remotes/origin/develop' into ostatus-controller-no-auth-check-on-non-federating-instances

# Conflicts:
#	lib/pleroma/web/feed/user_controller.ex
#	lib/pleroma/web/o_status/o_status_controller.ex
#	lib/pleroma/web/router.ex
#	lib/pleroma/web/static_fe/static_fe_controller.ex
This commit is contained in:
Ivan Tashkinov 2020-10-17 13:12:39 +03:00
commit 049ece1ef3
677 changed files with 1669 additions and 800 deletions

View file

@ -0,0 +1,166 @@
# Pleroma: A lightweight social networking server
# Originally taken from
# https://github.com/VeryBigThings/elixir_common/blob/master/lib/vbt/credo/check/consistency/file_location.ex
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Credo.Check.Consistency.FileLocation do
@moduledoc false
# credo:disable-for-this-file Credo.Check.Readability.Specs
@checkdoc """
File location should follow the namespace hierarchy of the module it defines.
Examples:
- `lib/my_system.ex` should define the `MySystem` module
- `lib/my_system/accounts.ex` should define the `MySystem.Accounts` module
"""
@explanation [warning: @checkdoc]
@special_namespaces [
"controllers",
"views",
"operations",
"channels"
]
# `use Credo.Check` required that module attributes are already defined, so we need
# to place these attributes
# before use/alias expressions.
# credo:disable-for-next-line VBT.Credo.Check.Consistency.ModuleLayout
use Credo.Check, category: :warning, base_priority: :high
alias Credo.Code
def run(source_file, params \\ []) do
case verify(source_file, params) do
:ok ->
[]
{:error, module, expected_file} ->
error(IssueMeta.for(source_file, params), module, expected_file)
end
end
defp verify(source_file, params) do
source_file.filename
|> Path.relative_to_cwd()
|> verify(Code.ast(source_file), params)
end
@doc false
def verify(relative_path, ast, params) do
if verify_path?(relative_path, params),
do: ast |> main_module() |> verify_module(relative_path, params),
else: :ok
end
defp verify_path?(relative_path, params) do
case Path.split(relative_path) do
["lib" | _] -> not exclude?(relative_path, params)
["test", "support" | _] -> false
["test", "test_helper.exs"] -> false
["test" | _] -> not exclude?(relative_path, params)
_ -> false
end
end
defp exclude?(relative_path, params) do
params
|> Keyword.get(:exclude, [])
|> Enum.any?(&String.starts_with?(relative_path, &1))
end
defp main_module(ast) do
{_ast, modules} = Macro.prewalk(ast, [], &traverse/2)
Enum.at(modules, -1)
end
defp traverse({:defmodule, _meta, args}, modules) do
[{:__aliases__, _, name_parts}, _module_body] = args
{args, [Module.concat(name_parts) | modules]}
end
defp traverse(ast, state), do: {ast, state}
# empty file - shouldn't really happen, but we'll let it through
defp verify_module(nil, _relative_path, _params), do: :ok
defp verify_module(main_module, relative_path, params) do
parsed_path = parsed_path(relative_path, params)
expected_file =
expected_file_base(parsed_path.root, main_module) <>
Path.extname(parsed_path.allowed)
cond do
expected_file == parsed_path.allowed ->
:ok
special_namespaces?(parsed_path.allowed) ->
original_path = parsed_path.allowed
namespace =
Enum.find(@special_namespaces, original_path, fn namespace ->
String.contains?(original_path, namespace)
end)
allowed = String.replace(original_path, "/" <> namespace, "")
if expected_file == allowed,
do: :ok,
else: {:error, main_module, expected_file}
true ->
{:error, main_module, expected_file}
end
end
defp special_namespaces?(path), do: String.contains?(path, @special_namespaces)
defp parsed_path(relative_path, params) do
parts = Path.split(relative_path)
allowed =
Keyword.get(params, :ignore_folder_namespace, %{})
|> Stream.flat_map(fn {root, folders} -> Enum.map(folders, &Path.join([root, &1])) end)
|> Stream.map(&Path.split/1)
|> Enum.find(&List.starts_with?(parts, &1))
|> case do
nil ->
relative_path
ignore_parts ->
Stream.drop(ignore_parts, -1)
|> Enum.concat(Stream.drop(parts, length(ignore_parts)))
|> Path.join()
end
%{root: hd(parts), allowed: allowed}
end
defp expected_file_base(root_folder, module) do
{parent_namespace, module_name} = module |> Module.split() |> Enum.split(-1)
relative_path =
if parent_namespace == [],
do: "",
else: parent_namespace |> Module.concat() |> Macro.underscore()
file_name = module_name |> Module.concat() |> Macro.underscore()
Path.join([root_folder, relative_path, file_name])
end
defp error(issue_meta, module, expected_file) do
format_issue(issue_meta,
message:
"Mismatch between file name and main module #{inspect(module)}. " <>
"Expected file path to be #{expected_file}. " <>
"Either move the file or rename the module.",
line_no: 1
)
end
end

View file

@ -1,3 +1,7 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
use Mix.Config
config :pleroma, :first_setting, key: "value", key2: [Pleroma.Repo]

View file

@ -2,7 +2,7 @@
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule RuntimeModule do
defmodule Fixtures.Modules.RuntimeModule do
@moduledoc """
This is a dummy module to test custom runtime modules.
"""

View file

@ -1,3 +1,7 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.DigestTest do
use Pleroma.DataCase

View file

@ -1,3 +1,7 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.EmailTest do
use Pleroma.DataCase

View file

@ -1,3 +1,7 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.EmojiTest do
use ExUnit.Case, async: true

View file

@ -2,7 +2,7 @@
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.FrontendTest do
defmodule Mix.Tasks.Pleroma.FrontendTest do
use Pleroma.DataCase
alias Mix.Tasks.Pleroma.Frontend

View file

@ -2,9 +2,11 @@
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.InstanceTest do
defmodule Mix.Tasks.Pleroma.InstanceTest do
use ExUnit.Case
@release_env_file "./test/pleroma.test.env"
setup do
File.mkdir_p!(tmp_path())
@ -16,6 +18,8 @@ defmodule Pleroma.InstanceTest do
File.rm_rf(Path.join(static_dir, "robots.txt"))
end
if File.exists?(@release_env_file), do: File.rm_rf(@release_env_file)
Pleroma.Config.put([:instance, :static_dir], static_dir)
end)
@ -63,7 +67,15 @@ defmodule Pleroma.InstanceTest do
"--uploads-dir",
"test/uploads",
"--static-dir",
"./test/../test/instance/static/"
"./test/../test/instance/static/",
"--strip-uploads",
"y",
"--dedupe-uploads",
"n",
"--anonymize-uploads",
"n",
"--release-env-file",
@release_env_file
])
end
@ -82,8 +94,12 @@ defmodule Pleroma.InstanceTest do
assert generated_config =~ "password: \"dbpass\""
assert generated_config =~ "configurable_from_database: true"
assert generated_config =~ "http: [ip: {127, 0, 0, 1}, port: 4000]"
assert generated_config =~ "filters: [Pleroma.Upload.Filter.ExifTool]"
assert File.read!(tmp_path() <> "setup.psql") == generated_setup_psql()
assert File.exists?(Path.expand("./test/instance/static/robots.txt"))
assert File.exists?(@release_env_file)
assert File.read!(@release_env_file) =~ ~r/^RELEASE_COOKIE=.*/
end
defp generated_setup_psql do

View file

@ -0,0 +1,30 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.ReleaseEnvTest do
use ExUnit.Case
import ExUnit.CaptureIO, only: [capture_io: 1]
@path "config/pleroma.test.env"
def do_clean do
if File.exists?(@path) do
File.rm_rf(@path)
end
end
setup do
do_clean()
on_exit(fn -> do_clean() end)
:ok
end
test "generate pleroma.env" do
assert capture_io(fn ->
Mix.Tasks.Pleroma.ReleaseEnv.run(["gen", "--path", @path, "--force"])
end) =~ "The file generated"
assert File.read!(@path) =~ "RELEASE_COOKIE="
end
end

View file

@ -248,14 +248,19 @@ defmodule Mix.Tasks.Pleroma.UserTest do
user = User.get_cached_by_nickname(user.nickname)
assert user.is_moderator
assert user.locked
assert user.is_locked
assert user.is_admin
refute user.confirmation_pending
end
test "All statuses unset" do
user =
insert(:user, locked: true, is_moderator: true, is_admin: true, confirmation_pending: true)
insert(:user,
is_locked: true,
is_moderator: true,
is_admin: true,
confirmation_pending: true
)
Mix.Tasks.Pleroma.User.run([
"set",
@ -280,7 +285,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
user = User.get_cached_by_nickname(user.nickname)
refute user.is_moderator
refute user.locked
refute user.is_locked
refute user.is_admin
assert user.confirmation_pending
end

View file

@ -1,3 +1,7 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Activity.Ir.TopicsTest do
use Pleroma.DataCase

View file

@ -4,9 +4,12 @@
defmodule Pleroma.ApplicationRequirementsTest do
use Pleroma.DataCase
import ExUnit.CaptureLog
import Mock
alias Pleroma.ApplicationRequirements
alias Pleroma.Config
alias Pleroma.Repo
describe "check_welcome_message_config!/1" do
@ -70,42 +73,42 @@ defmodule Pleroma.ApplicationRequirementsTest do
setup do: clear_config([:database, :rum_enabled])
test "raises if rum is enabled and detects unapplied rum migrations" do
Pleroma.Config.put([:database, :rum_enabled], true)
Config.put([:database, :rum_enabled], true)
with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
assert_raise Pleroma.ApplicationRequirements.VerifyError,
assert_raise ApplicationRequirements.VerifyError,
"Unapplied RUM Migrations detected",
fn ->
capture_log(&Pleroma.ApplicationRequirements.verify!/0)
capture_log(&ApplicationRequirements.verify!/0)
end
end
end
test "raises if rum is disabled and detects rum migrations" do
Pleroma.Config.put([:database, :rum_enabled], false)
Config.put([:database, :rum_enabled], false)
with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
assert_raise Pleroma.ApplicationRequirements.VerifyError,
assert_raise ApplicationRequirements.VerifyError,
"RUM Migrations detected",
fn ->
capture_log(&Pleroma.ApplicationRequirements.verify!/0)
capture_log(&ApplicationRequirements.verify!/0)
end
end
end
test "doesn't do anything if rum enabled and applied migrations" do
Pleroma.Config.put([:database, :rum_enabled], true)
Config.put([:database, :rum_enabled], true)
with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> true end]}]) do
assert Pleroma.ApplicationRequirements.verify!() == :ok
assert ApplicationRequirements.verify!() == :ok
end
end
test "doesn't do anything if rum disabled" do
Pleroma.Config.put([:database, :rum_enabled], false)
Config.put([:database, :rum_enabled], false)
with_mocks([{Repo, [:passthrough], [exists?: fn _, _ -> false end]}]) do
assert Pleroma.ApplicationRequirements.verify!() == :ok
assert ApplicationRequirements.verify!() == :ok
end
end
end
@ -130,17 +133,17 @@ defmodule Pleroma.ApplicationRequirementsTest do
setup do: clear_config([:i_am_aware_this_may_cause_data_loss, :disable_migration_check])
test "raises if it detects unapplied migrations" do
assert_raise Pleroma.ApplicationRequirements.VerifyError,
assert_raise ApplicationRequirements.VerifyError,
"Unapplied Migrations detected",
fn ->
capture_log(&Pleroma.ApplicationRequirements.verify!/0)
capture_log(&ApplicationRequirements.verify!/0)
end
end
test "doesn't do anything if disabled" do
Pleroma.Config.put([:i_am_aware_this_may_cause_data_loss, :disable_migration_check], true)
Config.put([:i_am_aware_this_may_cause_data_loss, :disable_migration_check], true)
assert :ok == Pleroma.ApplicationRequirements.verify!()
assert :ok == ApplicationRequirements.verify!()
end
end
end

View file

@ -1,3 +1,7 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Config.DeprecationWarningsTest do
use ExUnit.Case
use Pleroma.Tests.Helpers
@ -83,7 +87,7 @@ defmodule Pleroma.Config.DeprecationWarningsTest do
end
test "check_activity_expiration_config/0" do
clear_config([Pleroma.ActivityExpiration, :enabled], true)
clear_config(Pleroma.ActivityExpiration, enabled: true)
assert capture_log(fn ->
DeprecationWarnings.check_activity_expiration_config()

View file

@ -1,3 +1,7 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Docs.GeneratorTest do
use ExUnit.Case, async: true
alias Pleroma.Docs.Generator

View file

@ -1,4 +1,8 @@
defmodule Pleroma.Web.ActivityPub.ObjectValidators.Types.DateTimeTest do
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.DateTimeTest do
alias Pleroma.EctoType.ActivityPub.ObjectValidators.DateTime
use Pleroma.DataCase

View file

@ -2,7 +2,7 @@
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ObjectValidators.Types.ObjectIDTest do
defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectIDTest do
alias Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectID
use Pleroma.DataCase

View file

@ -1,4 +1,8 @@
defmodule Pleroma.Web.ObjectValidators.Types.RecipientsTest do
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.RecipientsTest do
alias Pleroma.EctoType.ActivityPub.ObjectValidators.Recipients
use Pleroma.DataCase

View file

@ -2,7 +2,7 @@
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ObjectValidators.Types.SafeTextTest do
defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.SafeTextTest do
use Pleroma.DataCase
alias Pleroma.EctoType.ActivityPub.ObjectValidators.SafeText

View file

@ -1,3 +1,7 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.MFA.BackupCodesTest do
use Pleroma.DataCase

View file

@ -1,3 +1,7 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.MFA.TOTPTest do
use Pleroma.DataCase

View file

@ -346,7 +346,7 @@ defmodule Pleroma.NotificationTest do
describe "follow / follow_request notifications" do
test "it creates `follow` notification for approved Follow activity" do
user = insert(:user)
followed_user = insert(:user, locked: false)
followed_user = insert(:user, is_locked: false)
{:ok, _, _, _activity} = CommonAPI.follow(user, followed_user)
assert FollowingRelationship.following?(user, followed_user)
@ -361,7 +361,7 @@ defmodule Pleroma.NotificationTest do
test "it creates `follow_request` notification for pending Follow activity" do
user = insert(:user)
followed_user = insert(:user, locked: true)
followed_user = insert(:user, is_locked: true)
{:ok, _, _, _activity} = CommonAPI.follow(user, followed_user)
refute FollowingRelationship.following?(user, followed_user)
@ -383,7 +383,7 @@ defmodule Pleroma.NotificationTest do
test "it doesn't create a notification for follow-unfollow-follow chains" do
user = insert(:user)
followed_user = insert(:user, locked: false)
followed_user = insert(:user, is_locked: false)
{:ok, _, _, _activity} = CommonAPI.follow(user, followed_user)
assert FollowingRelationship.following?(user, followed_user)
@ -397,7 +397,7 @@ defmodule Pleroma.NotificationTest do
end
test "dismisses the notification on follow request rejection" do
user = insert(:user, locked: true)
user = insert(:user, is_locked: true)
follower = insert(:user)
{:ok, _, _, _follow_activity} = CommonAPI.follow(follower, user)
assert [notification] = Notification.for_user(user)

View file

@ -82,7 +82,7 @@ defmodule Pleroma.ObjectTest do
Pleroma.Config.put([:instance, :cleanup_attachments], false)
file = %Plug.Upload{
content_type: "image/jpg",
content_type: "image/jpeg",
path: Path.absname("test/fixtures/image.jpg"),
filename: "an_image.jpg"
}
@ -116,7 +116,7 @@ defmodule Pleroma.ObjectTest do
Pleroma.Config.put([:instance, :cleanup_attachments], true)
file = %Plug.Upload{
content_type: "image/jpg",
content_type: "image/jpeg",
path: Path.absname("test/fixtures/image.jpg"),
filename: "an_image.jpg"
}
@ -155,7 +155,7 @@ defmodule Pleroma.ObjectTest do
File.mkdir_p!(uploads_dir)
file = %Plug.Upload{
content_type: "image/jpg",
content_type: "image/jpeg",
path: Path.absname("test/fixtures/image.jpg"),
filename: "an_image.jpg"
}
@ -188,7 +188,7 @@ defmodule Pleroma.ObjectTest do
Pleroma.Config.put([:instance, :cleanup_attachments], true)
file = %Plug.Upload{
content_type: "image/jpg",
content_type: "image/jpeg",
path: Path.absname("test/fixtures/image.jpg"),
filename: "an_image.jpg"
}
@ -225,7 +225,7 @@ defmodule Pleroma.ObjectTest do
Pleroma.Config.put([:instance, :cleanup_attachments], true)
file = %Plug.Upload{
content_type: "image/jpg",
content_type: "image/jpeg",
path: Path.absname("test/fixtures/image.jpg"),
filename: "an_image.jpg"
}

View file

@ -1,3 +1,7 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Repo.Migrations.AutolinkerToLinkifyTest do
use Pleroma.DataCase
import Pleroma.Factory

View file

@ -1,3 +1,7 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Repo.Migrations.FixLegacyTagsTest do
alias Pleroma.User
use Pleroma.DataCase

View file

@ -1,3 +1,7 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Repo.Migrations.FixMalformedFormatterConfigTest do
use Pleroma.DataCase
import Pleroma.Factory

View file

@ -1,3 +1,7 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Repo.Migrations.MoveWelcomeSettingsTest do
use Pleroma.DataCase
import Pleroma.Factory

View file

@ -6,6 +6,7 @@ defmodule Pleroma.RuntimeTest do
use ExUnit.Case, async: true
test "it loads custom runtime modules" do
assert {:module, RuntimeModule} == Code.ensure_compiled(RuntimeModule)
assert {:module, Fixtures.Modules.RuntimeModule} ==
Code.ensure_compiled(Fixtures.Modules.RuntimeModule)
end
end

View file

@ -1,3 +1,7 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.SafeJsonbSetTest do
use Pleroma.DataCase

View file

@ -13,7 +13,7 @@ defmodule Pleroma.Upload.Filter.AnonymizeFilenameTest do
upload_file = %Upload{
name: "an… image.jpg",
content_type: "image/jpg",
content_type: "image/jpeg",
path: Path.absname("test/fixtures/image_tmp.jpg")
}

View file

@ -18,7 +18,7 @@ defmodule Pleroma.Upload.Filter.DedupeTest do
upload = %Upload{
name: "an… image.jpg",
content_type: "image/jpg",
content_type: "image/jpeg",
path: Path.absname("test/fixtures/image_tmp.jpg"),
tempfile: Path.absname("test/fixtures/image_tmp.jpg")
}

View file

@ -16,7 +16,7 @@ defmodule Pleroma.Upload.Filter.ExiftoolTest do
upload = %Pleroma.Upload{
name: "image_with_GPS_data.jpg",
content_type: "image/jpg",
content_type: "image/jpeg",
path: Path.absname("test/fixtures/DSCN0010.jpg"),
tempfile: Path.absname("test/fixtures/DSCN0010_tmp.jpg")
}

View file

@ -17,7 +17,7 @@ defmodule Pleroma.Upload.Filter.MogrifunTest do
upload = %Upload{
name: "an… image.jpg",
content_type: "image/jpg",
content_type: "image/jpeg",
path: Path.absname("test/fixtures/image_tmp.jpg"),
tempfile: Path.absname("test/fixtures/image_tmp.jpg")
}

Some files were not shown because too many files have changed in this diff Show more