Merge remote-tracking branch 'origin/develop' into link-verification
This commit is contained in:
commit
b7c625db0f
609 changed files with 6056 additions and 2607 deletions
1
test/fixtures/ccworld-ap-bridge_note.json
vendored
Normal file
1
test/fixtures/ccworld-ap-bridge_note.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"@context":"https://www.w3.org/ns/activitystreams","type":"Note","id":"https://cc.mkdir.uk/ap/note/e5d1d0a1-1ab3-4498-9949-588e3fdea286","attributedTo":"https://cc.mkdir.uk/ap/acct/hiira","inReplyTo":"","quoteUrl":"","content":"おはコンー","published":"2024-01-19T22:08:05Z","to":["https://www.w3.org/ns/activitystreams#Public"],"tag":null,"attachment":[],"object":null}
|
||||
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 |
12
test/fixtures/rich_media/google.html
vendored
Normal file
12
test/fixtures/rich_media/google.html
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<meta property="og:url" content="https://google.com">
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:title" content="Google">
|
||||
<meta property="og:description" content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.">
|
||||
<meta property="og:image" content="">
|
||||
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta property="twitter:domain" content="google.com">
|
||||
<meta property="twitter:url" content="https://google.com">
|
||||
<meta name="twitter:title" content="Google">
|
||||
<meta name="twitter:description" content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.">
|
||||
<meta name="twitter:image" content="">
|
||||
2
test/fixtures/rich_media/oembed.html
vendored
2
test/fixtures/rich_media/oembed.html
vendored
|
|
@ -1,3 +1,3 @@
|
|||
<link rel="alternate" type="application/json+oembed"
|
||||
href="http://example.com/oembed.json"
|
||||
href="https://example.com/oembed.json"
|
||||
title="Bacon Lollys oEmbed Profile" />
|
||||
|
|
|
|||
12
test/fixtures/rich_media/yahoo.html
vendored
Normal file
12
test/fixtures/rich_media/yahoo.html
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<meta property="og:url" content="https://yahoo.com">
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:title" content="Yahoo | Mail, Weather, Search, Politics, News, Finance, Sports & Videos">
|
||||
<meta property="og:description" content="Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!">
|
||||
<meta property="og:image" content="https://s.yimg.com/cv/apiv2/social/images/yahoo_default_logo.png">
|
||||
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta property="twitter:domain" content="yahoo.com">
|
||||
<meta property="twitter:url" content="https://yahoo.com">
|
||||
<meta name="twitter:title" content="Yahoo | Mail, Weather, Search, Politics, News, Finance, Sports & Videos">
|
||||
<meta name="twitter:description" content="Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!">
|
||||
<meta name="twitter:image" content="https://s.yimg.com/cv/apiv2/social/images/yahoo_default_logo.png">
|
||||
|
|
@ -39,7 +39,7 @@ defmodule Mix.PleromaTest do
|
|||
|
||||
describe "get_option/3" do
|
||||
test "get from options" do
|
||||
assert get_option([domain: "some-domain.com"], :domain, "Promt") == "some-domain.com"
|
||||
assert get_option([domain: "some-domain.com"], :domain, "Prompt") == "some-domain.com"
|
||||
end
|
||||
|
||||
test "get from prompt" do
|
||||
|
|
|
|||
|
|
@ -140,7 +140,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
federating: true,
|
||||
federation_incoming_replies_max_depth: 100,
|
||||
federation_reachability_timeout_days: 7,
|
||||
federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],
|
||||
allow_relay: true,
|
||||
public: true,
|
||||
quarantined_instances: [],
|
||||
|
|
@ -183,8 +182,8 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
assert File.exists?(temp_file)
|
||||
{:ok, file} = File.read(temp_file)
|
||||
|
||||
assert file ==
|
||||
"import Config\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n attachment_links: false,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n"
|
||||
assert file =~ "import Config\n"
|
||||
assert file =~ "A Pleroma instance, an alternative fediverse server"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -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,11 +9,11 @@ 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"])
|
||||
end) =~ "[info] Rollback succesfully"
|
||||
end) =~ "[info] Rollback successfully"
|
||||
|
||||
Logger.configure(level: level)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
|
|||
assert file == "User-Agent: *\nDisallow: /\n"
|
||||
end
|
||||
|
||||
test "to existance folder" do
|
||||
test "to existing folder" do
|
||||
path = "test/fixtures/"
|
||||
file_path = path <> "robots.txt"
|
||||
clear_config([:instance, :static_dir], path)
|
||||
|
|
|
|||
|
|
@ -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,7 @@ defmodule Pleroma.ActivityTest do
|
|||
|
||||
setup do: clear_config([:instance, :limit_to_local_content])
|
||||
|
||||
@tag :skip_on_mac
|
||||
@tag :skip_darwin
|
||||
test "finds utf8 text in statuses", %{
|
||||
japanese_activity: japanese_activity,
|
||||
user: user
|
||||
|
|
|
|||
|
|
@ -125,13 +125,12 @@ defmodule Pleroma.Config.DeprecationWarningsTest do
|
|||
media_removal: ["some.removal", {"some.other.instance", "Some reason"}]
|
||||
)
|
||||
|
||||
expected_config = [
|
||||
expected_config =
|
||||
{:media_removal, [{"some.removal", ""}, {"some.other.instance", "Some reason"}]}
|
||||
]
|
||||
|
||||
capture_log(fn -> DeprecationWarnings.warn() end)
|
||||
|
||||
assert Config.get([:mrf_simple]) == expected_config
|
||||
assert expected_config in Config.get([:mrf_simple])
|
||||
end
|
||||
|
||||
test "doesn't give a warning with correct config" do
|
||||
|
|
@ -215,7 +214,7 @@ defmodule Pleroma.Config.DeprecationWarningsTest do
|
|||
|
||||
```
|
||||
config :pleroma, :mrf,
|
||||
transparency_exclusions: [{"instance.tld", "Reason to exlude transparency"}]
|
||||
transparency_exclusions: [{"instance.tld", "Reason to exclude transparency"}]
|
||||
```
|
||||
"""
|
||||
end
|
||||
|
|
@ -327,11 +326,11 @@ defmodule Pleroma.Config.DeprecationWarningsTest do
|
|||
end) =~ "Your config is using old namespace for activity expiration configuration."
|
||||
end
|
||||
|
||||
test "check_uploders_s3_public_endpoint/0" do
|
||||
test "check_uploaders_s3_public_endpoint/0" do
|
||||
clear_config([Pleroma.Uploaders.S3], public_endpoint: "https://fake.amazonaws.com/bucket/")
|
||||
|
||||
assert capture_log(fn ->
|
||||
DeprecationWarnings.check_uploders_s3_public_endpoint()
|
||||
DeprecationWarnings.check_uploaders_s3_public_endpoint()
|
||||
end) =~
|
||||
"Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket."
|
||||
end
|
||||
|
|
|
|||
|
|
@ -321,7 +321,7 @@ defmodule Pleroma.ConfigDBTest do
|
|||
}) == {:proxy_url, {:socks5, {127, 0, 0, 1}, 1234}}
|
||||
end
|
||||
|
||||
test "tuple with n childs" do
|
||||
test "tuple with n children" do
|
||||
assert ConfigDB.to_elixir_types(%{
|
||||
"tuple" => [
|
||||
"v1",
|
||||
|
|
@ -399,7 +399,7 @@ defmodule Pleroma.ConfigDBTest do
|
|||
assert ConfigDB.to_elixir_types(a: 1, b: 2, c: "string") == [a: 1, b: 2, c: "string"]
|
||||
end
|
||||
|
||||
test "complex keyword with nested mixed childs" do
|
||||
test "complex keyword with nested mixed children" do
|
||||
assert ConfigDB.to_elixir_types([
|
||||
%{"tuple" => [":uploader", "Pleroma.Uploaders.Local"]},
|
||||
%{"tuple" => [":filters", ["Pleroma.Upload.Filter.Dedupe"]]},
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
assert Participation.unread_count(other_user) == 0
|
||||
end
|
||||
|
||||
test "for a new conversation, it sets the recipents of the participation" do
|
||||
test "for a new conversation, it sets the recipients of the participation" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
third_user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -72,7 +72,7 @@ defmodule Pleroma.Emoji.LoaderTest do
|
|||
assert group == "special file"
|
||||
end
|
||||
|
||||
test "no mathing returns nil", %{groups: groups} do
|
||||
test "no matching returns nil", %{groups: groups} do
|
||||
group =
|
||||
groups
|
||||
|> Loader.match_extra("/emoji/some_undefined.png")
|
||||
|
|
|
|||
|
|
@ -6,26 +6,26 @@ defmodule Pleroma.EmojiTest do
|
|||
use ExUnit.Case, async: true
|
||||
alias Pleroma.Emoji
|
||||
|
||||
describe "is_unicode_emoji?/1" do
|
||||
describe "unicode?/1" do
|
||||
test "tells if a string is an unicode emoji" do
|
||||
refute Emoji.is_unicode_emoji?("X")
|
||||
refute Emoji.is_unicode_emoji?("ね")
|
||||
refute Emoji.unicode?("X")
|
||||
refute Emoji.unicode?("ね")
|
||||
|
||||
# Only accept fully-qualified (RGI) emoji
|
||||
# See http://www.unicode.org/reports/tr51/
|
||||
refute Emoji.is_unicode_emoji?("❤")
|
||||
refute Emoji.is_unicode_emoji?("☂")
|
||||
refute Emoji.unicode?("❤")
|
||||
refute Emoji.unicode?("☂")
|
||||
|
||||
assert Emoji.is_unicode_emoji?("🥺")
|
||||
assert Emoji.is_unicode_emoji?("🤰")
|
||||
assert Emoji.is_unicode_emoji?("❤️")
|
||||
assert Emoji.is_unicode_emoji?("🏳️⚧️")
|
||||
assert Emoji.is_unicode_emoji?("🫵")
|
||||
assert Emoji.unicode?("🥺")
|
||||
assert Emoji.unicode?("🤰")
|
||||
assert Emoji.unicode?("❤️")
|
||||
assert Emoji.unicode?("🏳️⚧️")
|
||||
assert Emoji.unicode?("🫵")
|
||||
|
||||
# Additionally, we accept regional indicators.
|
||||
assert Emoji.is_unicode_emoji?("🇵")
|
||||
assert Emoji.is_unicode_emoji?("🇴")
|
||||
assert Emoji.is_unicode_emoji?("🇬")
|
||||
assert Emoji.unicode?("🇵")
|
||||
assert Emoji.unicode?("🇴")
|
||||
assert Emoji.unicode?("🇬")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -324,7 +324,7 @@ defmodule Pleroma.FormatterTest do
|
|||
assert {_text, [], ^expected_tags} = Formatter.linkify(text)
|
||||
end
|
||||
|
||||
test "parses mulitple tags in html" do
|
||||
test "parses multiple tags in html" do
|
||||
text = "<p>#tag1 #tag2 #tag3 #tag4</p>"
|
||||
|
||||
expected_tags = [
|
||||
|
|
@ -347,7 +347,7 @@ defmodule Pleroma.FormatterTest do
|
|||
assert {_text, [], ^expected_tags} = Formatter.linkify(text)
|
||||
end
|
||||
|
||||
test "parses mulitple tags on mulitple lines in html" do
|
||||
test "parses multiple tags on multiple lines in html" do
|
||||
text =
|
||||
"<p>testing...</p><p>#tag1 #tag2 #tag3 #tag4</p><p>paragraph</p><p>#tag5 #tag6 #tag7 #tag8</p>"
|
||||
|
||||
|
|
|
|||
|
|
@ -9,14 +9,16 @@ defmodule Pleroma.HealthcheckTest do
|
|||
test "system_info/0" do
|
||||
result = Healthcheck.system_info() |> Map.from_struct()
|
||||
|
||||
assert Map.keys(result) == [
|
||||
keys = Map.keys(result)
|
||||
|
||||
assert Keyword.equal?(keys, [
|
||||
:active,
|
||||
:healthy,
|
||||
:idle,
|
||||
:job_queue_stats,
|
||||
:memory_used,
|
||||
:pool_size
|
||||
]
|
||||
])
|
||||
end
|
||||
|
||||
describe "check_health/1" do
|
||||
|
|
@ -25,7 +27,7 @@ defmodule Pleroma.HealthcheckTest do
|
|||
refute result.healthy
|
||||
end
|
||||
|
||||
test "chech_health/1" do
|
||||
test "check_health/1" do
|
||||
result = Healthcheck.check_health(%Healthcheck{pool_size: 10, active: 9})
|
||||
assert result.healthy
|
||||
end
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ defmodule Pleroma.HTTP.AdapterHelper.GunTest do
|
|||
assert opts[:certificates_verification]
|
||||
end
|
||||
|
||||
test "https url with non standart port" do
|
||||
test "https url with non-standard port" do
|
||||
uri = URI.parse("https://example.com:115")
|
||||
|
||||
opts = Gun.options([receive_conn: false], uri)
|
||||
|
|
@ -44,7 +44,7 @@ defmodule Pleroma.HTTP.AdapterHelper.GunTest do
|
|||
assert opts[:certificates_verification]
|
||||
end
|
||||
|
||||
test "merges with defaul http adapter config" do
|
||||
test "merges with default http adapter config" do
|
||||
defaults = Gun.options([receive_conn: false], URI.parse("https://example.com"))
|
||||
assert Keyword.has_key?(defaults, :a)
|
||||
assert Keyword.has_key?(defaults, :b)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -268,17 +268,6 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
|
|||
end)
|
||||
end
|
||||
|
||||
test "accepts valid token on Sec-WebSocket-Protocol header", %{token: token} do
|
||||
assert {:ok, _} = start_socket("?stream=user", [{"Sec-WebSocket-Protocol", token.token}])
|
||||
|
||||
capture_log(fn ->
|
||||
assert {:error, %WebSockex.RequestError{code: 401}} =
|
||||
start_socket("?stream=user", [{"Sec-WebSocket-Protocol", "I am a friend"}])
|
||||
|
||||
Process.sleep(30)
|
||||
end)
|
||||
end
|
||||
|
||||
test "accepts valid token on client-sent event", %{token: token} do
|
||||
assert {:ok, pid} = start_socket()
|
||||
|
||||
|
|
|
|||
22
test/pleroma/maps_test.exs
Normal file
22
test/pleroma/maps_test.exs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2024 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.MapsTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Maps
|
||||
|
||||
describe "filter_empty_values/1" do
|
||||
assert %{"bar" => "b", "ray" => ["foo"], "objs" => %{"a" => "b"}} ==
|
||||
Maps.filter_empty_values(%{
|
||||
"foo" => nil,
|
||||
"fooz" => "",
|
||||
"bar" => "b",
|
||||
"rei" => [],
|
||||
"ray" => ["foo"],
|
||||
"obj" => %{},
|
||||
"objs" => %{"a" => "b"}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
@ -7,6 +7,8 @@ defmodule Pleroma.MFA.TOTPTest do
|
|||
|
||||
alias Pleroma.MFA.TOTP
|
||||
|
||||
import Pleroma.Tests.Helpers, only: [uri_equal?: 2]
|
||||
|
||||
test "create provisioning_uri to generate qrcode" do
|
||||
uri =
|
||||
TOTP.provisioning_uri("test-secrcet", "test@example.com",
|
||||
|
|
@ -15,7 +17,9 @@ defmodule Pleroma.MFA.TOTPTest do
|
|||
period: 60
|
||||
)
|
||||
|
||||
assert uri ==
|
||||
assert uri_equal?(
|
||||
uri,
|
||||
"otpauth://totp/test@example.com?digits=8&issuer=Plerome-42&period=60&secret=test-secrcet"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -101,8 +101,7 @@ defmodule Pleroma.Object.FetcherTest do
|
|||
test "it returns thread depth exceeded error if thread depth is exceeded" do
|
||||
clear_config([:instance, :federation_incoming_replies_max_depth], 0)
|
||||
|
||||
assert {:error, "Max thread distance exceeded."} =
|
||||
Fetcher.fetch_object_from_id(@ap_id, depth: 1)
|
||||
assert {:error, :allowed_depth} = Fetcher.fetch_object_from_id(@ap_id, depth: 1)
|
||||
end
|
||||
|
||||
test "it fetches object if max thread depth is restricted to 0 and depth is not specified" do
|
||||
|
|
@ -220,14 +219,14 @@ defmodule Pleroma.Object.FetcherTest do
|
|||
end
|
||||
|
||||
test "handle HTTP 410 Gone response" do
|
||||
assert {:error, "Object has been deleted"} ==
|
||||
assert {:error, :not_found} ==
|
||||
Fetcher.fetch_and_contain_remote_object_from_id(
|
||||
"https://mastodon.example.org/users/userisgone"
|
||||
)
|
||||
end
|
||||
|
||||
test "handle HTTP 404 response" do
|
||||
assert {:error, "Object has been deleted"} ==
|
||||
assert {:error, :not_found} ==
|
||||
Fetcher.fetch_and_contain_remote_object_from_id(
|
||||
"https://mastodon.example.org/users/userisgone404"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ defmodule Pleroma.OTPVersionTest do
|
|||
"23.0"
|
||||
end
|
||||
|
||||
test "with non existance file" do
|
||||
test "with nonexistent file" do
|
||||
assert OTPVersion.get_version_from_files([
|
||||
"test/fixtures/warnings/otp_version/non-exising",
|
||||
"test/fixtures/warnings/otp_version/22.4"
|
||||
|
|
|
|||
|
|
@ -29,13 +29,13 @@ defmodule Pleroma.Repo.Migrations.AutolinkerToLinkifyTest do
|
|||
|
||||
%{value: new_opts} = ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Formatter})
|
||||
|
||||
assert new_opts == [
|
||||
assert Keyword.equal?(new_opts,
|
||||
class: false,
|
||||
extra: true,
|
||||
new_window: false,
|
||||
rel: "testing",
|
||||
strip_prefix: false
|
||||
]
|
||||
)
|
||||
|
||||
clear_config(Pleroma.Formatter, new_opts)
|
||||
assert new_opts == Pleroma.Config.get(Pleroma.Formatter)
|
||||
|
|
@ -67,6 +67,6 @@ defmodule Pleroma.Repo.Migrations.AutolinkerToLinkifyTest do
|
|||
strip_prefix: false
|
||||
]
|
||||
|
||||
assert migration.transform_opts(old_opts) == expected_opts
|
||||
assert Keyword.equal?(migration.transform_opts(old_opts), expected_opts)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@ defmodule Pleroma.Repo.Migrations.FixMalformedFormatterConfigTest do
|
|||
|
||||
%{value: new_opts} = ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Formatter})
|
||||
|
||||
assert new_opts == [
|
||||
assert Keyword.equal?(new_opts,
|
||||
class: false,
|
||||
extra: true,
|
||||
new_window: false,
|
||||
rel: "F",
|
||||
strip_prefix: false
|
||||
]
|
||||
)
|
||||
|
||||
clear_config(Pleroma.Formatter, new_opts)
|
||||
assert new_opts == Pleroma.Config.get(Pleroma.Formatter)
|
||||
|
|
|
|||
|
|
@ -306,7 +306,7 @@ defmodule Pleroma.ReverseProxyTest do
|
|||
end
|
||||
|
||||
describe "response content disposition header" do
|
||||
test "not atachment", %{conn: conn} do
|
||||
test "not attachment", %{conn: conn} do
|
||||
disposition_headers_mock([
|
||||
{"content-type", "image/gif"},
|
||||
{"content-length", "0"}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -116,7 +113,7 @@ defmodule Pleroma.SignatureTest do
|
|||
|
||||
test "it calls webfinger for 'acct:' accounts" do
|
||||
with_mock(Pleroma.Web.WebFinger,
|
||||
finger: fn _ -> %{"ap_id" => "https://gensokyo.2hu/users/raymoo"} end
|
||||
finger: fn _ -> {:ok, %{"ap_id" => "https://gensokyo.2hu/users/raymoo"}} end
|
||||
) do
|
||||
assert Signature.key_id_to_actor_id("acct:raymoo@gensokyo.2hu") ==
|
||||
{:ok, "https://gensokyo.2hu/users/raymoo"}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -221,7 +226,7 @@ defmodule Pleroma.UserTest do
|
|||
assert [] = User.get_follow_requests(followed)
|
||||
end
|
||||
|
||||
test "follow_all follows mutliple users" do
|
||||
test "follow_all follows multiple users" do
|
||||
user = insert(:user)
|
||||
followed_zero = insert(:user)
|
||||
followed_one = insert(:user)
|
||||
|
|
@ -245,7 +250,7 @@ defmodule Pleroma.UserTest do
|
|||
refute User.following?(user, reverse_blocked)
|
||||
end
|
||||
|
||||
test "follow_all follows mutliple users without duplicating" do
|
||||
test "follow_all follows multiple users without duplicating" do
|
||||
user = insert(:user)
|
||||
followed_zero = insert(:user)
|
||||
followed_one = insert(:user)
|
||||
|
|
@ -868,7 +873,7 @@ defmodule Pleroma.UserTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "get_or_fetch/1 remote users with tld, while BE is runned on subdomain" do
|
||||
describe "get_or_fetch/1 remote users with tld, while BE is running on a subdomain" do
|
||||
setup do: clear_config([Pleroma.Web.WebFinger, :update_nickname_on_user_fetch], true)
|
||||
|
||||
test "for mastodon" do
|
||||
|
|
@ -1013,13 +1018,13 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
@tag capture_log: true
|
||||
test "returns nil if no user could be fetched" do
|
||||
{:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistant@social.heldscal.la")
|
||||
assert fetched_user == "not found nonexistant@social.heldscal.la"
|
||||
{:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistent@social.heldscal.la")
|
||||
assert fetched_user == "not found nonexistent@social.heldscal.la"
|
||||
end
|
||||
|
||||
test "returns nil for nonexistant local user" do
|
||||
{:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistant")
|
||||
assert fetched_user == "not found nonexistant"
|
||||
test "returns nil for nonexistent local user" do
|
||||
{:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistent")
|
||||
assert fetched_user == "not found nonexistent"
|
||||
end
|
||||
|
||||
test "updates an existing user, if stale" do
|
||||
|
|
@ -1127,7 +1132,7 @@ defmodule Pleroma.UserTest do
|
|||
assert cs.valid?
|
||||
end
|
||||
|
||||
test "it sets the follower_adress" do
|
||||
test "it sets the follower_address" do
|
||||
cs = User.remote_user_changeset(@valid_remote)
|
||||
# remote users get a fake local follower address
|
||||
assert cs.changes.follower_address ==
|
||||
|
|
@ -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
|
||||
|
|
@ -2419,20 +2424,20 @@ defmodule Pleroma.UserTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "is_internal_user?/1" do
|
||||
describe "internal?/1" do
|
||||
test "non-internal user returns false" do
|
||||
user = insert(:user)
|
||||
refute User.is_internal_user?(user)
|
||||
refute User.internal?(user)
|
||||
end
|
||||
|
||||
test "user with no nickname returns true" do
|
||||
user = insert(:user, %{nickname: nil})
|
||||
assert User.is_internal_user?(user)
|
||||
assert User.internal?(user)
|
||||
end
|
||||
|
||||
test "user with internal-prefixed nickname returns true" do
|
||||
user = insert(:user, %{nickname: "internal.test"})
|
||||
assert User.is_internal_user?(user)
|
||||
assert User.internal?(user)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -2678,13 +2683,23 @@ defmodule Pleroma.UserTest do
|
|||
end
|
||||
|
||||
describe "full_nickname/1" do
|
||||
test "returns fully qualified nickname for local and remote users" do
|
||||
local_user =
|
||||
insert(:user, nickname: "local_user", ap_id: "https://somehost.com/users/local_user")
|
||||
test "returns fully qualified nickname for local users" do
|
||||
local_user = insert(:user, nickname: "local_user")
|
||||
|
||||
assert User.full_nickname(local_user) == "local_user@localhost"
|
||||
end
|
||||
|
||||
test "returns fully qualified nickname for local users when using different domain for webfinger" do
|
||||
clear_config([Pleroma.Web.WebFinger, :domain], "plemora.dev")
|
||||
|
||||
local_user = insert(:user, nickname: "local_user")
|
||||
|
||||
assert User.full_nickname(local_user) == "local_user@plemora.dev"
|
||||
end
|
||||
|
||||
test "returns fully qualified nickname for remote users" do
|
||||
remote_user = insert(:user, nickname: "remote@host.com", local: false)
|
||||
|
||||
assert User.full_nickname(local_user) == "local_user@somehost.com"
|
||||
assert User.full_nickname(remote_user) == "remote@host.com"
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -216,7 +221,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
user = insert(:user)
|
||||
{:ok, post} = CommonAPI.post(user, %{status: "test", visibility: "local"})
|
||||
|
||||
assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post)
|
||||
assert Pleroma.Web.ActivityPub.Visibility.local_public?(post)
|
||||
|
||||
object = Object.normalize(post, fetch: false)
|
||||
uuid = String.split(object.data["id"], "/") |> List.last()
|
||||
|
|
@ -233,7 +238,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
user = insert(:user)
|
||||
{:ok, post} = CommonAPI.post(user, %{status: "test", visibility: "local"})
|
||||
|
||||
assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post)
|
||||
assert Pleroma.Web.ActivityPub.Visibility.local_public?(post)
|
||||
|
||||
object = Object.normalize(post, fetch: false)
|
||||
uuid = String.split(object.data["id"], "/") |> List.last()
|
||||
|
|
@ -254,7 +259,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
{:ok, post} =
|
||||
CommonAPI.post(user, %{status: "test @#{reader.nickname}", visibility: "local"})
|
||||
|
||||
assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post)
|
||||
assert Pleroma.Web.ActivityPub.Visibility.local_public?(post)
|
||||
|
||||
object = Object.normalize(post, fetch: false)
|
||||
uuid = String.split(object.data["id"], "/") |> List.last()
|
||||
|
|
@ -431,7 +436,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
user = insert(:user)
|
||||
{:ok, post} = CommonAPI.post(user, %{status: "test", visibility: "local"})
|
||||
|
||||
assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post)
|
||||
assert Pleroma.Web.ActivityPub.Visibility.local_public?(post)
|
||||
|
||||
uuid = String.split(post.data["id"], "/") |> List.last()
|
||||
|
||||
|
|
@ -447,7 +452,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
user = insert(:user)
|
||||
{:ok, post} = CommonAPI.post(user, %{status: "test", visibility: "local"})
|
||||
|
||||
assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post)
|
||||
assert Pleroma.Web.ActivityPub.Visibility.local_public?(post)
|
||||
|
||||
uuid = String.split(post.data["id"], "/") |> List.last()
|
||||
|
||||
|
|
@ -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
|
||||
|
|
@ -994,7 +1028,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
refute repeat_activity in activities
|
||||
end
|
||||
|
||||
test "see your own posts even when they adress actors from blocked domains" do
|
||||
test "see your own posts even when they address actors from blocked domains" do
|
||||
user = insert(:user)
|
||||
|
||||
domain = "dogwhistle.zone"
|
||||
|
|
@ -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(%{
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrependedTest do
|
|||
assert res["object"]["summary"] == "re: object-summary"
|
||||
end
|
||||
|
||||
test "it adds `re:` to summary object when child summary containts re-subject of parent summary " do
|
||||
test "it adds `re:` to summary object when child summary contains re-subject of parent summary " do
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
"object" => %{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -60,6 +60,59 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do
|
|||
|> File.exists?()
|
||||
end
|
||||
|
||||
test "works with unknown extension", %{path: path} do
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
"object" => %{
|
||||
"emoji" => [{"firedfox", "https://example.org/emoji/firedfox"}],
|
||||
"actor" => "https://example.org/users/admin"
|
||||
}
|
||||
}
|
||||
|
||||
fullpath = Path.join(path, "firedfox.png")
|
||||
|
||||
Tesla.Mock.mock(fn %{method: :get, url: "https://example.org/emoji/firedfox"} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/image.jpg")}
|
||||
end)
|
||||
|
||||
clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 284_468)
|
||||
|
||||
refute "firedfox" in installed()
|
||||
refute File.exists?(path)
|
||||
|
||||
assert {:ok, _message} = StealEmojiPolicy.filter(message)
|
||||
|
||||
assert "firedfox" in installed()
|
||||
assert File.exists?(path)
|
||||
assert File.exists?(fullpath)
|
||||
end
|
||||
|
||||
test "rejects invalid shortcodes", %{path: path} do
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
"object" => %{
|
||||
"emoji" => [{"fired/fox", "https://example.org/emoji/firedfox"}],
|
||||
"actor" => "https://example.org/users/admin"
|
||||
}
|
||||
}
|
||||
|
||||
fullpath = Path.join(path, "fired/fox.png")
|
||||
|
||||
Tesla.Mock.mock(fn %{method: :get, url: "https://example.org/emoji/firedfox"} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/image.jpg")}
|
||||
end)
|
||||
|
||||
clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 284_468)
|
||||
|
||||
refute "firedfox" in installed()
|
||||
refute File.exists?(path)
|
||||
|
||||
assert {:ok, _message} = StealEmojiPolicy.filter(message)
|
||||
|
||||
refute "fired/fox" in installed()
|
||||
refute File.exists?(fullpath)
|
||||
end
|
||||
|
||||
test "reject regex shortcode", %{message: message} do
|
||||
refute "firedfox" in installed()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
|
||||
# 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
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
|
||||
alias Pleroma.Web.ActivityPub.MRF
|
||||
|
||||
test "subdomains_regex/1" do
|
||||
|
|
@ -61,6 +64,14 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
refute MRF.subdomain_match?(regexes, "EXAMPLE.COM")
|
||||
refute MRF.subdomain_match?(regexes, "example.com")
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
test "logs sensible error on accidental wildcard" do
|
||||
assert_raise Regex.CompileError, fn ->
|
||||
assert capture_log(MRF.subdomains_regex(["*unsafe.tld"])) =~
|
||||
"MRF: Invalid subdomain Regex: *unsafe.tld"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "instance_list_from_tuples/1" do
|
||||
|
|
|
|||
|
|
@ -93,6 +93,17 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest
|
|||
%{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
|
||||
end
|
||||
|
||||
test "a Note from Convergence AP Bridge validates" do
|
||||
insert(:user, ap_id: "https://cc.mkdir.uk/ap/acct/hiira")
|
||||
|
||||
note =
|
||||
"test/fixtures/ccworld-ap-bridge_note.json"
|
||||
|> File.read!()
|
||||
|> Jason.decode!()
|
||||
|
||||
%{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
|
||||
end
|
||||
|
||||
test "a note with an attachment should work", _ do
|
||||
insert(:user, %{ap_id: "https://owncast.localhost.localdomain/federation/user/streamer"})
|
||||
|
||||
|
|
|
|||
|
|
@ -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} =
|
||||
|
|
@ -159,7 +164,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
|
|||
assert attachment.mediaType == "image/jpeg"
|
||||
end
|
||||
|
||||
test "it transforms image dimentions to our internal format" do
|
||||
test "it transforms image dimensions to our internal format" do
|
||||
attachment = %{
|
||||
"type" => "Document",
|
||||
"name" => "Hello world",
|
||||
|
|
|
|||
|
|
@ -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 =
|
||||
|
|
@ -136,6 +147,21 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
|
|||
assert object["attachment"]
|
||||
end
|
||||
|
||||
test "validates for a basic object with content but attachment set to empty array", %{
|
||||
user: user,
|
||||
recipient: recipient
|
||||
} do
|
||||
{:ok, valid_chat_message, _} = Builder.chat_message(user, recipient.ap_id, "Hello!")
|
||||
|
||||
valid_chat_message =
|
||||
valid_chat_message
|
||||
|> Map.put("attachment", [])
|
||||
|
||||
assert {:ok, object, _meta} = ObjectValidator.validate(valid_chat_message, [])
|
||||
|
||||
assert object == Map.drop(valid_chat_message, ["attachment"])
|
||||
end
|
||||
|
||||
test "does not validate if the message has no content", %{
|
||||
valid_chat_message: valid_chat_message
|
||||
} do
|
||||
|
|
|
|||
|
|
@ -212,7 +212,8 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
actor = insert(:user)
|
||||
inbox = "http://404.site/users/nick1/inbox"
|
||||
|
||||
assert {:error, _} = Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1})
|
||||
assert {:discard, _} =
|
||||
Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1})
|
||||
|
||||
assert called(Instances.set_unreachable(inbox))
|
||||
end
|
||||
|
|
@ -268,7 +269,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
|
||||
describe "publish/2" do
|
||||
test_with_mock "doesn't publish a non-public activity to quarantined instances.",
|
||||
Pleroma.Web.Federator.Publisher,
|
||||
Pleroma.Web.ActivityPub.Publisher,
|
||||
[:passthrough],
|
||||
[] do
|
||||
Config.put([:instance, :quarantined_instances], [{"domain.com", "some reason"}])
|
||||
|
|
@ -295,7 +296,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
assert res == :ok
|
||||
|
||||
assert not called(
|
||||
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
|
||||
Publisher.enqueue_one(%{
|
||||
inbox: "https://domain.com/users/nick1/inbox",
|
||||
actor_id: actor.id,
|
||||
id: note_activity.data["id"]
|
||||
|
|
@ -304,7 +305,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
end
|
||||
|
||||
test_with_mock "Publishes a non-public activity to non-quarantined instances.",
|
||||
Pleroma.Web.Federator.Publisher,
|
||||
Pleroma.Web.ActivityPub.Publisher,
|
||||
[:passthrough],
|
||||
[] do
|
||||
Config.put([:instance, :quarantined_instances], [{"somedomain.com", "some reason"}])
|
||||
|
|
@ -331,16 +332,43 @@ 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"]
|
||||
})
|
||||
Publisher.enqueue_one(
|
||||
%{
|
||||
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.ActivityPub.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(
|
||||
Publisher.enqueue_one(
|
||||
%{
|
||||
inbox: :_,
|
||||
actor_id: actor.id,
|
||||
id: note_activity.data["id"]
|
||||
},
|
||||
priority: 0
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
test_with_mock "publishes an activity with BCC to all relevant peers.",
|
||||
Pleroma.Web.Federator.Publisher,
|
||||
Pleroma.Web.ActivityPub.Publisher,
|
||||
[:passthrough],
|
||||
[] do
|
||||
follower =
|
||||
|
|
@ -364,7 +392,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
assert res == :ok
|
||||
|
||||
assert called(
|
||||
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
|
||||
Publisher.enqueue_one(%{
|
||||
inbox: "https://domain.com/users/nick1/inbox",
|
||||
actor_id: actor.id,
|
||||
id: note_activity.data["id"]
|
||||
|
|
@ -373,7 +401,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
end
|
||||
|
||||
test_with_mock "publishes a delete activity to peers who signed fetch requests to the create acitvity/object.",
|
||||
Pleroma.Web.Federator.Publisher,
|
||||
Pleroma.Web.ActivityPub.Publisher,
|
||||
[:passthrough],
|
||||
[] do
|
||||
fetcher =
|
||||
|
|
@ -414,19 +442,25 @@ 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"]
|
||||
})
|
||||
Publisher.enqueue_one(
|
||||
%{
|
||||
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"]
|
||||
})
|
||||
Publisher.enqueue_one(
|
||||
%{
|
||||
inbox: "https://domain2.com/users/nick1/inbox",
|
||||
actor_id: actor.id,
|
||||
id: delete.data["id"]
|
||||
},
|
||||
priority: 1
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,11 +17,19 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
alias Pleroma.Web.ActivityPub.SideEffects
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.CommonAPI.ActivityDraft
|
||||
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
|
||||
defp get_announces_of_object(%{data: %{"id" => id}} = _object) do
|
||||
Pleroma.Activity.Queries.by_type("Announce")
|
||||
|> Pleroma.Activity.Queries.by_object_id(id)
|
||||
|> Pleroma.Repo.all()
|
||||
end
|
||||
|
||||
describe "handle_after_transaction" do
|
||||
test "it streams out notifications and streams" do
|
||||
author = insert(:user, local: true)
|
||||
|
|
@ -915,4 +923,85 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
assert User.get_follow_state(user, followed, nil) == nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "Group actors" do
|
||||
setup do
|
||||
poster =
|
||||
insert(:user,
|
||||
local: false,
|
||||
nickname: "poster@example.com",
|
||||
ap_id: "https://example.com/users/poster"
|
||||
)
|
||||
|
||||
group = insert(:user, actor_type: "Group")
|
||||
|
||||
make_create = fn mentioned_users ->
|
||||
mentions = mentioned_users |> Enum.map(fn u -> "@#{u.nickname}" end) |> Enum.join(" ")
|
||||
{:ok, draft} = ActivityDraft.create(poster, %{status: "#{mentions} hey"})
|
||||
|
||||
create_activity_data =
|
||||
Utils.make_create_data(draft.changes |> Map.put(:published, nil), %{})
|
||||
|> put_in(["object", "id"], "https://example.com/object")
|
||||
|> put_in(["id"], "https://example.com/activity")
|
||||
|
||||
assert Enum.all?(mentioned_users, fn u -> u.ap_id in create_activity_data["to"] end)
|
||||
|
||||
create_activity_data
|
||||
end
|
||||
|
||||
%{poster: poster, group: group, make_create: make_create}
|
||||
end
|
||||
|
||||
test "group should boost it", %{make_create: make_create, group: group} do
|
||||
create_activity_data = make_create.([group])
|
||||
{:ok, create_activity, _meta} = ActivityPub.persist(create_activity_data, local: false)
|
||||
|
||||
{:ok, _create_activity, _meta} =
|
||||
SideEffects.handle(create_activity,
|
||||
local: false,
|
||||
object_data: create_activity_data["object"]
|
||||
)
|
||||
|
||||
object = Object.normalize(create_activity, fetch: false)
|
||||
assert [announce] = get_announces_of_object(object)
|
||||
assert announce.actor == group.ap_id
|
||||
end
|
||||
|
||||
test "remote group should not boost it", %{make_create: make_create, group: group} do
|
||||
remote_group =
|
||||
insert(:user, actor_type: "Group", local: false, nickname: "remotegroup@example.com")
|
||||
|
||||
create_activity_data = make_create.([group, remote_group])
|
||||
{:ok, create_activity, _meta} = ActivityPub.persist(create_activity_data, local: false)
|
||||
|
||||
{:ok, _create_activity, _meta} =
|
||||
SideEffects.handle(create_activity,
|
||||
local: false,
|
||||
object_data: create_activity_data["object"]
|
||||
)
|
||||
|
||||
object = Object.normalize(create_activity, fetch: false)
|
||||
assert [announce] = get_announces_of_object(object)
|
||||
assert announce.actor == group.ap_id
|
||||
end
|
||||
|
||||
test "group should not boost it if group is blocking poster", %{
|
||||
make_create: make_create,
|
||||
group: group,
|
||||
poster: poster
|
||||
} do
|
||||
{:ok, _} = CommonAPI.block(group, poster)
|
||||
create_activity_data = make_create.([group])
|
||||
{:ok, create_activity, _meta} = ActivityPub.persist(create_activity_data, local: false)
|
||||
|
||||
{:ok, _create_activity, _meta} =
|
||||
SideEffects.handle(create_activity,
|
||||
local: false,
|
||||
object_data: create_activity_data["object"]
|
||||
)
|
||||
|
||||
object = Object.normalize(create_activity, fetch: false)
|
||||
assert [] = get_announces_of_object(object)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -221,6 +221,19 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
"<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>"
|
||||
end
|
||||
|
||||
test "it works for incoming notices with a nil contentMap (firefish)" do
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity-contentmap.json")
|
||||
|> Jason.decode!()
|
||||
|> Map.put("contentMap", nil)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
object = Object.normalize(data["object"], fetch: false)
|
||||
|
||||
assert object.data["content"] ==
|
||||
"<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>"
|
||||
end
|
||||
|
||||
test "it works for incoming notices with to/cc not being an array (kroeg)" do
|
||||
data = File.read!("test/fixtures/kroeg-post-activity.json") |> Jason.decode!()
|
||||
|
||||
|
|
@ -508,7 +521,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
|
|||
[data: data]
|
||||
end
|
||||
|
||||
test "returns not modified object when hasn't containts inReplyTo field", %{data: data} do
|
||||
test "returns not modified object when has no inReplyTo field", %{data: data} do
|
||||
assert Transmogrifier.fix_in_reply_to(data) == data
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.UndoHandlingTest do
|
|||
assert activity.data["type"] == "Undo"
|
||||
end
|
||||
|
||||
test "it returns an error for incoming unlikes wihout a like activity" do
|
||||
test "it returns an error for incoming unlikes without a like activity" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "leave a like pls"})
|
||||
|
||||
|
|
|
|||
|
|
@ -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) =~ "Object rejected while fetching"
|
||||
end
|
||||
|
||||
test "it accepts quote posts" do
|
||||
|
|
@ -409,7 +410,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
assert capture_log(fn ->
|
||||
{:error, _} = Transmogrifier.handle_incoming(data)
|
||||
end) =~ "Object containment failed"
|
||||
end) =~ "Object rejected while fetching"
|
||||
end
|
||||
|
||||
test "it rejects activities which reference objects that have an incorrect attribution (variant 1)" do
|
||||
|
|
@ -424,7 +425,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
assert capture_log(fn ->
|
||||
{:error, _} = Transmogrifier.handle_incoming(data)
|
||||
end) =~ "Object containment failed"
|
||||
end) =~ "Object rejected while fetching"
|
||||
end
|
||||
|
||||
test "it rejects activities which reference objects that have an incorrect attribution (variant 2)" do
|
||||
|
|
@ -439,7 +440,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
assert capture_log(fn ->
|
||||
{:error, _} = Transmogrifier.handle_incoming(data)
|
||||
end) =~ "Object containment failed"
|
||||
end) =~ "Object rejected while fetching"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -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 activities" 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)
|
||||
|
|
@ -118,7 +153,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
assert Enum.sort(cc) == expected_cc
|
||||
end
|
||||
|
||||
test "does not adress actor's follower address if the activity is not public", %{
|
||||
test "does not address actor's follower address if the activity is not public", %{
|
||||
user: user,
|
||||
other_user: other_user,
|
||||
third_user: third_user
|
||||
|
|
@ -587,7 +622,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
end
|
||||
|
||||
describe "get_cached_emoji_reactions/1" do
|
||||
test "returns the normalized data or an emtpy list" do
|
||||
test "returns the normalized data or an empty list" do
|
||||
object = insert(:note)
|
||||
assert Utils.get_cached_emoji_reactions(object) == []
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -52,60 +52,60 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
|
|||
}
|
||||
end
|
||||
|
||||
test "is_direct?", %{
|
||||
test "direct?", %{
|
||||
public: public,
|
||||
private: private,
|
||||
direct: direct,
|
||||
unlisted: unlisted,
|
||||
list: list
|
||||
} do
|
||||
assert Visibility.is_direct?(direct)
|
||||
refute Visibility.is_direct?(public)
|
||||
refute Visibility.is_direct?(private)
|
||||
refute Visibility.is_direct?(unlisted)
|
||||
assert Visibility.is_direct?(list)
|
||||
assert Visibility.direct?(direct)
|
||||
refute Visibility.direct?(public)
|
||||
refute Visibility.direct?(private)
|
||||
refute Visibility.direct?(unlisted)
|
||||
assert Visibility.direct?(list)
|
||||
end
|
||||
|
||||
test "is_public?", %{
|
||||
test "public?", %{
|
||||
public: public,
|
||||
private: private,
|
||||
direct: direct,
|
||||
unlisted: unlisted,
|
||||
list: list
|
||||
} do
|
||||
refute Visibility.is_public?(direct)
|
||||
assert Visibility.is_public?(public)
|
||||
refute Visibility.is_public?(private)
|
||||
assert Visibility.is_public?(unlisted)
|
||||
refute Visibility.is_public?(list)
|
||||
refute Visibility.public?(direct)
|
||||
assert Visibility.public?(public)
|
||||
refute Visibility.public?(private)
|
||||
assert Visibility.public?(unlisted)
|
||||
refute Visibility.public?(list)
|
||||
end
|
||||
|
||||
test "is_private?", %{
|
||||
test "private?", %{
|
||||
public: public,
|
||||
private: private,
|
||||
direct: direct,
|
||||
unlisted: unlisted,
|
||||
list: list
|
||||
} do
|
||||
refute Visibility.is_private?(direct)
|
||||
refute Visibility.is_private?(public)
|
||||
assert Visibility.is_private?(private)
|
||||
refute Visibility.is_private?(unlisted)
|
||||
refute Visibility.is_private?(list)
|
||||
refute Visibility.private?(direct)
|
||||
refute Visibility.private?(public)
|
||||
assert Visibility.private?(private)
|
||||
refute Visibility.private?(unlisted)
|
||||
refute Visibility.private?(list)
|
||||
end
|
||||
|
||||
test "is_list?", %{
|
||||
test "list?", %{
|
||||
public: public,
|
||||
private: private,
|
||||
direct: direct,
|
||||
unlisted: unlisted,
|
||||
list: list
|
||||
} do
|
||||
refute Visibility.is_list?(direct)
|
||||
refute Visibility.is_list?(public)
|
||||
refute Visibility.is_list?(private)
|
||||
refute Visibility.is_list?(unlisted)
|
||||
assert Visibility.is_list?(list)
|
||||
refute Visibility.list?(direct)
|
||||
refute Visibility.list?(public)
|
||||
refute Visibility.list?(private)
|
||||
refute Visibility.list?(unlisted)
|
||||
assert Visibility.list?(list)
|
||||
end
|
||||
|
||||
test "visible_for_user? Activity", %{
|
||||
|
|
@ -227,7 +227,7 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
|
|||
} do
|
||||
Repo.delete(user)
|
||||
Pleroma.User.invalidate_cache(user)
|
||||
refute Visibility.is_private?(direct)
|
||||
refute Visibility.private?(direct)
|
||||
end
|
||||
|
||||
test "get_visibility", %{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -873,7 +873,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
%{
|
||||
"tuple" => [
|
||||
":_",
|
||||
"Phoenix.Endpoint.Cowboy2Handler",
|
||||
"Plug.Cowboy.Handler",
|
||||
%{"tuple" => ["Pleroma.Web.Endpoint", []]}
|
||||
]
|
||||
}
|
||||
|
|
@ -937,7 +937,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
%{
|
||||
"tuple" => [
|
||||
":_",
|
||||
"Phoenix.Endpoint.Cowboy2Handler",
|
||||
"Plug.Cowboy.Handler",
|
||||
%{"tuple" => ["Pleroma.Web.Endpoint", []]}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ defmodule Pleroma.Web.AdminAPI.OAuthAppControllerTest do
|
|||
assert response == ""
|
||||
end
|
||||
|
||||
test "with non existance id", %{conn: conn} do
|
||||
test "with nonexistent id", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> delete("/api/pleroma/admin/oauth_app/0")
|
||||
|
|
|
|||
|
|
@ -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,17 +21,32 @@ 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.Activity.Queries
|
||||
require Pleroma.Constants
|
||||
|
||||
defp get_announces_of_object(%{data: %{"id" => id}} = _object) do
|
||||
Pleroma.Activity.Queries.by_type("Announce")
|
||||
|> Pleroma.Activity.Queries.by_object_id(id)
|
||||
|> Pleroma.Repo.all()
|
||||
end
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
: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])
|
||||
|
|
@ -490,7 +506,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
{:ok, convo_reply} =
|
||||
CommonAPI.post(user, %{status: ".", in_reply_to_conversation_id: participation.id})
|
||||
|
||||
assert Visibility.is_direct?(convo_reply)
|
||||
assert Visibility.direct?(convo_reply)
|
||||
|
||||
assert activity.data["context"] == convo_reply.data["context"]
|
||||
end
|
||||
|
|
@ -908,7 +924,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
{:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
|
||||
|
||||
{:ok, %Activity{} = announce_activity} = CommonAPI.repeat(activity.id, user)
|
||||
assert Visibility.is_public?(announce_activity)
|
||||
assert Visibility.public?(announce_activity)
|
||||
end
|
||||
|
||||
test "can't repeat a repeat" do
|
||||
|
|
@ -930,7 +946,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
{:ok, %Activity{} = announce_activity} =
|
||||
CommonAPI.repeat(activity.id, user, %{visibility: "private"})
|
||||
|
||||
assert Visibility.is_private?(announce_activity)
|
||||
assert Visibility.private?(announce_activity)
|
||||
refute Visibility.visible_for_user?(announce_activity, nil)
|
||||
end
|
||||
|
||||
|
|
@ -943,7 +959,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
{:ok, %Activity{} = announce_activity} = CommonAPI.repeat(activity.id, author)
|
||||
|
||||
assert Visibility.is_private?(announce_activity)
|
||||
assert Visibility.private?(announce_activity)
|
||||
refute Visibility.visible_for_user?(announce_activity, nil)
|
||||
|
||||
assert Visibility.visible_for_user?(activity, follower)
|
||||
|
|
@ -1588,7 +1604,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "#2hu #2HU", visibility: "local"})
|
||||
|
||||
assert Visibility.is_local_public?(activity)
|
||||
assert Visibility.local_public?(activity)
|
||||
assert_not_called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
end
|
||||
|
|
@ -1603,7 +1619,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
assert {:ok, %Activity{data: %{"deleted_activity_id" => ^activity_id}} = activity} =
|
||||
CommonAPI.delete(activity_id, user)
|
||||
|
||||
assert Visibility.is_local_public?(activity)
|
||||
assert Visibility.local_public?(activity)
|
||||
assert_not_called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
end
|
||||
|
|
@ -1619,7 +1635,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
assert {:ok, %Activity{data: %{"type" => "Announce"}} = activity} =
|
||||
CommonAPI.repeat(activity_id, user)
|
||||
|
||||
assert Visibility.is_local_public?(activity)
|
||||
assert Visibility.local_public?(activity)
|
||||
refute called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
end
|
||||
|
|
@ -1637,7 +1653,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
assert {:ok, %Activity{data: %{"type" => "Undo"}} = activity} =
|
||||
CommonAPI.unrepeat(activity_id, user)
|
||||
|
||||
assert Visibility.is_local_public?(activity)
|
||||
assert Visibility.local_public?(activity)
|
||||
refute called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
end
|
||||
|
|
@ -1652,7 +1668,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
assert {:ok, %Activity{data: %{"type" => "Like"}} = activity} =
|
||||
CommonAPI.favorite(user, activity.id)
|
||||
|
||||
assert Visibility.is_local_public?(activity)
|
||||
assert Visibility.local_public?(activity)
|
||||
refute called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
end
|
||||
|
|
@ -1667,7 +1683,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
|
||||
assert {:ok, activity} = CommonAPI.unfavorite(activity.id, user)
|
||||
assert Visibility.is_local_public?(activity)
|
||||
assert Visibility.local_public?(activity)
|
||||
refute called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
end
|
||||
|
|
@ -1681,7 +1697,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
assert {:ok, %Activity{data: %{"type" => "EmojiReact"}} = activity} =
|
||||
CommonAPI.react_with_emoji(activity.id, user, "👍")
|
||||
|
||||
assert Visibility.is_local_public?(activity)
|
||||
assert Visibility.local_public?(activity)
|
||||
refute called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
end
|
||||
|
|
@ -1697,7 +1713,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
assert {:ok, %Activity{data: %{"type" => "Undo"}} = activity} =
|
||||
CommonAPI.unreact_with_emoji(activity.id, user, "👍")
|
||||
|
||||
assert Visibility.is_local_public?(activity)
|
||||
assert Visibility.local_public?(activity)
|
||||
refute called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
end
|
||||
|
|
@ -1826,4 +1842,54 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
assert Map.has_key?(updated_object.data, "updated")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Group actors" do
|
||||
setup do
|
||||
poster = insert(:user)
|
||||
group = insert(:user, actor_type: "Group")
|
||||
other_group = insert(:user, actor_type: "Group")
|
||||
%{poster: poster, group: group, other_group: other_group}
|
||||
end
|
||||
|
||||
test "it boosts public posts", %{poster: poster, group: group} do
|
||||
{:ok, post} = CommonAPI.post(poster, %{status: "hey @#{group.nickname}"})
|
||||
|
||||
announces = get_announces_of_object(post.object)
|
||||
assert [_] = announces
|
||||
end
|
||||
|
||||
test "it does not boost private posts", %{poster: poster, group: group} do
|
||||
{:ok, private_post} =
|
||||
CommonAPI.post(poster, %{status: "hey @#{group.nickname}", visibility: "private"})
|
||||
|
||||
assert [] = get_announces_of_object(private_post.object)
|
||||
end
|
||||
|
||||
test "remote groups do not boost any posts", %{poster: poster} do
|
||||
remote_group =
|
||||
insert(:user, actor_type: "Group", local: false, nickname: "remote@example.com")
|
||||
|
||||
{:ok, post} = CommonAPI.post(poster, %{status: "hey @#{User.full_nickname(remote_group)}"})
|
||||
assert remote_group.ap_id in post.data["to"]
|
||||
|
||||
announces = get_announces_of_object(post.object)
|
||||
assert [] = announces
|
||||
end
|
||||
|
||||
test "multiple groups mentioned", %{poster: poster, group: group, other_group: other_group} do
|
||||
{:ok, post} =
|
||||
CommonAPI.post(poster, %{status: "hey @#{group.nickname} @#{other_group.nickname}"})
|
||||
|
||||
announces = get_announces_of_object(post.object)
|
||||
assert [_, _] = announces
|
||||
end
|
||||
|
||||
test "it does not boost if group is blocking poster", %{poster: poster, group: group} do
|
||||
{:ok, _} = CommonAPI.block(group, poster)
|
||||
{:ok, post} = CommonAPI.post(poster, %{status: "hey @#{group.nickname}"})
|
||||
|
||||
announces = get_announces_of_object(post.object)
|
||||
assert [] = announces
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,44 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
%{activity: activity, relay_mock: relay_mock}
|
||||
end
|
||||
|
||||
test "to shared inbox when multiple actors from same instance are recipients" do
|
||||
user = insert(:user)
|
||||
|
||||
shared_inbox = "https://domain.com/inbox"
|
||||
|
||||
follower_one =
|
||||
insert(:user, %{
|
||||
local: false,
|
||||
nickname: "nick1@domain.com",
|
||||
ap_id: "https://domain.com/users/nick1",
|
||||
inbox: "https://domain.com/users/nick1/inbox",
|
||||
shared_inbox: shared_inbox
|
||||
})
|
||||
|
||||
follower_two =
|
||||
insert(:user, %{
|
||||
local: false,
|
||||
nickname: "nick2@domain.com",
|
||||
ap_id: "https://domain.com/users/nick2",
|
||||
inbox: "https://domain.com/users/nick2/inbox",
|
||||
shared_inbox: shared_inbox
|
||||
})
|
||||
|
||||
{:ok, _, _} = Pleroma.User.follow(follower_one, user)
|
||||
{:ok, _, _} = Pleroma.User.follow(follower_two, user)
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(user, %{status: "Happy Friday everyone!"})
|
||||
|
||||
ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
|
||||
|
||||
inboxes =
|
||||
all_enqueued(worker: PublisherWorker)
|
||||
|> Enum.filter(&(get_in(&1, [Access.key(:args), Access.key("op")]) == "publish_one"))
|
||||
|> Enum.map(&get_in(&1, [Access.key(:args), Access.key("params"), Access.key("inbox")]))
|
||||
|
||||
assert [shared_inbox] == inboxes
|
||||
end
|
||||
|
||||
test "with relays active, it publishes to the relay", %{
|
||||
activity: activity,
|
||||
relay_mock: relay_mock
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -1355,7 +1360,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert user.registration_reason == "I'm a cool dude, bro"
|
||||
end
|
||||
|
||||
test "returns error when user already registred", %{conn: conn, valid_params: valid_params} do
|
||||
test "returns error when user already registered", %{conn: conn, valid_params: valid_params} do
|
||||
_user = insert(:user, email: "lain@example.org")
|
||||
app_token = insert(:oauth_token, user: nil)
|
||||
|
||||
|
|
@ -1490,7 +1495,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|> Plug.Conn.put_req_header("authorization", "Bearer " <> token)
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> post("/api/v1/accounts", %{
|
||||
nickname: "nickanme",
|
||||
nickname: "nickname",
|
||||
agreement: true,
|
||||
email: "email@example.com",
|
||||
fullname: "Lain",
|
||||
|
|
@ -1776,7 +1781,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert %{language: "ru_RU"} = Pleroma.User.get_by_nickname("foo")
|
||||
end
|
||||
|
||||
test "createing an account without language parameter should fallback to cookie/header language",
|
||||
test "creating an account without language parameter should fallback to cookie/header language",
|
||||
%{conn: conn} do
|
||||
params = %{
|
||||
username: "foo2",
|
||||
|
|
|
|||
|
|
@ -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,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
@tag :skip_on_mac
|
||||
@tag :skip_darwin
|
||||
test "search", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user_two = insert(:user, %{nickname: "shp@shitposter.club"})
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.ScheduledActivity
|
||||
alias Pleroma.Tests.Helpers
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
|
|
@ -19,25 +20,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 +64,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 +123,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 +170,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 +182,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 +196,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,15 +330,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
end
|
||||
|
||||
test "fake statuses' preview card is not cached", %{conn: conn} do
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://example.com/twitter-card"
|
||||
} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/twitter_card.html")}
|
||||
Pleroma.StaticStubbedConfigMock
|
||||
|> stub(:get, fn
|
||||
[:rich_media, :enabled] -> true
|
||||
path -> Pleroma.Test.StaticConfig.get(path)
|
||||
end)
|
||||
|
||||
Tesla.Mock.mock_global(fn
|
||||
env ->
|
||||
apply(HttpRequestMock, :request, [env])
|
||||
end)
|
||||
|
|
@ -353,7 +365,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 +392,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 +429,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 +458,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 +1661,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 +1701,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 +1915,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)
|
||||
|
||||
|
|
@ -2165,7 +2186,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
# Using the header for pagination works correctly
|
||||
[next, _] = get_resp_header(result, "link") |> hd() |> String.split(", ")
|
||||
[_, max_id] = Regex.run(~r/max_id=([^&]+)/, next)
|
||||
[next_url, _next_rel] = String.split(next, ";")
|
||||
next_url = String.trim_trailing(next_url, ">") |> String.trim_leading("<")
|
||||
|
||||
max_id = Helpers.get_query_parameter(next_url, "max_id")
|
||||
|
||||
assert max_id == third_favorite.id
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
use Pleroma.Web.ConnCase, async: false
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
@ -35,17 +35,20 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
|
|||
|
||||
defmacro assert_error_when_disable_push(do: yield) do
|
||||
quote do
|
||||
vapid_details = Application.get_env(:web_push_encryption, :vapid_details, [])
|
||||
Application.put_env(:web_push_encryption, :vapid_details, [])
|
||||
|
||||
assert %{"error" => "Web push subscription is disabled on this Pleroma instance"} ==
|
||||
unquote(yield)
|
||||
|
||||
Application.put_env(:web_push_encryption, :vapid_details, vapid_details)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when disabled" do
|
||||
setup do
|
||||
vapid_config = Application.get_env(:web_push_encryption, :vapid_details)
|
||||
|
||||
Application.put_env(:web_push_encryption, :vapid_details, [])
|
||||
|
||||
on_exit(fn -> Application.put_env(:web_push_encryption, :vapid_details, vapid_config) end)
|
||||
end
|
||||
|
||||
test "POST returns error", %{conn: conn} do
|
||||
assert_error_when_disable_push do
|
||||
conn
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -729,4 +738,20 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
|||
assert account["source"]["pleroma"]["actor_type"] == "Person"
|
||||
end
|
||||
end
|
||||
|
||||
describe "Mark account as group" do
|
||||
setup do: oauth_access(["write:accounts"])
|
||||
setup :request_content_type
|
||||
|
||||
test "changing actor_type to Group makes account a Group and enables bot indicator for backward compatibility",
|
||||
%{conn: conn} do
|
||||
account =
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{actor_type: "Group"})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert account["bot"]
|
||||
assert account["source"]["pleroma"]["actor_type"] == "Group"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -174,7 +182,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
|||
media_proxy_url: media_proxy_url
|
||||
} do
|
||||
Tesla.Mock.mock(fn
|
||||
%{method: "HEAD", url: ^media_proxy_url} ->
|
||||
%{method: :head, url: ^media_proxy_url} ->
|
||||
%Tesla.Env{status: 500, body: ""}
|
||||
end)
|
||||
|
||||
|
|
@ -189,7 +197,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
|||
media_proxy_url: media_proxy_url
|
||||
} do
|
||||
Tesla.Mock.mock(fn
|
||||
%{method: "HEAD", url: ^media_proxy_url} ->
|
||||
%{method: :head, url: ^media_proxy_url} ->
|
||||
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "application/pdf"}]}
|
||||
end)
|
||||
|
||||
|
|
@ -209,7 +217,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
|||
clear_config([:media_preview_proxy, :min_content_length], 1_000_000_000)
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{method: "HEAD", url: ^media_proxy_url} ->
|
||||
%{method: :head, url: ^media_proxy_url} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: "",
|
||||
|
|
@ -234,7 +242,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
|||
media_proxy_url: media_proxy_url
|
||||
} do
|
||||
Tesla.Mock.mock(fn
|
||||
%{method: "HEAD", url: ^media_proxy_url} ->
|
||||
%{method: :head, url: ^media_proxy_url} ->
|
||||
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/gif"}]}
|
||||
end)
|
||||
|
||||
|
|
@ -252,7 +260,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
|||
media_proxy_url: media_proxy_url
|
||||
} do
|
||||
Tesla.Mock.mock(fn
|
||||
%{method: "HEAD", url: ^media_proxy_url} ->
|
||||
%{method: :head, url: ^media_proxy_url} ->
|
||||
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]}
|
||||
end)
|
||||
|
||||
|
|
@ -272,7 +280,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
|||
clear_config([:media_preview_proxy, :min_content_length], 100_000)
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{method: "HEAD", url: ^media_proxy_url} ->
|
||||
%{method: :head, url: ^media_proxy_url} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: "",
|
||||
|
|
@ -294,7 +302,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
|||
assert_dependencies_installed()
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{method: "HEAD", url: ^media_proxy_url} ->
|
||||
%{method: :head, url: ^media_proxy_url} ->
|
||||
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/png"}]}
|
||||
|
||||
%{method: :get, url: ^media_proxy_url} ->
|
||||
|
|
@ -316,7 +324,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
|||
assert_dependencies_installed()
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{method: "HEAD", url: ^media_proxy_url} ->
|
||||
%{method: :head, url: ^media_proxy_url} ->
|
||||
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]}
|
||||
|
||||
%{method: :get, url: ^media_proxy_url} ->
|
||||
|
|
@ -336,7 +344,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
|||
media_proxy_url: media_proxy_url
|
||||
} do
|
||||
Tesla.Mock.mock(fn
|
||||
%{method: "HEAD", url: ^media_proxy_url} ->
|
||||
%{method: :head, url: ^media_proxy_url} ->
|
||||
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]}
|
||||
|
||||
%{method: :get, url: ^media_proxy_url} ->
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ defmodule Pleroma.Web.OAuth.MFAControllerTest do
|
|||
assert response == %{"error" => "Invalid code"}
|
||||
end
|
||||
|
||||
test "returns error when client credentails is wrong ", %{conn: conn, user: user} do
|
||||
test "returns error when client credentials is wrong ", %{conn: conn, user: user} do
|
||||
otp_token = TOTP.generate_token(user.multi_factor_authentication_settings.totp.secret)
|
||||
mfa_token = insert(:mfa_token, user: user)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ defmodule Pleroma.Web.OAuth.Token.UtilsTest do
|
|||
Utils.fetch_app(%Plug.Conn{params: %{"client_id" => 1, "client_secret" => "x"}})
|
||||
end
|
||||
|
||||
test "returns App by params credentails" do
|
||||
test "returns App by params credentials" do
|
||||
app = insert(:oauth_app)
|
||||
|
||||
assert {:ok, load_app} =
|
||||
|
|
@ -24,7 +24,7 @@ defmodule Pleroma.Web.OAuth.Token.UtilsTest do
|
|||
assert load_app == app
|
||||
end
|
||||
|
||||
test "returns App by header credentails" do
|
||||
test "returns App by header credentials" do
|
||||
app = insert(:oauth_app)
|
||||
header = "Basic " <> Base.encode64("#{app.client_id}:#{app.client_secret}")
|
||||
|
||||
|
|
|
|||
|
|
@ -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,13 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
alias Pleroma.Chat
|
||||
alias Pleroma.Chat.MessageReference
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Tests.Helpers
|
||||
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 +115,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)
|
||||
|
|
@ -207,36 +213,63 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
result = json_response_and_validate_schema(response, 200)
|
||||
|
||||
[next, prev] = get_resp_header(response, "link") |> hd() |> String.split(", ")
|
||||
api_endpoint = "/api/v1/pleroma/chats/"
|
||||
api_endpoint = Pleroma.Web.Endpoint.url() <> "/api/v1/pleroma/chats/"
|
||||
|
||||
[next_url, next_rel] = String.split(next, ";")
|
||||
next_url = String.trim_trailing(next_url, ">") |> String.trim_leading("<")
|
||||
|
||||
next_url_sorted = Helpers.uri_query_sort(next_url)
|
||||
|
||||
assert String.match?(
|
||||
next,
|
||||
~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*; rel=\"next\"$)
|
||||
next_url_sorted,
|
||||
~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*&offset=\d+$)
|
||||
)
|
||||
|
||||
assert next_rel =~ "next"
|
||||
|
||||
[prev_url, prev_rel] = String.split(prev, ";")
|
||||
prev_url = String.trim_trailing(prev_url, ">") |> String.trim_leading("<")
|
||||
|
||||
prev_url_sorted = Helpers.uri_query_sort(prev_url)
|
||||
|
||||
assert String.match?(
|
||||
prev,
|
||||
~r(#{api_endpoint}.*/messages\?limit=\d+&min_id=.*; rel=\"prev\"$)
|
||||
prev_url_sorted,
|
||||
~r(#{api_endpoint}.*/messages\?limit=\d+&min_id=.*&offset=\d+$)
|
||||
)
|
||||
|
||||
assert prev_rel =~ "prev"
|
||||
|
||||
assert length(result) == 20
|
||||
|
||||
response =
|
||||
get(conn, "/api/v1/pleroma/chats/#{chat.id}/messages?max_id=#{List.last(result)["id"]}")
|
||||
response = get(conn, "#{api_endpoint}#{chat.id}/messages?max_id=#{List.last(result)["id"]}")
|
||||
|
||||
result = json_response_and_validate_schema(response, 200)
|
||||
[next, prev] = get_resp_header(response, "link") |> hd() |> String.split(", ")
|
||||
|
||||
assert String.match?(
|
||||
next,
|
||||
~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*; rel=\"next\"$)
|
||||
)
|
||||
[next_url, next_rel] = String.split(next, ";")
|
||||
next_url = String.trim_trailing(next_url, ">") |> String.trim_leading("<")
|
||||
|
||||
next_url_sorted = Helpers.uri_query_sort(next_url)
|
||||
|
||||
assert String.match?(
|
||||
prev,
|
||||
~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*&min_id=.*; rel=\"prev\"$)
|
||||
next_url_sorted,
|
||||
~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*&offset=\d+$)
|
||||
)
|
||||
|
||||
assert next_rel =~ "next"
|
||||
|
||||
[prev_url, prev_rel] = String.split(prev, ";")
|
||||
prev_url = String.trim_trailing(prev_url, ">") |> String.trim_leading("<")
|
||||
|
||||
prev_url_sorted = Helpers.uri_query_sort(prev_url)
|
||||
|
||||
assert String.match?(
|
||||
prev_url_sorted,
|
||||
~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*&min_id=.*&offset=\d+$)
|
||||
)
|
||||
|
||||
assert prev_rel =~ "prev"
|
||||
|
||||
assert length(result) == 10
|
||||
end
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue