Merge remote-tracking branch 'origin/develop' into webfinger-fix
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
commit
28e5e65676
365 changed files with 3208 additions and 872 deletions
BIN
test/fixtures/png_with_transparency.png
vendored
Normal file
BIN
test/fixtures/png_with_transparency.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 82 KiB |
|
|
@ -23,6 +23,11 @@ defmodule Mix.Tasks.Pleroma.DigestTest do
|
|||
|
||||
setup do: clear_config([Pleroma.Emails.Mailer, :enabled], true)
|
||||
|
||||
setup do
|
||||
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config)
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "pleroma.digest test" do
|
||||
test "Sends digest to the given user" do
|
||||
user1 = insert(:user)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ defmodule Mix.Tasks.Pleroma.Ecto.MigrateTest do
|
|||
|
||||
test "ecto.migrate info message" do
|
||||
level = Logger.level()
|
||||
Logger.configure(level: :warn)
|
||||
Logger.configure(level: :warning)
|
||||
|
||||
assert capture_log(fn ->
|
||||
Mix.Tasks.Pleroma.Ecto.Migrate.run()
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ defmodule Mix.Tasks.Pleroma.Ecto.RollbackTest do
|
|||
|
||||
test "ecto.rollback info message" do
|
||||
level = Logger.level()
|
||||
Logger.configure(level: :warn)
|
||||
Logger.configure(level: :warning)
|
||||
|
||||
assert capture_log(fn ->
|
||||
Mix.Tasks.Pleroma.Ecto.Rollback.run(["--env", "test"])
|
||||
|
|
|
|||
|
|
@ -20,6 +20,11 @@ defmodule Mix.Tasks.Pleroma.UserTest do
|
|||
import Mock
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do
|
||||
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config)
|
||||
:ok
|
||||
end
|
||||
|
||||
setup_all do
|
||||
Mix.shell(Mix.Shell.Process)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Activity.Ir.TopicsTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Activity.Ir.Topics
|
||||
|
|
|
|||
|
|
@ -145,7 +145,6 @@ defmodule Pleroma.ActivityTest do
|
|||
|
||||
setup do: clear_config([:instance, :limit_to_local_content])
|
||||
|
||||
@tag :skip_on_mac
|
||||
test "finds utf8 text in statuses", %{
|
||||
japanese_activity: japanese_activity,
|
||||
user: user
|
||||
|
|
|
|||
|
|
@ -443,13 +443,13 @@ defmodule Pleroma.ConfigDBTest do
|
|||
|
||||
test "common keyword" do
|
||||
assert ConfigDB.to_elixir_types([
|
||||
%{"tuple" => [":level", ":warn"]},
|
||||
%{"tuple" => [":level", ":warning"]},
|
||||
%{"tuple" => [":meta", [":all"]]},
|
||||
%{"tuple" => [":path", ""]},
|
||||
%{"tuple" => [":val", nil]},
|
||||
%{"tuple" => [":webhook_url", "https://hooks.slack.com/services/YOUR-KEY-HERE"]}
|
||||
]) == [
|
||||
level: :warn,
|
||||
level: :warning,
|
||||
meta: [:all],
|
||||
path: "",
|
||||
val: nil,
|
||||
|
|
|
|||
|
|
@ -13,6 +13,11 @@ defmodule Pleroma.ConversationTest do
|
|||
|
||||
setup_all do: clear_config([:instance, :federating], true)
|
||||
|
||||
setup do
|
||||
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "it goes through old direct conversations" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -9,17 +9,17 @@ defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.BareUriTest do
|
|||
|
||||
test "diaspora://" do
|
||||
text = "diaspora://alice@fediverse.example/post/deadbeefdeadbeefdeadbeefdeadbeef"
|
||||
assert {:ok, text} = BareUri.cast(text)
|
||||
assert {:ok, ^text} = BareUri.cast(text)
|
||||
end
|
||||
|
||||
test "nostr:" do
|
||||
text = "nostr:note1gwdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
|
||||
assert {:ok, text} = BareUri.cast(text)
|
||||
assert {:ok, ^text} = BareUri.cast(text)
|
||||
end
|
||||
|
||||
test "errors for non-URIs" do
|
||||
assert :error == SafeText.cast(1)
|
||||
assert :error == SafeText.cast("foo")
|
||||
assert :error == SafeText.cast("foo bar")
|
||||
assert :error == BareUri.cast(1)
|
||||
assert :error == BareUri.cast("foo")
|
||||
assert :error == BareUri.cast("foo bar")
|
||||
end
|
||||
end
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.HTTP.AdapterHelper.HackneyTest do
|
||||
use ExUnit.Case, async: true
|
||||
use ExUnit.Case
|
||||
use Pleroma.Tests.Helpers
|
||||
|
||||
alias Pleroma.HTTP.AdapterHelper.Hackney
|
||||
|
|
|
|||
45
test/pleroma/http/web_push_test.exs
Normal file
45
test/pleroma/http/web_push_test.exs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.HTTP.WebPushTest do
|
||||
use ExUnit.Case
|
||||
|
||||
import Tesla.Mock
|
||||
alias Pleroma.HTTP
|
||||
|
||||
@push_url "https://some-push-server/"
|
||||
|
||||
setup do
|
||||
mock(fn
|
||||
%{
|
||||
method: :post,
|
||||
url: @push_url,
|
||||
headers: headers
|
||||
} ->
|
||||
if {"content-type", "octet-stream"} in headers do
|
||||
%Tesla.Env{
|
||||
status: 200
|
||||
}
|
||||
else
|
||||
%Tesla.Env{
|
||||
status: 403
|
||||
}
|
||||
end
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
test "post" do
|
||||
response =
|
||||
HTTP.WebPush.post(
|
||||
@push_url,
|
||||
"encrypted payload",
|
||||
%{"authorization" => "WebPush"},
|
||||
[]
|
||||
)
|
||||
|
||||
assert {:ok, %{status: 200}} = response
|
||||
end
|
||||
end
|
||||
|
|
@ -31,14 +31,6 @@ defmodule Pleroma.Instances.InstanceTest do
|
|||
assert {:ok, instance} = Instance.set_reachable(instance.host)
|
||||
refute instance.unreachable_since
|
||||
end
|
||||
|
||||
test "does NOT create an Instance record in case of no existing matching record" do
|
||||
host = "domain.org"
|
||||
assert nil == Instance.set_reachable(host)
|
||||
|
||||
assert [] = Repo.all(Ecto.Query.from(i in Instance))
|
||||
assert Instance.reachable?(host)
|
||||
end
|
||||
end
|
||||
|
||||
describe "set_unreachable/1" do
|
||||
|
|
|
|||
|
|
@ -21,6 +21,11 @@ defmodule Pleroma.NotificationTest do
|
|||
alias Pleroma.Web.Push
|
||||
alias Pleroma.Web.Streamer
|
||||
|
||||
setup do
|
||||
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config)
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "create_notifications" do
|
||||
test "never returns nil" do
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.ObjectTest do
|
|||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
|
|
@ -15,10 +16,12 @@ defmodule Pleroma.ObjectTest do
|
|||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
ConfigMock |> stub_with(Pleroma.Test.StaticConfig)
|
||||
:ok
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -3,19 +3,23 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.ScheduledActivityTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.ScheduledActivity
|
||||
alias Pleroma.Test.StaticConfig
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do: clear_config([ScheduledActivity, :enabled])
|
||||
|
||||
setup [:ensure_local_uploader]
|
||||
|
||||
describe "creation" do
|
||||
test "scheduled activities with jobs when ScheduledActivity enabled" do
|
||||
clear_config([ScheduledActivity, :enabled], true)
|
||||
ConfigMock
|
||||
|> stub(:get, fn
|
||||
[ScheduledActivity, :enabled] -> true
|
||||
path -> StaticConfig.get(path)
|
||||
end)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
today =
|
||||
|
|
@ -34,7 +38,12 @@ defmodule Pleroma.ScheduledActivityTest do
|
|||
end
|
||||
|
||||
test "scheduled activities without jobs when ScheduledActivity disabled" do
|
||||
clear_config([ScheduledActivity, :enabled], false)
|
||||
ConfigMock
|
||||
|> stub(:get, fn
|
||||
[ScheduledActivity, :enabled] -> false
|
||||
path -> StaticConfig.get(path)
|
||||
end)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
today =
|
||||
|
|
@ -53,6 +62,9 @@ defmodule Pleroma.ScheduledActivityTest do
|
|||
end
|
||||
|
||||
test "when daily user limit is exceeded" do
|
||||
ConfigMock
|
||||
|> stub_with(StaticConfig)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
today =
|
||||
|
|
@ -69,6 +81,9 @@ defmodule Pleroma.ScheduledActivityTest do
|
|||
end
|
||||
|
||||
test "when total user limit is exceeded" do
|
||||
ConfigMock
|
||||
|> stub_with(StaticConfig)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
today =
|
||||
|
|
@ -89,6 +104,9 @@ defmodule Pleroma.ScheduledActivityTest do
|
|||
end
|
||||
|
||||
test "when scheduled_at is earlier than 5 minute from now" do
|
||||
ConfigMock
|
||||
|> stub_with(StaticConfig)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
scheduled_at =
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Activity.SearchTest do
|
||||
alias Pleroma.Activity.Search
|
||||
defmodule Pleroma.Search.DatabaseSearchTest do
|
||||
alias Pleroma.Search.DatabaseSearch, as: Search
|
||||
alias Pleroma.Web.CommonAPI
|
||||
import Pleroma.Factory
|
||||
|
||||
160
test/pleroma/search/meilisearch_test.exs
Normal file
160
test/pleroma/search/meilisearch_test.exs
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Search.MeilisearchTest do
|
||||
require Pleroma.Constants
|
||||
|
||||
use Pleroma.DataCase, async: true
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
import Mox
|
||||
|
||||
alias Pleroma.Search.Meilisearch
|
||||
alias Pleroma.UnstubbedConfigMock, as: Config
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Workers.SearchIndexingWorker
|
||||
|
||||
describe "meilisearch" do
|
||||
test "indexes a local post on creation" do
|
||||
user = insert(:user)
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{
|
||||
method: :put,
|
||||
url: "http://127.0.0.1:7700/indexes/objects/documents",
|
||||
body: body
|
||||
} ->
|
||||
assert match?(
|
||||
[%{"content" => "guys i just don't wanna leave the swamp"}],
|
||||
Jason.decode!(body)
|
||||
)
|
||||
|
||||
# To make sure that the worker is called
|
||||
send(self(), "posted_to_meilisearch")
|
||||
|
||||
%{
|
||||
"enqueuedAt" => "2023-11-12T12:36:46.927517Z",
|
||||
"indexUid" => "objects",
|
||||
"status" => "enqueued",
|
||||
"taskUid" => 6,
|
||||
"type" => "documentAdditionOrUpdate"
|
||||
}
|
||||
|> json()
|
||||
end)
|
||||
|
||||
Config
|
||||
|> expect(:get, 3, fn
|
||||
[Pleroma.Search, :module], nil ->
|
||||
Meilisearch
|
||||
|
||||
[Pleroma.Search.Meilisearch, :url], nil ->
|
||||
"http://127.0.0.1:7700"
|
||||
|
||||
[Pleroma.Search.Meilisearch, :private_key], nil ->
|
||||
"secret"
|
||||
end)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
status: "guys i just don't wanna leave the swamp",
|
||||
visibility: "public"
|
||||
})
|
||||
|
||||
args = %{"op" => "add_to_index", "activity" => activity.id}
|
||||
|
||||
assert_enqueued(
|
||||
worker: SearchIndexingWorker,
|
||||
args: args
|
||||
)
|
||||
|
||||
assert :ok = perform_job(SearchIndexingWorker, args)
|
||||
assert_received("posted_to_meilisearch")
|
||||
end
|
||||
|
||||
test "doesn't index posts that are not public" do
|
||||
user = insert(:user)
|
||||
|
||||
Enum.each(["private", "direct"], fn visibility ->
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
status: "guys i just don't wanna leave the swamp",
|
||||
visibility: visibility
|
||||
})
|
||||
|
||||
args = %{"op" => "add_to_index", "activity" => activity.id}
|
||||
|
||||
Config
|
||||
|> expect(:get, fn
|
||||
[Pleroma.Search, :module], nil ->
|
||||
Meilisearch
|
||||
end)
|
||||
|
||||
assert_enqueued(worker: SearchIndexingWorker, args: args)
|
||||
assert :ok = perform_job(SearchIndexingWorker, args)
|
||||
end)
|
||||
end
|
||||
|
||||
test "deletes posts from index when deleted locally" do
|
||||
user = insert(:user)
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{
|
||||
method: :put,
|
||||
url: "http://127.0.0.1:7700/indexes/objects/documents",
|
||||
body: body
|
||||
} ->
|
||||
assert match?(
|
||||
[%{"content" => "guys i just don't wanna leave the swamp"}],
|
||||
Jason.decode!(body)
|
||||
)
|
||||
|
||||
%{
|
||||
"enqueuedAt" => "2023-11-12T12:36:46.927517Z",
|
||||
"indexUid" => "objects",
|
||||
"status" => "enqueued",
|
||||
"taskUid" => 6,
|
||||
"type" => "documentAdditionOrUpdate"
|
||||
}
|
||||
|> json()
|
||||
|
||||
%{method: :delete, url: "http://127.0.0.1:7700/indexes/objects/documents/" <> id} ->
|
||||
send(self(), "called_delete")
|
||||
assert String.length(id) > 1
|
||||
json(%{})
|
||||
end)
|
||||
|
||||
Config
|
||||
|> expect(:get, 6, fn
|
||||
[Pleroma.Search, :module], nil ->
|
||||
Meilisearch
|
||||
|
||||
[Pleroma.Search.Meilisearch, :url], nil ->
|
||||
"http://127.0.0.1:7700"
|
||||
|
||||
[Pleroma.Search.Meilisearch, :private_key], nil ->
|
||||
"secret"
|
||||
end)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
status: "guys i just don't wanna leave the swamp",
|
||||
visibility: "public"
|
||||
})
|
||||
|
||||
args = %{"op" => "add_to_index", "activity" => activity.id}
|
||||
assert_enqueued(worker: SearchIndexingWorker, args: args)
|
||||
assert :ok = perform_job(SearchIndexingWorker, args)
|
||||
|
||||
{:ok, _} = CommonAPI.delete(activity.id, user)
|
||||
|
||||
delete_args = %{"op" => "remove_from_index", "object" => activity.object.id}
|
||||
assert_enqueued(worker: SearchIndexingWorker, args: delete_args)
|
||||
assert :ok = perform_job(SearchIndexingWorker, delete_args)
|
||||
|
||||
assert_received("called_delete")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -43,10 +43,7 @@ defmodule Pleroma.SignatureTest do
|
|||
end
|
||||
|
||||
test "it returns error when not found user" do
|
||||
assert capture_log(fn ->
|
||||
assert Signature.fetch_public_key(make_fake_conn("https://test-ap-id")) ==
|
||||
{:error, :error}
|
||||
end) =~ "[error] Could not decode user"
|
||||
assert Signature.fetch_public_key(make_fake_conn("https://test-ap-id")) == {:error, :error}
|
||||
end
|
||||
|
||||
test "it returns error if public key is nil" do
|
||||
|
|
|
|||
|
|
@ -20,6 +20,20 @@ defmodule Pleroma.Upload.Filter.AnalyzeMetadataTest do
|
|||
assert meta.blurhash
|
||||
end
|
||||
|
||||
test "it blurhashes images with an alpha component" do
|
||||
upload = %Pleroma.Upload{
|
||||
name: "an… image.jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/png_with_transparency.png"),
|
||||
tempfile: Path.absname("test/fixtures/png_with_transparency.png")
|
||||
}
|
||||
|
||||
{:ok, :filtered, meta} = AnalyzeMetadata.filter(upload)
|
||||
|
||||
assert %{width: 320, height: 320} = meta
|
||||
assert meta.blurhash == "eXJi-E:SwCEm5rCmn$+YWYn+15K#5A$xxCi{SiV]s*W:Efa#s.jE-T"
|
||||
end
|
||||
|
||||
test "adds the dimensions for videos" do
|
||||
upload = %Pleroma.Upload{
|
||||
name: "coolvideo.mp4",
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Upload.Filter.Exiftool.ReadDescriptionTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Upload.Filter
|
||||
|
||||
@uploads %Pleroma.Upload{
|
||||
|
|
|
|||
|
|
@ -6,10 +6,19 @@ defmodule Pleroma.UploadTest do
|
|||
use Pleroma.DataCase
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Mox
|
||||
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.Upload
|
||||
alias Pleroma.Uploaders.Uploader
|
||||
|
||||
setup do
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
@upload_file %Plug.Upload{
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image_tmp.jpg"),
|
||||
|
|
@ -236,6 +245,8 @@ defmodule Pleroma.UploadTest do
|
|||
describe "Setting a custom base_url for uploaded media" do
|
||||
setup do: clear_config([Pleroma.Upload, :base_url], "https://cache.pleroma.social")
|
||||
|
||||
# This seems to be backwards. Skipped for that reason
|
||||
@tag skip: true
|
||||
test "returns a media url with configured base_url" do
|
||||
base_url = Pleroma.Config.get([Pleroma.Upload, :base_url])
|
||||
|
||||
|
|
|
|||
|
|
@ -3,22 +3,27 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Uploaders.S3Test do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.Uploaders.S3
|
||||
alias Pleroma.Uploaders.S3.ExAwsMock
|
||||
|
||||
import Mock
|
||||
import Mox
|
||||
import ExUnit.CaptureLog
|
||||
|
||||
setup do
|
||||
clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3)
|
||||
clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")
|
||||
clear_config([Pleroma.Uploaders.S3])
|
||||
clear_config([Pleroma.Uploaders.S3, :bucket], "test_bucket")
|
||||
end
|
||||
|
||||
describe "get_file/1" do
|
||||
test "it returns path to local folder for files" do
|
||||
test "it returns url for files" do
|
||||
ConfigMock
|
||||
|> expect(:get, 6, fn key ->
|
||||
[
|
||||
{Pleroma.Upload,
|
||||
[uploader: Pleroma.Uploaders.S3, base_url: "https://s3.amazonaws.com"]},
|
||||
{Pleroma.Uploaders.S3, [bucket: "test_bucket"]}
|
||||
]
|
||||
|> get_in(key)
|
||||
end)
|
||||
|
||||
assert S3.get_file("test_image.jpg") == {
|
||||
:ok,
|
||||
{:url, "https://s3.amazonaws.com/test_bucket/test_image.jpg"}
|
||||
|
|
@ -26,13 +31,16 @@ defmodule Pleroma.Uploaders.S3Test do
|
|||
end
|
||||
|
||||
test "it returns path without bucket when truncated_namespace set to ''" do
|
||||
clear_config([Pleroma.Uploaders.S3],
|
||||
bucket: "test_bucket",
|
||||
bucket_namespace: "myaccount",
|
||||
truncated_namespace: ""
|
||||
)
|
||||
|
||||
clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")
|
||||
ConfigMock
|
||||
|> expect(:get, 6, fn key ->
|
||||
[
|
||||
{Pleroma.Upload,
|
||||
[uploader: Pleroma.Uploaders.S3, base_url: "https://s3.amazonaws.com"]},
|
||||
{Pleroma.Uploaders.S3,
|
||||
[bucket: "test_bucket", truncated_namespace: "", bucket_namespace: "myaccount"]}
|
||||
]
|
||||
|> get_in(key)
|
||||
end)
|
||||
|
||||
assert S3.get_file("test_image.jpg") == {
|
||||
:ok,
|
||||
|
|
@ -41,10 +49,15 @@ defmodule Pleroma.Uploaders.S3Test do
|
|||
end
|
||||
|
||||
test "it returns path with bucket namespace when namespace is set" do
|
||||
clear_config([Pleroma.Uploaders.S3],
|
||||
bucket: "test_bucket",
|
||||
bucket_namespace: "family"
|
||||
)
|
||||
ConfigMock
|
||||
|> expect(:get, 6, fn key ->
|
||||
[
|
||||
{Pleroma.Upload,
|
||||
[uploader: Pleroma.Uploaders.S3, base_url: "https://s3.amazonaws.com"]},
|
||||
{Pleroma.Uploaders.S3, [bucket: "test_bucket", bucket_namespace: "family"]}
|
||||
]
|
||||
|> get_in(key)
|
||||
end)
|
||||
|
||||
assert S3.get_file("test_image.jpg") == {
|
||||
:ok,
|
||||
|
|
@ -62,28 +75,42 @@ defmodule Pleroma.Uploaders.S3Test do
|
|||
tempfile: Path.absname("test/instance_static/add/shortcode.png")
|
||||
}
|
||||
|
||||
ConfigMock
|
||||
|> expect(:get, fn [Pleroma.Uploaders.S3] ->
|
||||
[
|
||||
bucket: "test_bucket"
|
||||
]
|
||||
end)
|
||||
|
||||
[file_upload: file_upload]
|
||||
end
|
||||
|
||||
test "save file", %{file_upload: file_upload} do
|
||||
with_mock ExAws, request: fn _ -> {:ok, :ok} end do
|
||||
assert S3.put_file(file_upload) == {:ok, {:file, "test_folder/image-tet.jpg"}}
|
||||
end
|
||||
ExAwsMock
|
||||
|> expect(:request, fn _req -> {:ok, %{status_code: 200}} end)
|
||||
|
||||
assert S3.put_file(file_upload) == {:ok, {:file, "test_folder/image-tet.jpg"}}
|
||||
end
|
||||
|
||||
test "returns error", %{file_upload: file_upload} do
|
||||
with_mock ExAws, request: fn _ -> {:error, "S3 Upload failed"} end do
|
||||
assert capture_log(fn ->
|
||||
assert S3.put_file(file_upload) == {:error, "S3 Upload failed"}
|
||||
end) =~ "Elixir.Pleroma.Uploaders.S3: {:error, \"S3 Upload failed\"}"
|
||||
end
|
||||
ExAwsMock
|
||||
|> expect(:request, fn _req -> {:error, "S3 Upload failed"} end)
|
||||
|
||||
assert capture_log(fn ->
|
||||
assert S3.put_file(file_upload) == {:error, "S3 Upload failed"}
|
||||
end) =~ "Elixir.Pleroma.Uploaders.S3: {:error, \"S3 Upload failed\"}"
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete_file/1" do
|
||||
test_with_mock "deletes file", ExAws, request: fn _req -> {:ok, %{status_code: 204}} end do
|
||||
test "deletes file" do
|
||||
ExAwsMock
|
||||
|> expect(:request, fn _req -> {:ok, %{status_code: 204}} end)
|
||||
|
||||
ConfigMock
|
||||
|> expect(:get, fn [Pleroma.Uploaders.S3, :bucket] -> "test_bucket" end)
|
||||
|
||||
assert :ok = S3.delete_file("image.jpg")
|
||||
assert_called(ExAws.request(:_))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
51
test/pleroma/user/backup_async_test.exs
Normal file
51
test/pleroma/user/backup_async_test.exs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.User.BackupAsyncTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
import Pleroma.Factory
|
||||
import Mox
|
||||
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.User.Backup
|
||||
alias Pleroma.User.Backup.ProcessorMock
|
||||
|
||||
setup do
|
||||
user = insert(:user, %{nickname: "cofe", name: "Cofe", ap_id: "http://cofe.io/users/cofe"})
|
||||
|
||||
{:ok, backup} = user |> Backup.new() |> Repo.insert()
|
||||
%{backup: backup}
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
test "it handles unrecoverable exceptions", %{backup: backup} do
|
||||
ProcessorMock
|
||||
|> expect(:do_process, fn _, _ ->
|
||||
raise "mock exception"
|
||||
end)
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Config)
|
||||
|
||||
{:error, %{backup: backup, reason: :exit}} = Backup.process(backup, ProcessorMock)
|
||||
|
||||
assert backup.state == :failed
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
test "it handles timeouts", %{backup: backup} do
|
||||
ProcessorMock
|
||||
|> expect(:do_process, fn _, _ ->
|
||||
Process.sleep(:timer.seconds(4))
|
||||
end)
|
||||
|
||||
ConfigMock
|
||||
|> expect(:get, fn [Pleroma.User.Backup, :process_wait_time] -> :timer.seconds(2) end)
|
||||
|
||||
{:error, %{backup: backup, reason: :timeout}} = Backup.process(backup, ProcessorMock)
|
||||
|
||||
assert backup.state == :failed
|
||||
end
|
||||
end
|
||||
|
|
@ -9,10 +9,14 @@ defmodule Pleroma.User.BackupTest do
|
|||
import Mock
|
||||
import Pleroma.Factory
|
||||
import Swoosh.TestAssertions
|
||||
import Mox
|
||||
|
||||
alias Pleroma.Bookmark
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.Uploaders.S3.ExAwsMock
|
||||
alias Pleroma.User.Backup
|
||||
alias Pleroma.User.Backup.ProcessorMock
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Workers.BackupWorker
|
||||
|
||||
|
|
@ -20,6 +24,14 @@ defmodule Pleroma.User.BackupTest do
|
|||
clear_config([Pleroma.Upload, :uploader])
|
||||
clear_config([Backup, :limit_days])
|
||||
clear_config([Pleroma.Emails.Mailer, :enabled], true)
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Config)
|
||||
|
||||
ProcessorMock
|
||||
|> stub_with(Pleroma.User.Backup.Processor)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
test "it does not requrie enabled email" do
|
||||
|
|
@ -302,24 +314,6 @@ defmodule Pleroma.User.BackupTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "it handles unrecoverable exceptions" do
|
||||
user = insert(:user, %{nickname: "cofe", name: "Cofe", ap_id: "http://cofe.io/users/cofe"})
|
||||
|
||||
assert {:ok, backup} = user |> Backup.new() |> Repo.insert()
|
||||
|
||||
with_mock Backup, [:passthrough], do_process: fn _, _ -> raise "mock exception" end do
|
||||
{:error, %{backup: backup, reason: :exit}} = Backup.process(backup)
|
||||
|
||||
assert backup.state == :failed
|
||||
end
|
||||
|
||||
with_mock Backup, [:passthrough], do_process: fn _, _ -> Process.sleep(:timer.seconds(32)) end do
|
||||
{:error, %{backup: backup, reason: :timeout}} = Backup.process(backup)
|
||||
|
||||
assert backup.state == :failed
|
||||
end
|
||||
end
|
||||
|
||||
describe "it uploads and deletes a backup archive" do
|
||||
setup do
|
||||
clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com")
|
||||
|
|
@ -345,14 +339,14 @@ defmodule Pleroma.User.BackupTest do
|
|||
clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3)
|
||||
clear_config([Pleroma.Uploaders.S3, :streaming_enabled], false)
|
||||
|
||||
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
|
||||
ExAwsMock
|
||||
|> expect(:request, 2, fn
|
||||
%{http_method: :put} -> {:ok, :ok}
|
||||
%{http_method: :delete} -> {:ok, %{status_code: 204}}
|
||||
end)
|
||||
|
||||
assert {:ok, %Pleroma.Upload{}} = Backup.upload(backup, path)
|
||||
assert {:ok, _backup} = Backup.delete(backup)
|
||||
end
|
||||
|
||||
test "Local", %{path: path, backup: backup} do
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ defmodule Pleroma.UserTest do
|
|||
import ExUnit.CaptureLog
|
||||
import Swoosh.TestAssertions
|
||||
|
||||
setup do
|
||||
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config)
|
||||
:ok
|
||||
end
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
|
@ -1946,8 +1951,8 @@ defmodule Pleroma.UserTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "get_public_key_for_ap_id fetches a user that's not in the db" do
|
||||
assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
|
||||
test "get_public_key_for_ap_id returns correctly for user that's not in the db" do
|
||||
assert :error = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
|
||||
end
|
||||
|
||||
describe "per-user rich-text filtering" do
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
require Pleroma.Constants
|
||||
|
||||
setup do
|
||||
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config)
|
||||
:ok
|
||||
end
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
|
@ -890,6 +895,23 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
assert Activity.get_by_ap_id(data["id"])
|
||||
end
|
||||
|
||||
test "it rejects an invalid incoming activity", %{conn: conn, data: data} do
|
||||
user = insert(:user, is_active: false)
|
||||
|
||||
data =
|
||||
data
|
||||
|> Map.put("bcc", [user.ap_id])
|
||||
|> Kernel.put_in(["object", "bcc"], [user.ap_id])
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:valid_signature, true)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{user.nickname}/inbox", data)
|
||||
|
||||
assert "Invalid request." == json_response(conn, 400)
|
||||
end
|
||||
|
||||
test "it accepts messages with to as string instead of array", %{conn: conn, data: data} do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
alias Pleroma.Config
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
|
|
@ -19,11 +20,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
|
||||
import ExUnit.CaptureLog
|
||||
import Mock
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
|
|
@ -770,6 +776,34 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert object.data["repliesCount"] == 2
|
||||
end
|
||||
|
||||
test "increates quotes count", %{user: user} do
|
||||
user2 = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "1", visibility: "public"})
|
||||
ap_id = activity.data["id"]
|
||||
quote_data = %{status: "1", quote_id: activity.id}
|
||||
|
||||
# public
|
||||
{:ok, _} = CommonAPI.post(user2, Map.put(quote_data, :visibility, "public"))
|
||||
assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert object.data["quotesCount"] == 1
|
||||
|
||||
# unlisted
|
||||
{:ok, _} = CommonAPI.post(user2, Map.put(quote_data, :visibility, "unlisted"))
|
||||
assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert object.data["quotesCount"] == 2
|
||||
|
||||
# private
|
||||
{:ok, _} = CommonAPI.post(user2, Map.put(quote_data, :visibility, "private"))
|
||||
assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert object.data["quotesCount"] == 2
|
||||
|
||||
# direct
|
||||
{:ok, _} = CommonAPI.post(user2, Map.put(quote_data, :visibility, "direct"))
|
||||
assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert object.data["quotesCount"] == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetch activities for recipients" do
|
||||
|
|
@ -2653,6 +2687,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert user.name == " "
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
test "pin_data_from_featured_collection will ignore unsupported values" do
|
||||
assert %{} ==
|
||||
ActivityPub.pin_data_from_featured_collection(%{
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.FollowBotPolicyTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.MRF.FollowBotPolicy
|
||||
|
|
|
|||
|
|
@ -7,10 +7,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do
|
|||
use Pleroma.Tests.Helpers
|
||||
|
||||
alias Pleroma.HTTP
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.Web.ActivityPub.MRF
|
||||
alias Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy
|
||||
|
||||
import Mock
|
||||
import Mox
|
||||
|
||||
@message %{
|
||||
"type" => "Create",
|
||||
|
|
@ -42,6 +44,13 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do
|
|||
}
|
||||
}
|
||||
|
||||
setup do
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
setup do: clear_config([:media_proxy, :enabled], true)
|
||||
|
||||
test "it prefetches media proxy URIs" do
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRFTest do
|
||||
use ExUnit.Case, async: true
|
||||
use ExUnit.Case
|
||||
use Pleroma.Tests.Helpers
|
||||
alias Pleroma.Web.ActivityPub.MRF
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,11 @@
|
|||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
|
||||
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "attachments" do
|
||||
|
|
@ -116,6 +118,9 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
|
|||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
{:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
|
||||
|
||||
{:ok, attachment} =
|
||||
|
|
|
|||
|
|
@ -5,11 +5,13 @@
|
|||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidator
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "chat message create activities" do
|
||||
|
|
@ -82,6 +84,9 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
|
|||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
{:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
|
||||
|
||||
valid_chat_message =
|
||||
|
|
@ -103,6 +108,9 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
|
|||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
{:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
|
||||
|
||||
valid_chat_message =
|
||||
|
|
@ -124,6 +132,9 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
|
|||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
{:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
|
||||
|
||||
valid_chat_message =
|
||||
|
|
|
|||
|
|
@ -331,11 +331,40 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
assert res == :ok
|
||||
|
||||
assert called(
|
||||
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
|
||||
inbox: "https://domain.com/users/nick1/inbox",
|
||||
actor_id: actor.id,
|
||||
id: note_activity.data["id"]
|
||||
})
|
||||
Pleroma.Web.Federator.Publisher.enqueue_one(
|
||||
Publisher,
|
||||
%{
|
||||
inbox: "https://domain.com/users/nick1/inbox",
|
||||
actor_id: actor.id,
|
||||
id: note_activity.data["id"]
|
||||
},
|
||||
priority: 1
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
test_with_mock "Publishes to directly addressed actors with higher priority.",
|
||||
Pleroma.Web.Federator.Publisher,
|
||||
[:passthrough],
|
||||
[] do
|
||||
note_activity = insert(:direct_note_activity)
|
||||
|
||||
actor = Pleroma.User.get_by_ap_id(note_activity.data["actor"])
|
||||
|
||||
res = Publisher.publish(actor, note_activity)
|
||||
|
||||
assert res == :ok
|
||||
|
||||
assert called(
|
||||
Pleroma.Web.Federator.Publisher.enqueue_one(
|
||||
Publisher,
|
||||
%{
|
||||
inbox: :_,
|
||||
actor_id: actor.id,
|
||||
id: note_activity.data["id"]
|
||||
},
|
||||
priority: 0
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
|
|
@ -414,19 +443,27 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
assert res == :ok
|
||||
|
||||
assert called(
|
||||
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
|
||||
inbox: "https://domain.com/users/nick1/inbox",
|
||||
actor_id: actor.id,
|
||||
id: delete.data["id"]
|
||||
})
|
||||
Pleroma.Web.Federator.Publisher.enqueue_one(
|
||||
Publisher,
|
||||
%{
|
||||
inbox: "https://domain.com/users/nick1/inbox",
|
||||
actor_id: actor.id,
|
||||
id: delete.data["id"]
|
||||
},
|
||||
priority: 1
|
||||
)
|
||||
)
|
||||
|
||||
assert called(
|
||||
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
|
||||
inbox: "https://domain2.com/users/nick1/inbox",
|
||||
actor_id: actor.id,
|
||||
id: delete.data["id"]
|
||||
})
|
||||
Pleroma.Web.Federator.Publisher.enqueue_one(
|
||||
Publisher,
|
||||
%{
|
||||
inbox: "https://domain2.com/users/nick1/inbox",
|
||||
actor_id: actor.id,
|
||||
id: delete.data["id"]
|
||||
},
|
||||
priority: 1
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -128,10 +128,11 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
message = File.read!("test/fixtures/fep-e232.json") |> Jason.decode!()
|
||||
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||
|
||||
object = Object.normalize(activity)
|
||||
assert [%{"type" => "Mention"}, %{"type" => "Link"}] = object.data["tag"]
|
||||
assert capture_log(fn ->
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||
object = Object.normalize(activity)
|
||||
assert [%{"type" => "Mention"}, %{"type" => "Link"}] = object.data["tag"]
|
||||
end) =~ "Error while fetching"
|
||||
end
|
||||
|
||||
test "it accepts quote posts" do
|
||||
|
|
|
|||
|
|
@ -16,6 +16,41 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
|
||||
require Pleroma.Constants
|
||||
|
||||
describe "strip_report_status_data/1" do
|
||||
test "does not break on issues with the reported activites" do
|
||||
reporter = insert(:user)
|
||||
target_account = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(target_account, %{status: "foobar"})
|
||||
context = Utils.generate_context_id()
|
||||
content = "foobar"
|
||||
post_id = activity.data["id"]
|
||||
|
||||
res =
|
||||
Utils.make_flag_data(
|
||||
%{
|
||||
actor: reporter,
|
||||
context: context,
|
||||
account: target_account,
|
||||
statuses: [%{"id" => post_id}],
|
||||
content: content
|
||||
},
|
||||
%{}
|
||||
)
|
||||
|
||||
res =
|
||||
res
|
||||
|> Map.put("object", res["object"] ++ [nil, 1, 5, "123"])
|
||||
|
||||
{:ok, activity} = Pleroma.Web.ActivityPub.ActivityPub.insert(res)
|
||||
|
||||
[user_id, object | _] = activity.data["object"]
|
||||
|
||||
{:ok, stripped} = Utils.strip_report_status_data(activity)
|
||||
|
||||
assert stripped.data["object"] == [user_id, object["id"]]
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetch the latest Follow" do
|
||||
test "fetches the latest Follow activity" do
|
||||
%Activity{data: %{"type" => "Follow"}} = activity = insert(:follow_activity)
|
||||
|
|
|
|||
|
|
@ -76,6 +76,15 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|||
assert %{"invisible" => true} = UserView.render("service.json", %{user: user})
|
||||
end
|
||||
|
||||
test "service has a few essential fields" do
|
||||
user = insert(:user)
|
||||
result = UserView.render("service.json", %{user: user})
|
||||
assert result["id"]
|
||||
assert result["type"] == "Application"
|
||||
assert result["inbox"]
|
||||
assert result["outbox"]
|
||||
end
|
||||
|
||||
test "renders AKAs" do
|
||||
akas = ["https://i.tusooa.xyz/users/test-pleroma"]
|
||||
user = insert(:user, also_known_as: akas)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
alias Pleroma.ModerationLog
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
|
|
@ -1077,6 +1078,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "/api/pleroma/backups" do
|
||||
test "it creates a backup", %{conn: conn} do
|
||||
ConfigMock
|
||||
|> Mox.stub_with(Pleroma.Config)
|
||||
|
||||
admin = %{id: admin_id, nickname: admin_nickname} = insert(:user, is_admin: true)
|
||||
token = insert(:oauth_admin_token, user: admin)
|
||||
user = %{id: user_id, nickname: user_nickname} = insert(:user)
|
||||
|
|
|
|||
|
|
@ -5,9 +5,11 @@
|
|||
defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import Pleroma.Factory
|
||||
import Mock
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.Web.MediaProxy
|
||||
|
||||
setup do: clear_config([:media_proxy])
|
||||
|
|
@ -128,6 +130,9 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
|
|||
"http://example.com/media/fb1f4d.jpg"
|
||||
]
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
with_mocks [
|
||||
{MediaProxy.Invalidation.Script, [],
|
||||
[
|
||||
|
|
@ -150,6 +155,9 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
|
|||
"http://example.com/media/fb1f4d.jpg"
|
||||
]
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
with_mocks [{MediaProxy.Invalidation.Script, [], [purge: fn _, _ -> {"ok", 0} end]}] do
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
|||
alias Pleroma.Web.Endpoint
|
||||
alias Pleroma.Web.MediaProxy
|
||||
|
||||
setup do
|
||||
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config)
|
||||
:ok
|
||||
end
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
alias Pleroma.Notification
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
|
|
@ -20,9 +21,10 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Workers.PollWorker
|
||||
|
||||
import Pleroma.Factory
|
||||
import Mock
|
||||
import Ecto.Query, only: [from: 2]
|
||||
import Mock
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
|
|
@ -31,6 +33,13 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
:ok
|
||||
end
|
||||
|
||||
setup do
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
setup do: clear_config([:instance, :safe_dm_mentions])
|
||||
setup do: clear_config([:instance, :limit])
|
||||
setup do: clear_config([:instance, :max_pinned_statuses])
|
||||
|
|
|
|||
|
|
@ -1,69 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Endpoint.MetricsExporterTest do
|
||||
# Modifies AppEnv, has to stay synchronous
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Web.Endpoint.MetricsExporter
|
||||
|
||||
defp config do
|
||||
Application.get_env(:prometheus, MetricsExporter)
|
||||
end
|
||||
|
||||
describe "with default config" do
|
||||
test "does NOT expose app metrics", %{conn: conn} do
|
||||
conn
|
||||
|> get(config()[:path])
|
||||
|> json_response(404)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when enabled" do
|
||||
setup do
|
||||
initial_config = config()
|
||||
on_exit(fn -> Application.put_env(:prometheus, MetricsExporter, initial_config) end)
|
||||
|
||||
Application.put_env(
|
||||
:prometheus,
|
||||
MetricsExporter,
|
||||
Keyword.put(initial_config, :enabled, true)
|
||||
)
|
||||
end
|
||||
|
||||
test "serves app metrics", %{conn: conn} do
|
||||
conn = get(conn, config()[:path])
|
||||
assert response = response(conn, 200)
|
||||
|
||||
for metric <- [
|
||||
"http_requests_total",
|
||||
"http_request_duration_microseconds",
|
||||
"phoenix_controller_call_duration",
|
||||
"telemetry_scrape_duration",
|
||||
"erlang_vm_memory_atom_bytes_total"
|
||||
] do
|
||||
assert response =~ ~r/#{metric}/
|
||||
end
|
||||
end
|
||||
|
||||
test "when IP whitelist configured, " <>
|
||||
"serves app metrics only if client IP is whitelisted",
|
||||
%{conn: conn} do
|
||||
Application.put_env(
|
||||
:prometheus,
|
||||
MetricsExporter,
|
||||
Keyword.put(config(), :ip_whitelist, ["127.127.127.127", {1, 1, 1, 1}, '255.255.255.255'])
|
||||
)
|
||||
|
||||
conn
|
||||
|> get(config()[:path])
|
||||
|> json_response(404)
|
||||
|
||||
conn
|
||||
|> Map.put(:remote_ip, {127, 127, 127, 127})
|
||||
|> get(config()[:path])
|
||||
|> response(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -6,20 +6,6 @@ defmodule Pleroma.Web.FallbackTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "neither preloaded data nor metadata attached to" do
|
||||
test "GET /registration/:token", %{conn: conn} do
|
||||
response = get(conn, "/registration/foo")
|
||||
|
||||
assert html_response(response, 200) =~ "<!--server-generated-meta-->"
|
||||
end
|
||||
|
||||
test "GET /*path", %{conn: conn} do
|
||||
assert conn
|
||||
|> get("/foo")
|
||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||
end
|
||||
end
|
||||
|
||||
test "GET /*path adds a title", %{conn: conn} do
|
||||
clear_config([:instance, :name], "a cool title")
|
||||
|
||||
|
|
@ -29,21 +15,28 @@ defmodule Pleroma.Web.FallbackTest do
|
|||
end
|
||||
|
||||
describe "preloaded data and metadata attached to" do
|
||||
test "GET /:maybe_nickname_or_id", %{conn: conn} do
|
||||
test "GET /:maybe_nickname_or_id with existing user", %{conn: conn} do
|
||||
clear_config([:instance, :name], "a cool title")
|
||||
user = insert(:user)
|
||||
|
||||
resp = get(conn, "/#{user.nickname}")
|
||||
|
||||
assert html_response(resp, 200) =~ "<title>a cool title</title>"
|
||||
refute html_response(resp, 200) =~ "<!--server-generated-meta-->"
|
||||
assert html_response(resp, 200) =~ "initial-results"
|
||||
end
|
||||
|
||||
test "GET /:maybe_nickname_or_id with missing user", %{conn: conn} do
|
||||
clear_config([:instance, :name], "a cool title")
|
||||
|
||||
user = insert(:user)
|
||||
user_missing = get(conn, "/foo")
|
||||
user_present = get(conn, "/#{user.nickname}")
|
||||
resp = get(conn, "/foo")
|
||||
|
||||
assert html_response(user_missing, 200) =~ "<!--server-generated-meta-->"
|
||||
refute html_response(user_present, 200) =~ "<!--server-generated-meta-->"
|
||||
assert html_response(user_present, 200) =~ "initial-results"
|
||||
assert html_response(user_present, 200) =~ "<title>a cool title</title>"
|
||||
assert html_response(resp, 200) =~ "<title>a cool title</title>"
|
||||
refute html_response(resp, 200) =~ "initial-results"
|
||||
end
|
||||
|
||||
test "GET /*path", %{conn: conn} do
|
||||
assert conn
|
||||
refute conn
|
||||
|> get("/foo")
|
||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||
|
||||
|
|
@ -65,10 +58,12 @@ defmodule Pleroma.Web.FallbackTest do
|
|||
end
|
||||
|
||||
test "GET /main/all", %{conn: conn} do
|
||||
clear_config([:instance, :name], "a cool title")
|
||||
public_page = get(conn, "/main/all")
|
||||
|
||||
refute html_response(public_page, 200) =~ "<!--server-generated-meta-->"
|
||||
assert html_response(public_page, 200) =~ "initial-results"
|
||||
assert html_response(public_page, 200) =~ "<title>a cool title</title>"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,11 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do
|
||||
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config)
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "account fetching" do
|
||||
test "works by id" do
|
||||
%User{id: user_id} = insert(:user)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.DirectoryControllerTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
use Pleroma.Web.ConnCase
|
||||
alias Pleroma.Web.CommonAPI
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
|
|||
|
|
@ -106,4 +106,11 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
|
|||
|> get("/api/v1/instance")
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "get instance information v2", %{conn: conn} do
|
||||
clear_config([:auth, :oauth_consumer_strategies], [])
|
||||
|
||||
assert get(conn, "/api/v2/instance")
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,8 +6,10 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Mox
|
||||
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
|
||||
|
|
@ -15,6 +17,9 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
|
|||
setup do: oauth_access(["write:media"])
|
||||
|
||||
setup do
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
image = %Plug.Upload{
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
|
|
@ -145,6 +150,9 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
|
|||
setup do: oauth_access(["write:media"])
|
||||
|
||||
setup %{user: actor} do
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
|
|
@ -177,6 +185,9 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
|
|||
setup do: oauth_access(["read:media"])
|
||||
|
||||
setup %{user: actor} do
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
|
|
|
|||
|
|
@ -12,6 +12,11 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do
|
||||
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "does NOT render account/pleroma/relationship by default" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:notifications"])
|
||||
other_user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -3,15 +3,25 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.ScheduledActivityControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.ScheduledActivity
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
|
||||
import Pleroma.Factory
|
||||
import Ecto.Query
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do: clear_config([ScheduledActivity, :enabled])
|
||||
setup do
|
||||
ConfigMock
|
||||
|> stub(:get, fn
|
||||
[ScheduledActivity, :enabled] -> true
|
||||
path -> Pleroma.Test.StaticConfig.get(path)
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
test "shows scheduled activities" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:statuses"])
|
||||
|
|
@ -55,7 +65,6 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityControllerTest do
|
|||
end
|
||||
|
||||
test "updates a scheduled activity" do
|
||||
clear_config([ScheduledActivity, :enabled], true)
|
||||
%{user: user, conn: conn} = oauth_access(["write:statuses"])
|
||||
|
||||
scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60)
|
||||
|
|
@ -103,7 +112,6 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityControllerTest do
|
|||
end
|
||||
|
||||
test "deletes a scheduled activity" do
|
||||
clear_config([ScheduledActivity, :enabled], true)
|
||||
%{user: user, conn: conn} = oauth_access(["write:statuses"])
|
||||
scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60)
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,11 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
import Tesla.Mock
|
||||
import Mock
|
||||
|
||||
setup do
|
||||
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config)
|
||||
:ok
|
||||
end
|
||||
|
||||
setup_all do
|
||||
mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
|
@ -37,7 +42,6 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
@tag :skip_on_mac
|
||||
test "search", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user_two = insert(:user, %{nickname: "shp@shitposter.club"})
|
||||
|
|
|
|||
|
|
@ -19,25 +19,38 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Workers.ScheduledActivityWorker
|
||||
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do: clear_config([:instance, :federating])
|
||||
setup do: clear_config([:instance, :allow_relay])
|
||||
setup do: clear_config([:rich_media, :enabled])
|
||||
setup do: clear_config([:mrf, :policies])
|
||||
setup do: clear_config([:mrf_keyword, :reject])
|
||||
|
||||
setup do
|
||||
Pleroma.UnstubbedConfigMock
|
||||
|> stub_with(Pleroma.Config)
|
||||
|
||||
Pleroma.StaticStubbedConfigMock
|
||||
|> stub(:get, fn
|
||||
[:rich_media, :enabled] -> false
|
||||
path -> Pleroma.Test.StaticConfig.get(path)
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "posting statuses" do
|
||||
setup do: oauth_access(["write:statuses"])
|
||||
|
||||
test "posting a status does not increment reblog_count when relaying", %{conn: conn} do
|
||||
clear_config([:instance, :federating], true)
|
||||
Config.get([:instance, :allow_relay], true)
|
||||
clear_config([:instance, :allow_relay], true)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("api/v1/statuses", %{
|
||||
|> post("/api/v1/statuses", %{
|
||||
"content_type" => "text/plain",
|
||||
"source" => "Pleroma FE",
|
||||
"status" => "Hello world",
|
||||
|
|
@ -50,7 +63,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
response =
|
||||
conn
|
||||
|> get("api/v1/statuses/#{response["id"]}", %{})
|
||||
|> get("/api/v1/statuses/#{response["id"]}", %{})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response["reblogs_count"] == 0
|
||||
|
|
@ -109,7 +122,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
conn_four =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("api/v1/statuses", %{
|
||||
|> post("/api/v1/statuses", %{
|
||||
"status" => "oolong",
|
||||
"expires_in" => expires_in
|
||||
})
|
||||
|
|
@ -156,7 +169,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert %{"error" => "Expiry date is too soon"} =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("api/v1/statuses", %{
|
||||
|> post("/api/v1/statuses", %{
|
||||
"status" => "oolong",
|
||||
"expires_in" => expires_in
|
||||
})
|
||||
|
|
@ -168,7 +181,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert %{"error" => "Expiry date is too soon"} =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("api/v1/statuses", %{
|
||||
|> post("/api/v1/statuses", %{
|
||||
"status" => "oolong",
|
||||
"expires_in" => expires_in
|
||||
})
|
||||
|
|
@ -182,7 +195,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert %{"error" => "[KeywordPolicy] Matches with rejected keyword"} =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("api/v1/statuses", %{"status" => "GNO/Linux"})
|
||||
|> post("/api/v1/statuses", %{"status" => "GNO/Linux"})
|
||||
|> json_response_and_validate_schema(422)
|
||||
end
|
||||
|
||||
|
|
@ -316,7 +329,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
end
|
||||
|
||||
test "fake statuses' preview card is not cached", %{conn: conn} do
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
Pleroma.StaticStubbedConfigMock
|
||||
|> stub(:get, fn
|
||||
[:rich_media, :enabled] -> true
|
||||
path -> Pleroma.Test.StaticConfig.get(path)
|
||||
end)
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{
|
||||
|
|
@ -353,7 +370,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
test "posting a status with OGP link preview", %{conn: conn} do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
|
||||
Pleroma.StaticStubbedConfigMock
|
||||
|> stub(:get, fn
|
||||
[:rich_media, :enabled] -> true
|
||||
path -> Pleroma.Test.StaticConfig.get(path)
|
||||
end)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -375,7 +397,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("api/v1/statuses", %{"status" => content, "visibility" => "direct"})
|
||||
|> post("/api/v1/statuses", %{"status" => content, "visibility" => "direct"})
|
||||
|
||||
assert %{"id" => id} = response = json_response_and_validate_schema(conn, 200)
|
||||
assert response["visibility"] == "direct"
|
||||
|
|
@ -412,7 +434,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> get("api/v1/statuses/#{activity}")
|
||||
|> get("/api/v1/statuses/#{activity}")
|
||||
|
||||
assert %{
|
||||
"content" => "cofe is my copilot",
|
||||
|
|
@ -441,7 +463,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> get("api/v1/statuses/#{activity}")
|
||||
|> get("/api/v1/statuses/#{activity}")
|
||||
|
||||
assert %{
|
||||
"content" => "club mate is my wingman",
|
||||
|
|
@ -1644,7 +1666,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert %{"id" => id} =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("api/v1/statuses", %{
|
||||
|> post("/api/v1/statuses", %{
|
||||
"status" => "oolong",
|
||||
"expires_in" => expires_in
|
||||
})
|
||||
|
|
@ -1684,7 +1706,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
describe "cards" do
|
||||
setup do
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
Pleroma.StaticStubbedConfigMock
|
||||
|> stub(:get, fn
|
||||
[:rich_media, :enabled] -> true
|
||||
path -> Pleroma.Test.StaticConfig.get(path)
|
||||
end)
|
||||
|
||||
oauth_access(["read:statuses"])
|
||||
end
|
||||
|
|
@ -1894,7 +1920,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
conn
|
||||
|> assign(:user, user3)
|
||||
|> assign(:token, insert(:oauth_token, user: user3, scopes: ["read:statuses"]))
|
||||
|> get("api/v1/timelines/home")
|
||||
|> get("/api/v1/timelines/home")
|
||||
|
||||
[reblogged_activity] = json_response_and_validate_schema(conn3, 200)
|
||||
|
||||
|
|
|
|||
|
|
@ -527,7 +527,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
|> assign(:token, insert(:oauth_token, user: user_two, scopes: ["read:statuses"]))
|
||||
|
||||
# Only direct should be visible here
|
||||
res_conn = get(conn_user_two, "api/v1/timelines/direct")
|
||||
res_conn = get(conn_user_two, "/api/v1/timelines/direct")
|
||||
|
||||
assert [status] = json_response_and_validate_schema(res_conn, :ok)
|
||||
|
||||
|
|
@ -539,14 +539,14 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
build_conn()
|
||||
|> assign(:user, user_one)
|
||||
|> assign(:token, insert(:oauth_token, user: user_one, scopes: ["read:statuses"]))
|
||||
|> get("api/v1/timelines/direct")
|
||||
|> get("/api/v1/timelines/direct")
|
||||
|
||||
[status] = json_response_and_validate_schema(res_conn, :ok)
|
||||
|
||||
assert %{"visibility" => "direct"} = status
|
||||
|
||||
# Both should be visible here
|
||||
res_conn = get(conn_user_two, "api/v1/timelines/home")
|
||||
res_conn = get(conn_user_two, "/api/v1/timelines/home")
|
||||
|
||||
[_s1, _s2] = json_response_and_validate_schema(res_conn, :ok)
|
||||
|
||||
|
|
@ -559,14 +559,14 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
})
|
||||
end)
|
||||
|
||||
res_conn = get(conn_user_two, "api/v1/timelines/direct")
|
||||
res_conn = get(conn_user_two, "/api/v1/timelines/direct")
|
||||
|
||||
statuses = json_response_and_validate_schema(res_conn, :ok)
|
||||
assert length(statuses) == 20
|
||||
|
||||
max_id = List.last(statuses)["id"]
|
||||
|
||||
res_conn = get(conn_user_two, "api/v1/timelines/direct?max_id=#{max_id}")
|
||||
res_conn = get(conn_user_two, "/api/v1/timelines/direct?max_id=#{max_id}")
|
||||
|
||||
assert [status] = json_response_and_validate_schema(res_conn, :ok)
|
||||
|
||||
|
|
@ -591,7 +591,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
visibility: "direct"
|
||||
})
|
||||
|
||||
res_conn = get(conn, "api/v1/timelines/direct")
|
||||
res_conn = get(conn, "/api/v1/timelines/direct")
|
||||
|
||||
[status] = json_response_and_validate_schema(res_conn, :ok)
|
||||
assert status["id"] == direct.id
|
||||
|
|
|
|||
|
|
@ -7,11 +7,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
|
|||
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.ScheduledActivity
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.MastodonAPI.MastodonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
import Mox
|
||||
|
||||
describe "follow/3" do
|
||||
test "returns error when followed user is deactivated" do
|
||||
|
|
@ -88,6 +90,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
|
|||
|
||||
describe "get_scheduled_activities/2" do
|
||||
test "returns user scheduled activities" do
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
today =
|
||||
|
|
|
|||
|
|
@ -4,13 +4,22 @@
|
|||
|
||||
defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.User
|
||||
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import Mock
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "updating credentials" do
|
||||
setup do: oauth_access(["write:accounts"])
|
||||
setup :request_content_type
|
||||
|
|
|
|||
|
|
@ -5,11 +5,13 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
||||
use Pleroma.DataCase, async: false
|
||||
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserRelationship
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
|
|
@ -35,7 +37,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
inserted_at: ~N[2017-08-15 15:47:06.597036],
|
||||
emoji: %{"karjalanpiirakka" => "/file.png"},
|
||||
raw_bio: "valid html. a\nb\nc\nd\nf '&<>\"",
|
||||
also_known_as: ["https://shitposter.zone/users/shp"]
|
||||
also_known_as: ["https://shitposter.zone/users/shp"],
|
||||
last_status_at: NaiveDateTime.utc_now()
|
||||
})
|
||||
|
||||
expected = %{
|
||||
|
|
@ -74,7 +77,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
fields: []
|
||||
},
|
||||
fqn: "shp@shitposter.club",
|
||||
last_status_at: nil,
|
||||
last_status_at: user.last_status_at |> NaiveDateTime.to_date() |> Date.to_iso8601(),
|
||||
pleroma: %{
|
||||
ap_id: user.ap_id,
|
||||
also_known_as: ["https://shitposter.zone/users/shp"],
|
||||
|
|
@ -752,6 +755,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
clear_config([:media_proxy, :enabled], true)
|
||||
clear_config([:media_preview_proxy, :enabled])
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
user =
|
||||
insert(:user,
|
||||
avatar: %{"url" => [%{"href" => "https://evil.website/avatar.png"}]},
|
||||
|
|
@ -759,7 +765,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
emoji: %{"joker_smile" => "https://evil.website/society.png"}
|
||||
)
|
||||
|
||||
with media_preview_enabled <- [false, true] do
|
||||
Enum.each([true, false], fn media_preview_enabled ->
|
||||
clear_config([:media_preview_proxy, :enabled], media_preview_enabled)
|
||||
|
||||
AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
|
|
@ -777,7 +783,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
true
|
||||
end)
|
||||
|> assert()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
test "renders mute expiration date" do
|
||||
|
|
|
|||
|
|
@ -22,6 +22,11 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
alias Pleroma.Web.PleromaAPI.Chat.MessageReferenceView
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do
|
||||
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config)
|
||||
:ok
|
||||
end
|
||||
|
||||
defp test_notifications_rendering(notifications, user, expected_result) do
|
||||
result = NotificationView.render("index.json", %{notifications: notifications, for: user})
|
||||
|
||||
|
|
|
|||
|
|
@ -4,12 +4,16 @@
|
|||
|
||||
defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.ScheduledActivity
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.CommonAPI.Utils
|
||||
alias Pleroma.Web.MastodonAPI.ScheduledActivityView
|
||||
alias Pleroma.Web.MastodonAPI.StatusView
|
||||
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
test "A scheduled activity with a media attachment" do
|
||||
|
|
@ -27,6 +31,9 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do
|
|||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
{:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
|
||||
|
||||
attrs = %{
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
alias Pleroma.HTML
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserRelationship
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
|
@ -19,9 +20,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
|
||||
require Bitwise
|
||||
|
||||
import Mox
|
||||
import OpenApiSpex.TestAssertions
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
import OpenApiSpex.TestAssertions
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
|
@ -198,6 +200,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
test "returns a temporary ap_id based user for activities missing db users" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -337,7 +340,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
thread_muted: false,
|
||||
emoji_reactions: [],
|
||||
parent_visible: false,
|
||||
pinned_at: nil
|
||||
pinned_at: nil,
|
||||
quotes_count: 0
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -778,6 +782,39 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
%{provider_name: "example.com"} =
|
||||
StatusView.render("card.json", %{page_url: page_url, rich_media: card})
|
||||
end
|
||||
|
||||
test "a rich media card has all media proxied" do
|
||||
clear_config([:media_proxy, :enabled], true)
|
||||
clear_config([:media_preview_proxy, :enabled])
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
page_url = "http://example.com"
|
||||
|
||||
card = %{
|
||||
url: page_url,
|
||||
site_name: "Example site name",
|
||||
title: "Example website",
|
||||
image: page_url <> "/example.jpg",
|
||||
audio: page_url <> "/example.ogg",
|
||||
video: page_url <> "/example.mp4",
|
||||
description: "Example description"
|
||||
}
|
||||
|
||||
strcard = for {k, v} <- card, into: %{}, do: {to_string(k), v}
|
||||
|
||||
%{
|
||||
provider_name: "example.com",
|
||||
image: image,
|
||||
pleroma: %{opengraph: og}
|
||||
} = StatusView.render("card.json", %{page_url: page_url, rich_media: strcard})
|
||||
|
||||
assert String.match?(image, ~r/\/proxy\//)
|
||||
assert String.match?(og["image"], ~r/\/proxy\//)
|
||||
assert String.match?(og["audio"], ~r/\/proxy\//)
|
||||
assert String.match?(og["video"], ~r/\/proxy\//)
|
||||
end
|
||||
end
|
||||
|
||||
test "does not embed a relationship in the account" do
|
||||
|
|
|
|||
|
|
@ -9,9 +9,17 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
|||
import Mox
|
||||
|
||||
alias Pleroma.ReverseProxy.ClientMock
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.Web.MediaProxy
|
||||
alias Plug.Conn
|
||||
|
||||
setup do
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "Media Proxy" do
|
||||
setup do
|
||||
clear_config([:media_proxy, :enabled], true)
|
||||
|
|
|
|||
|
|
@ -7,9 +7,19 @@ defmodule Pleroma.Web.MediaProxyTest do
|
|||
use Pleroma.Tests.Helpers
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.Web.Endpoint
|
||||
alias Pleroma.Web.MediaProxy
|
||||
|
||||
import Mox
|
||||
|
||||
setup do
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
defp decode_result(encoded) do
|
||||
{:ok, decoded} = MediaProxy.decode_url(encoded)
|
||||
decoded
|
||||
|
|
@ -222,7 +232,12 @@ defmodule Pleroma.Web.MediaProxyTest do
|
|||
|
||||
test "ensure Pleroma.Upload base_url is always whitelisted" do
|
||||
media_url = "https://media.pleroma.social"
|
||||
clear_config([Pleroma.Upload, :base_url], media_url)
|
||||
|
||||
ConfigMock
|
||||
|> stub(:get, fn
|
||||
[Pleroma.Upload, :base_url] -> media_url
|
||||
path -> Pleroma.Test.StaticConfig.get(path)
|
||||
end)
|
||||
|
||||
url = "#{media_url}/static/logo.png"
|
||||
encoded = MediaProxy.url(url)
|
||||
|
|
|
|||
|
|
@ -4,9 +4,19 @@
|
|||
|
||||
defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
|
||||
use Pleroma.DataCase
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.Web.Metadata.Providers.OpenGraph
|
||||
|
||||
setup do
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
|
||||
|
||||
test "it renders all supported types of attachments and skips unknown types" do
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
|
||||
assert html_response(conn, 302)
|
||||
assert redirected_to(conn) == app.redirect_uris
|
||||
assert get_flash(conn, :error) == "Failed to authenticate: (error description)."
|
||||
assert conn.assigns.flash["error"] == "Failed to authenticate: (error description)."
|
||||
end
|
||||
|
||||
test "GET /oauth/registration_details renders registration details form", %{
|
||||
|
|
@ -307,7 +307,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
|> post("/oauth/register", bad_params)
|
||||
|
||||
assert html_response(conn, 403) =~ ~r/name="op" type="submit" value="register"/
|
||||
assert get_flash(conn, :error) == "Error: #{bad_param} has already been taken."
|
||||
assert conn.assigns.flash["error"] == "Error: #{bad_param} has already been taken."
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -398,7 +398,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
|> post("/oauth/register", params)
|
||||
|
||||
assert html_response(conn, 401) =~ ~r/name="op" type="submit" value="connect"/
|
||||
assert get_flash(conn, :error) == "Invalid Username/Password"
|
||||
assert conn.assigns.flash["error"] == "Invalid Username/Password"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
|> get("/notice/#{like_activity.id}")
|
||||
|> response(200)
|
||||
|
||||
assert resp =~ "<!--server-generated-meta-->"
|
||||
refute resp =~ ~r(<meta content="[^"]*" property="og:url")
|
||||
end
|
||||
|
||||
test "404s a private notice", %{conn: conn} do
|
||||
|
|
|
|||
|
|
@ -5,12 +5,17 @@
|
|||
defmodule Pleroma.Web.PleromaAPI.BackupControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.User.Backup
|
||||
alias Pleroma.Web.PleromaAPI.BackupView
|
||||
|
||||
setup do
|
||||
clear_config([Pleroma.Upload, :uploader])
|
||||
clear_config([Backup, :limit_days])
|
||||
|
||||
ConfigMock
|
||||
|> Mox.stub_with(Pleroma.Config)
|
||||
|
||||
oauth_access(["read:backups"])
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,12 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
alias Pleroma.Chat
|
||||
alias Pleroma.Chat.MessageReference
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "POST /api/v1/pleroma/chats/:id/messages/:message_id/read" do
|
||||
|
|
@ -112,6 +114,9 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
{:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
|
||||
|
||||
other_user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,11 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do
|
||||
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "PUT /api/v1/pleroma/statuses/:id/reactions/:emoji", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ defmodule Pleroma.Web.PleromaApi.InstancesControllerTest do
|
|||
constant_unreachable: constant_unreachable,
|
||||
constant: constant
|
||||
} do
|
||||
clear_config([:instance, :public], false)
|
||||
|
||||
constant_host = URI.parse(constant).host
|
||||
|
||||
assert conn
|
||||
|
|
|
|||
|
|
@ -5,8 +5,11 @@
|
|||
defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.User
|
||||
|
||||
import Mox
|
||||
|
||||
test "mascot upload" do
|
||||
%{conn: conn} = oauth_access(["write:accounts"])
|
||||
|
||||
|
|
@ -29,6 +32,9 @@ defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
|
|||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|
|
@ -53,6 +59,9 @@ defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
|
|||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
ret_conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do
|
|||
"title" => "lain radio episode 1",
|
||||
"artist" => "lain",
|
||||
"album" => "lain radio",
|
||||
"length" => "180000"
|
||||
"length" => "180000",
|
||||
"externalLink" => "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+1"
|
||||
})
|
||||
|
||||
assert %{"title" => "lain radio episode 1"} = json_response_and_validate_schema(conn, 200)
|
||||
|
|
@ -33,21 +34,24 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do
|
|||
CommonAPI.listen(user, %{
|
||||
title: "lain radio episode 1",
|
||||
artist: "lain",
|
||||
album: "lain radio"
|
||||
album: "lain radio",
|
||||
externalLink: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+1"
|
||||
})
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.listen(user, %{
|
||||
title: "lain radio episode 2",
|
||||
artist: "lain",
|
||||
album: "lain radio"
|
||||
album: "lain radio",
|
||||
externalLink: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+2"
|
||||
})
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.listen(user, %{
|
||||
title: "lain radio episode 3",
|
||||
artist: "lain",
|
||||
album: "lain radio"
|
||||
album: "lain radio",
|
||||
externalLink: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+3"
|
||||
})
|
||||
|
||||
conn = get(conn, "/api/v1/pleroma/accounts/#{user.id}/scrobbles")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.PleromaAPI.StatusControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "getting quotes of a specified post" do
|
||||
setup do
|
||||
[current_user, user] = insert_pair(:user)
|
||||
%{user: current_user, conn: conn} = oauth_access(["read:statuses"], user: current_user)
|
||||
[current_user: current_user, user: user, conn: conn]
|
||||
end
|
||||
|
||||
test "shows quotes of a post", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
activity = insert(:note_activity)
|
||||
|
||||
{:ok, quote_post} = CommonAPI.post(user, %{status: "quoat", quote_id: activity.id})
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/statuses/#{activity.id}/quotes")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
[status] = response
|
||||
|
||||
assert length(response) == 1
|
||||
assert status["id"] == quote_post.id
|
||||
end
|
||||
|
||||
test "returns 404 error when a post can't be seen", %{conn: conn} do
|
||||
activity = insert(:direct_note_activity)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/statuses/#{activity.id}/quotes")
|
||||
|
||||
assert json_response_and_validate_schema(response, 404) == %{"error" => "Record not found"}
|
||||
end
|
||||
|
||||
test "returns 404 error when a post does not exist", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/statuses/idontexist/quotes")
|
||||
|
||||
assert json_response_and_validate_schema(response, 404) == %{"error" => "Record not found"}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -4,10 +4,21 @@
|
|||
|
||||
defmodule Pleroma.Web.PleromaAPI.BackupViewTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.User.Backup
|
||||
alias Pleroma.Web.PleromaAPI.BackupView
|
||||
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
test "it renders the ID" do
|
||||
user = insert(:user)
|
||||
backup = Backup.new(user)
|
||||
|
|
|
|||
|
|
@ -3,21 +3,28 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.PleromaAPI.ChatMessageReferenceViewTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.NullCache
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Chat
|
||||
alias Pleroma.Chat.MessageReference
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.StaticStubbedConfigMock
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.PleromaAPI.Chat.MessageReferenceView
|
||||
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
test "it displays a chat message" do
|
||||
user = insert(:user)
|
||||
recipient = insert(:user)
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
|
|
@ -35,6 +42,14 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageReferenceViewTest do
|
|||
|
||||
cm_ref = MessageReference.for_chat_and_object(chat, object)
|
||||
|
||||
id = cm_ref.id
|
||||
|
||||
Pleroma.CachexMock
|
||||
|> stub(:get, fn
|
||||
:chat_message_id_idempotency_key_cache, ^id -> {:ok, "123"}
|
||||
cache, key -> NullCache.get(cache, key)
|
||||
end)
|
||||
|
||||
chat_message = MessageReferenceView.render("show.json", chat_message_reference: cm_ref)
|
||||
|
||||
assert chat_message[:id] == cm_ref.id
|
||||
|
|
@ -46,7 +61,11 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageReferenceViewTest do
|
|||
assert match?([%{shortcode: "firefox"}], chat_message[:emojis])
|
||||
assert chat_message[:idempotency_key] == "123"
|
||||
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
StaticStubbedConfigMock
|
||||
|> stub(:get, fn
|
||||
[:rich_media, :enabled] -> true
|
||||
path -> Pleroma.Test.StaticConfig.get(path)
|
||||
end)
|
||||
|
||||
Tesla.Mock.mock_global(fn
|
||||
%{url: "https://example.com/ogp"} ->
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Plugs.EnsurePrivilegedPlugTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Web.Plugs.EnsurePrivilegedPlug
|
||||
import Pleroma.Factory
|
||||
|
|
|
|||
|
|
@ -4,7 +4,11 @@
|
|||
|
||||
defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import Mock
|
||||
import Mox
|
||||
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
|
||||
@dir "test/tmp/instance_static"
|
||||
|
||||
|
|
@ -66,6 +70,9 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
|||
File.mkdir_p!("#{path}/proxy/rr/ss")
|
||||
File.write!("#{path}/proxy/rr/ss/Ek7w8WPVcAApOvN.jpg:large", "FB image")
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
url =
|
||||
Pleroma.Web.MediaProxy.encode_url("https://pbs.twimg.com/media/Ek7w8WPVcAApOvN.jpg:large")
|
||||
|
||||
|
|
@ -82,6 +89,7 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
|||
"api",
|
||||
"main",
|
||||
"ostatus_subscribe",
|
||||
"authorize_interaction",
|
||||
"oauth",
|
||||
"objects",
|
||||
"activities",
|
||||
|
|
|
|||
|
|
@ -4,10 +4,18 @@
|
|||
|
||||
defmodule Pleroma.Web.Plugs.UploadedMediaPlugTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.Upload
|
||||
|
||||
import Mox
|
||||
|
||||
defp upload_file(context) do
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
Pleroma.DataCase.ensure_local_uploader(context)
|
||||
|
||||
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
|
||||
|
||||
file = %Plug.Upload{
|
||||
|
|
@ -23,6 +31,13 @@ defmodule Pleroma.Web.Plugs.UploadedMediaPlugTest do
|
|||
|
||||
setup_all :upload_file
|
||||
|
||||
setup do
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
test "does not send Content-Disposition header when name param is not set", %{
|
||||
attachment_url: attachment_url
|
||||
} do
|
||||
|
|
|
|||
|
|
@ -5,10 +5,12 @@
|
|||
defmodule Pleroma.Web.Push.ImplTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
|
@ -257,6 +259,9 @@ defmodule Pleroma.Web.Push.ImplTest do
|
|||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
{:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
|
||||
|
||||
{:ok, chat} = CommonAPI.post_chat_message(user, recipient, nil, media_id: upload.id)
|
||||
|
|
|
|||
|
|
@ -3,22 +3,31 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.RichMedia.HelpersTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.StaticStubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.RichMedia.Helpers
|
||||
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
ConfigMock
|
||||
|> stub(:get, fn
|
||||
[:rich_media, :enabled] -> false
|
||||
path -> Pleroma.Test.StaticConfig.get(path)
|
||||
end)
|
||||
|> stub(:get, fn
|
||||
path, default -> Pleroma.Test.StaticConfig.get(path, default)
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
setup do: clear_config([:rich_media, :enabled])
|
||||
|
||||
test "refuses to crawl incomplete URLs" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -28,7 +37,11 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
|
|||
content_type: "text/markdown"
|
||||
})
|
||||
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
ConfigMock
|
||||
|> stub(:get, fn
|
||||
[:rich_media, :enabled] -> true
|
||||
path -> Pleroma.Test.StaticConfig.get(path)
|
||||
end)
|
||||
|
||||
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
||||
end
|
||||
|
|
@ -42,7 +55,11 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
|
|||
content_type: "text/markdown"
|
||||
})
|
||||
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
ConfigMock
|
||||
|> stub(:get, fn
|
||||
[:rich_media, :enabled] -> true
|
||||
path -> Pleroma.Test.StaticConfig.get(path)
|
||||
end)
|
||||
|
||||
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
||||
end
|
||||
|
|
@ -56,12 +73,18 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
|
|||
content_type: "text/markdown"
|
||||
})
|
||||
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
ConfigMock
|
||||
|> stub(:get, fn
|
||||
[:rich_media, :enabled] -> true
|
||||
path -> Pleroma.Test.StaticConfig.get(path)
|
||||
end)
|
||||
|
||||
assert %{page_url: "https://example.com/ogp", rich_media: _} =
|
||||
Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
||||
end
|
||||
|
||||
# This does not seem to work. The urls are being fetched.
|
||||
@tag skip: true
|
||||
test "refuses to crawl URLs of private network from posts" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -73,7 +96,11 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
|
|||
{:ok, activity4} = CommonAPI.post(user, %{status: "https://192.168.10.40/notice/9kCP7V"})
|
||||
{:ok, activity5} = CommonAPI.post(user, %{status: "https://pleroma.local/notice/9kCP7V"})
|
||||
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
ConfigMock
|
||||
|> stub(:get, fn
|
||||
[:rich_media, :enabled] -> true
|
||||
path -> Pleroma.Test.StaticConfig.get(path)
|
||||
end)
|
||||
|
||||
assert %{} = Helpers.fetch_data_for_activity(activity)
|
||||
assert %{} = Helpers.fetch_data_for_activity(activity2)
|
||||
|
|
|
|||
|
|
@ -3,16 +3,18 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.MFA
|
||||
alias Pleroma.MFA.TOTP
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Pleroma.Factory
|
||||
import Ecto.Query
|
||||
import ExUnit.CaptureLog
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
setup_all do: clear_config([:instance, :federating], true)
|
||||
setup do: clear_config([:user, :deny_follow_blocked])
|
||||
|
|
@ -429,6 +431,9 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
|
|||
test "with media proxy" do
|
||||
clear_config([:media_proxy, :enabled], true)
|
||||
|
||||
ConfigMock
|
||||
|> stub_with(Pleroma.Test.StaticConfig)
|
||||
|
||||
user =
|
||||
insert(:user, %{
|
||||
local: false,
|
||||
|
|
@ -455,4 +460,38 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
|
|||
assert avatar_url == "#{Pleroma.Web.Endpoint.url()}/localuser/avatar.png"
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /authorize_interaction - authorize_interaction/2" do
|
||||
test "redirects to /ostatus_subscribe", %{conn: conn} do
|
||||
Tesla.Mock.mock(fn
|
||||
%{method: :get, url: "https://mastodon.social/users/emelie"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
headers: [{"content-type", "application/activity+json"}],
|
||||
body: File.read!("test/fixtures/tesla_mock/emelie.json")
|
||||
}
|
||||
|
||||
%{method: :get, url: "https://mastodon.social/users/emelie/collections/featured"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
headers: [{"content-type", "application/activity+json"}],
|
||||
body:
|
||||
File.read!("test/fixtures/users_mock/masto_featured.json")
|
||||
|> String.replace("{{domain}}", "mastodon.social")
|
||||
|> String.replace("{{nickname}}", "emelie")
|
||||
}
|
||||
end)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> get(
|
||||
remote_follow_path(conn, :authorize_interaction, %{
|
||||
uri: "https://mastodon.social/users/emelie"
|
||||
})
|
||||
)
|
||||
|
||||
assert redirected_to(conn) ==
|
||||
remote_follow_path(conn, :follow, %{acct: "https://mastodon.social/users/emelie"})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|> get("/api/pleroma/healthcheck")
|
||||
|> json_response_and_validate_schema(503)
|
||||
|
||||
assert response == %{}
|
||||
assert response == %{"error" => "Healthcheck disabled"}
|
||||
end
|
||||
|
||||
test "returns 200 when healthcheck enabled and all ok", %{conn: conn} do
|
||||
|
|
|
|||
|
|
@ -13,6 +13,11 @@ defmodule Pleroma.Workers.Cron.DigestEmailsWorkerTest do
|
|||
|
||||
setup do: clear_config([:email_notifications, :digest])
|
||||
|
||||
setup do
|
||||
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config)
|
||||
:ok
|
||||
end
|
||||
|
||||
setup do
|
||||
clear_config([:email_notifications, :digest], %{
|
||||
active: true,
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ defmodule Pleroma.Workers.Cron.NewUsersDigestWorkerTest do
|
|||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Workers.Cron.NewUsersDigestWorker
|
||||
|
||||
setup do
|
||||
Mox.stub_with(Pleroma.UnstubbedConfigMock, Pleroma.Config)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "it sends new users digest emails" do
|
||||
yesterday = NaiveDateTime.utc_now() |> Timex.shift(days: -1)
|
||||
admin = insert(:user, %{is_admin: true})
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Workers.PurgeExpiredTokenTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
use Pleroma.DataCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Workers.ReceiverWorkerTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
use Pleroma.DataCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
import Mock
|
||||
|
|
|
|||
|
|
@ -127,7 +127,10 @@ defmodule Pleroma.Cluster do
|
|||
|
||||
defp start_slave({node_host, override_configs}) do
|
||||
log(node_host, "booting federated VM")
|
||||
{:ok, node} = :slave.start(~c"127.0.0.1", node_name(node_host), vm_args())
|
||||
|
||||
{:ok, node} =
|
||||
do_start_slave(%{host: "127.0.0.1", name: node_name(node_host), args: vm_args()})
|
||||
|
||||
add_code_paths(node)
|
||||
load_apps_and_transfer_configuration(node, override_configs)
|
||||
ensure_apps_started(node)
|
||||
|
|
@ -219,4 +222,14 @@ defmodule Pleroma.Cluster do
|
|||
|> Enum.at(0)
|
||||
|> String.to_atom()
|
||||
end
|
||||
|
||||
defp do_start_slave(%{host: host, name: name, args: args} = opts) do
|
||||
peer_module = Application.get_env(__MODULE__, :peer_module)
|
||||
|
||||
if peer_module == :peer do
|
||||
peer_module.start(opts)
|
||||
else
|
||||
peer_module.start(host, name, args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ defmodule Pleroma.DataCase do
|
|||
Mox.stub_with(Pleroma.Web.ActivityPub.ActivityPubMock, Pleroma.Web.ActivityPub.ActivityPub)
|
||||
Mox.stub_with(Pleroma.Web.FederatorMock, Pleroma.Web.Federator)
|
||||
Mox.stub_with(Pleroma.ConfigMock, Pleroma.Config)
|
||||
Mox.stub_with(Pleroma.StaticStubbedConfigMock, Pleroma.Test.StaticConfig)
|
||||
end
|
||||
|
||||
def ensure_local_uploader(context) do
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ defmodule Pleroma.Factory do
|
|||
end
|
||||
|
||||
def direct_note_factory do
|
||||
user2 = insert(:user)
|
||||
user2 = insert(:user, local: false, inbox: "http://example.com/inbox")
|
||||
|
||||
%Pleroma.Object{data: data} = note_factory()
|
||||
%Pleroma.Object{data: Map.merge(data, %{"to" => [user2.ap_id]})}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ defmodule Pleroma.Tests.Helpers do
|
|||
# NOTE: `clear_config([section, key], value)` != `clear_config([section], key: value)` (!)
|
||||
# Displaying a warning to prevent unintentional clearing of all but one keys in section
|
||||
if Keyword.keyword?(temp_setting) and length(temp_setting) == 1 do
|
||||
Logger.warn(
|
||||
Logger.warning(
|
||||
"Please change `clear_config([section], key: value)` to `clear_config([section, key], value)`"
|
||||
)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ defmodule HttpRequestMock do
|
|||
else
|
||||
error ->
|
||||
with {:error, message} <- error do
|
||||
Logger.warn(to_string(message))
|
||||
Logger.warning(to_string(message))
|
||||
end
|
||||
|
||||
{_, _r} = error
|
||||
|
|
|
|||
|
|
@ -26,5 +26,11 @@ Mox.defmock(Pleroma.Web.ActivityPub.SideEffectsMock,
|
|||
Mox.defmock(Pleroma.Web.FederatorMock, for: Pleroma.Web.Federator.Publishing)
|
||||
|
||||
Mox.defmock(Pleroma.ConfigMock, for: Pleroma.Config.Getting)
|
||||
Mox.defmock(Pleroma.UnstubbedConfigMock, for: Pleroma.Config.Getting)
|
||||
Mox.defmock(Pleroma.StaticStubbedConfigMock, for: Pleroma.Config.Getting)
|
||||
|
||||
Mox.defmock(Pleroma.LoggerMock, for: Pleroma.Logging)
|
||||
|
||||
Mox.defmock(Pleroma.User.Backup.ProcessorMock, for: Pleroma.User.Backup.ProcessorAPI)
|
||||
|
||||
Mox.defmock(Pleroma.Uploaders.S3.ExAwsMock, for: Pleroma.Uploaders.S3.ExAwsAPI)
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
Code.put_compiler_option(:warnings_as_errors, true)
|
||||
|
||||
os_exclude = if :os.type() == {:unix, :darwin}, do: [skip_on_mac: true], else: []
|
||||
ExUnit.start(exclude: [:federated, :erratic] ++ os_exclude)
|
||||
ExUnit.start(exclude: [:federated, :erratic])
|
||||
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, :manual)
|
||||
|
||||
|
|
@ -18,3 +17,16 @@ ExUnit.after_suite(fn _results ->
|
|||
uploads = Pleroma.Config.get([Pleroma.Uploaders.Local, :uploads], "test/uploads")
|
||||
File.rm_rf!(uploads)
|
||||
end)
|
||||
|
||||
defmodule Pleroma.Test.StaticConfig do
|
||||
@moduledoc """
|
||||
This module provides a Config that is completely static, built at startup time from the environment. It's safe to use in testing as it will not modify any state.
|
||||
"""
|
||||
|
||||
@behaviour Pleroma.Config.Getting
|
||||
@config Application.get_all_env(:pleroma)
|
||||
|
||||
def get(path, default \\ nil) do
|
||||
get_in(@config, path) || default
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue