From 7aec234b44b762fe3564a9572345cc3a020a3fde Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 23 Dec 2020 17:01:11 -0600 Subject: [PATCH 01/24] Remove Proxy settings that were not meant to exist under Pleroma.Upload --- lib/pleroma/config/transfer_task.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/pleroma/config/transfer_task.ex b/lib/pleroma/config/transfer_task.ex index a0d7b7d71..9ec80eb69 100644 --- a/lib/pleroma/config/transfer_task.ex +++ b/lib/pleroma/config/transfer_task.ex @@ -26,7 +26,6 @@ defmodule Pleroma.Config.TransferTask do @reboot_time_subkeys [ {:pleroma, Pleroma.Captcha, [:seconds_valid]}, - {:pleroma, Pleroma.Upload, [:proxy_remote]}, {:pleroma, :instance, [:upload_limit]}, {:pleroma, :gopher, [:enabled]} ] From 5a084d6f8deea40b8134094d10053ca0e9ef51fd Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 23 Dec 2020 17:38:33 -0600 Subject: [PATCH 02/24] Update descriptions for MediaProxy, remove settings that should not be exposed in AdminFE --- config/description.exs | 136 ++++++----------------------------------- 1 file changed, 17 insertions(+), 119 deletions(-) diff --git a/config/description.exs b/config/description.exs index cf004f0cf..94468019f 100644 --- a/config/description.exs +++ b/config/description.exs @@ -102,73 +102,10 @@ key: :proxy_remote, type: :boolean, description: - "If enabled, requests to media stored using a remote uploader will be proxied instead of being redirected" - }, - %{ - key: :proxy_opts, - label: "Proxy Options", - type: :keyword, - description: "Options for Pleroma.ReverseProxy", - suggestions: [ - redirect_on_failure: false, - max_body_length: 25 * 1_048_576, - http: [ - follow_redirect: true, - pool: :media - ] - ], - children: [ - %{ - key: :redirect_on_failure, - type: :boolean, - description: - "Redirects the client to the real remote URL if there's any HTTP errors. " <> - "Any error during body processing will not be redirected as the response is chunked." - }, - %{ - key: :max_body_length, - type: :integer, - description: - "Limits the content length to be approximately the " <> - "specified length. It is validated with the `content-length` header and also verified when proxying." - }, - %{ - key: :http, - label: "HTTP", - type: :keyword, - description: "HTTP options", - children: [ - %{ - key: :adapter, - type: :keyword, - description: "Adapter specific options", - children: [ - %{ - key: :ssl_options, - type: :keyword, - label: "SSL Options", - description: "SSL options for HTTP adapter", - children: [ - %{ - key: :versions, - type: {:list, :atom}, - description: "List of TLS versions to use", - suggestions: [:tlsv1, ":tlsv1.1", ":tlsv1.2"] - } - ] - } - ] - }, - %{ - key: :proxy_url, - label: "Proxy URL", - type: [:string, :tuple], - description: "Proxy URL", - suggestions: ["127.0.0.1:8123", {:socks5, :localhost, 9050}] - } - ] - } - ] + """ + Proxy requests to the remote uploader.\n + Useful if media upload endpoint is not internet accessible. + """ }, %{ key: :filename_display_max_length, @@ -1550,7 +1487,7 @@ %{ key: :enabled, type: :boolean, - description: "Enables proxying of remote media to the instance's proxy" + description: "Enables proxying of remote media via the instance's proxy" }, %{ key: :base_url, @@ -1587,80 +1524,41 @@ }, %{ key: :proxy_opts, - label: "Proxy Options", + label: "Advanced MediaProxy Options", type: :keyword, - description: "Options for Pleroma.ReverseProxy", + description: "Internal Pleroma.ReverseProxy settings", suggestions: [ redirect_on_failure: false, max_body_length: 25 * 1_048_576, - max_read_duration: 30_000, - http: [ - follow_redirect: true, - pool: :media - ] + max_read_duration: 30_000 ], children: [ %{ key: :redirect_on_failure, type: :boolean, - description: - "Redirects the client to the real remote URL if there's any HTTP errors. " <> - "Any error during body processing will not be redirected as the response is chunked." + description: """ + Redirects the client to the origin server upon encountering HTTP errors.\n + Note that files larger than Max Body Length will trigger an error. (e.g., Peertube videos)\n\n + **WARNING:** This setting will allow larger files to be accessed, but exposes the\n + IP addresses of your users to the other servers, bypassing the MediaProxy. + """ }, %{ key: :max_body_length, type: :integer, - description: - "Limits the content length to be approximately the " <> - "specified length. It is validated with the `content-length` header and also verified when proxying." + description: "Maximum file size allowed through the Pleroma MediaProxy cache." }, %{ key: :max_read_duration, type: :integer, - description: "Timeout (in milliseconds) of GET request to remote URI." - }, - %{ - key: :http, - label: "HTTP", - type: :keyword, - description: "HTTP options", - children: [ - %{ - key: :adapter, - type: :keyword, - description: "Adapter specific options", - children: [ - %{ - key: :ssl_options, - type: :keyword, - label: "SSL Options", - description: "SSL options for HTTP adapter", - children: [ - %{ - key: :versions, - type: {:list, :atom}, - description: "List of TLS version to use", - suggestions: [:tlsv1, ":tlsv1.1", ":tlsv1.2"] - } - ] - } - ] - }, - %{ - key: :proxy_url, - label: "Proxy URL", - type: [:string, :tuple], - description: "Proxy URL", - suggestions: ["127.0.0.1:8123", {:socks5, :localhost, 9050}] - } - ] + description: "Timeout (in milliseconds) of GET request to the remote URI." } ] }, %{ key: :whitelist, type: {:list, :string}, - description: "List of hosts with scheme to bypass the mediaproxy", + description: "List of hosts with scheme to bypass the MediaProxy", suggestions: ["http://example.com"] } ] From ce78b64db8976821e5ca0cee0444fffe91744149 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 23 Dec 2020 17:41:10 -0600 Subject: [PATCH 03/24] Formatting --- config/description.exs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/config/description.exs b/config/description.exs index 94468019f..f438a88ab 100644 --- a/config/description.exs +++ b/config/description.exs @@ -101,11 +101,10 @@ %{ key: :proxy_remote, type: :boolean, - description: - """ - Proxy requests to the remote uploader.\n - Useful if media upload endpoint is not internet accessible. - """ + description: """ + Proxy requests to the remote uploader.\n + Useful if media upload endpoint is not internet accessible. + """ }, %{ key: :filename_display_max_length, From 50e226bc528a05157a310f0441d2f6e4cb84f212 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 23 Dec 2020 17:41:15 -0600 Subject: [PATCH 04/24] Revert, this is useful in an edge case --- lib/pleroma/config/transfer_task.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pleroma/config/transfer_task.ex b/lib/pleroma/config/transfer_task.ex index 9ec80eb69..a0d7b7d71 100644 --- a/lib/pleroma/config/transfer_task.ex +++ b/lib/pleroma/config/transfer_task.ex @@ -26,6 +26,7 @@ defmodule Pleroma.Config.TransferTask do @reboot_time_subkeys [ {:pleroma, Pleroma.Captcha, [:seconds_valid]}, + {:pleroma, Pleroma.Upload, [:proxy_remote]}, {:pleroma, :instance, [:upload_limit]}, {:pleroma, :gopher, [:enabled]} ] From 77e39e6aae0852df13b9576a081f30da13d7ec5b Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 23 Dec 2020 15:06:20 -0600 Subject: [PATCH 05/24] Create dir for EmojiStealPolicy automatically --- lib/pleroma/application.ex | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index bd568d858..a1655721a 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -114,6 +114,9 @@ def start(_type, _args) do set_postgres_server_version() + # Requires Config.TransferTask so ConfigDB values are loaded + steal_emoji_policy_setup() + result end @@ -300,4 +303,20 @@ def limiters_setup do [Pleroma.Web.RichMedia.Helpers, Pleroma.Web.MediaProxy] |> Enum.each(&ConcurrentLimiter.new(&1, 1, 0)) end + + @spec steal_emoji_policy_setup() :: :ok + def steal_emoji_policy_setup() do + with true <- + Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy in Config.get!([:mrf, :policies]) do + path = + [:instance, :static_dir] + |> Config.get!() + |> Path.join("emoji/steal") + + if !File.exists?(path), do: File.mkdir_p!(path) + else + _ -> + :ok + end + end end From 72aeb2e73b77611504e1cd524a9cb47faef6816f Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 23 Dec 2020 15:16:58 -0600 Subject: [PATCH 06/24] Mark private --- lib/pleroma/application.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index a1655721a..e3edd05ca 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -305,7 +305,7 @@ def limiters_setup do end @spec steal_emoji_policy_setup() :: :ok - def steal_emoji_policy_setup() do + defp steal_emoji_policy_setup() do with true <- Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy in Config.get!([:mrf, :policies]) do path = From e02889edb29ca5631c346b59c299907e9f7b0161 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 23 Dec 2020 15:19:08 -0600 Subject: [PATCH 07/24] Add MRFs to the list of things that may need a soft reboot --- lib/pleroma/config/transfer_task.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/config/transfer_task.ex b/lib/pleroma/config/transfer_task.ex index a0d7b7d71..8a6d66891 100644 --- a/lib/pleroma/config/transfer_task.ex +++ b/lib/pleroma/config/transfer_task.ex @@ -28,7 +28,8 @@ defmodule Pleroma.Config.TransferTask do {:pleroma, Pleroma.Captcha, [:seconds_valid]}, {:pleroma, Pleroma.Upload, [:proxy_remote]}, {:pleroma, :instance, [:upload_limit]}, - {:pleroma, :gopher, [:enabled]} + {:pleroma, :gopher, [:enabled]}, + {:pleroma, :mrf, [:policies]} ] def start_link(restart_pleroma? \\ true) do From aafd7b44ceaf50788f12061ee88071a288155b95 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Thu, 24 Dec 2020 20:27:28 +0300 Subject: [PATCH 08/24] check dir existence in policy --- lib/pleroma/application.ex | 19 ----------- .../activity_pub/mrf/steal_emoji_policy.ex | 34 ++++++++++++------- 2 files changed, 22 insertions(+), 31 deletions(-) diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index e3edd05ca..bd568d858 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -114,9 +114,6 @@ def start(_type, _args) do set_postgres_server_version() - # Requires Config.TransferTask so ConfigDB values are loaded - steal_emoji_policy_setup() - result end @@ -303,20 +300,4 @@ def limiters_setup do [Pleroma.Web.RichMedia.Helpers, Pleroma.Web.MediaProxy] |> Enum.each(&ConcurrentLimiter.new(&1, 1, 0)) end - - @spec steal_emoji_policy_setup() :: :ok - defp steal_emoji_policy_setup() do - with true <- - Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy in Config.get!([:mrf, :policies]) do - path = - [:instance, :static_dir] - |> Config.get!() - |> Path.join("emoji/steal") - - if !File.exists?(path), do: File.mkdir_p!(path) - else - _ -> - :ok - end - end end diff --git a/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex b/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex index 2858af9eb..eabee6542 100644 --- a/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex @@ -14,18 +14,12 @@ defp remote_host?(host), do: host != Config.get([Pleroma.Web.Endpoint, :url, :ho defp accept_host?(host), do: host in Config.get([:mrf_steal_emoji, :hosts], []) - defp steal_emoji({shortcode, url}) do + defp steal_emoji({shortcode, url}, emoji_dir_path) do url = Pleroma.Web.MediaProxy.url(url) {:ok, response} = Pleroma.HTTP.get(url) size_limit = Config.get([:mrf_steal_emoji, :size_limit], 50_000) if byte_size(response.body) <= size_limit do - emoji_dir_path = - Config.get( - [:mrf_steal_emoji, :path], - Path.join(Config.get([:instance, :static_dir]), "emoji/stolen") - ) - extension = url |> URI.parse() @@ -35,11 +29,9 @@ defp steal_emoji({shortcode, url}) do file_path = Path.join([emoji_dir_path, shortcode <> (extension || ".png")]) - try do - :ok = File.write(file_path, response.body) - + with :ok <- File.write(file_path, response.body) do shortcode - rescue + else e -> Logger.warn("MRF.StealEmojiPolicy: Failed to write to #{file_path}: #{inspect(e)}") nil @@ -66,6 +58,16 @@ def filter(%{"object" => %{"emoji" => foreign_emojis, "actor" => actor}} = messa if remote_host?(host) and accept_host?(host) do installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end) + emoji_dir_path = + Config.get( + [:mrf_steal_emoji, :path], + Path.join(Config.get([:instance, :static_dir]), "emoji/stolen") + ) + + if not Config.get([:mrf_steal_emoji, :dir_exists?], false) do + create_dir(emoji_dir_path) + end + new_emojis = foreign_emojis |> Enum.filter(fn {shortcode, _url} -> shortcode not in installed_emoji end) @@ -76,7 +78,7 @@ def filter(%{"object" => %{"emoji" => foreign_emojis, "actor" => actor}} = messa !reject_emoji? end) - |> Enum.map(&steal_emoji(&1)) + |> Enum.map(&steal_emoji(&1, emoji_dir_path)) |> Enum.filter(& &1) if !Enum.empty?(new_emojis) do @@ -94,4 +96,12 @@ def filter(message), do: {:ok, message} def describe do {:ok, %{}} end + + defp create_dir(path) do + if not File.exists?(path) do + File.mkdir_p!(path) + end + + Config.put([:mrf_steal_emoji, :dir_exists?], true) + end end From 7bfb041658708f002e5da8f7b911b6011169dfef Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Fri, 25 Dec 2020 11:30:36 +0300 Subject: [PATCH 09/24] insreasing test coverage for StealEmojiPolicy --- .../activity_pub/mrf/steal_emoji_policy.ex | 64 +++++------ .../mrf/steal_emoji_policy_test.exs | 105 ++++++++++++------ 2 files changed, 104 insertions(+), 65 deletions(-) diff --git a/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex b/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex index eabee6542..0311ca433 100644 --- a/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex @@ -10,52 +10,53 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy do @moduledoc "Detect new emojis by their shortcode and steals them" @behaviour Pleroma.Web.ActivityPub.MRF - defp remote_host?(host), do: host != Config.get([Pleroma.Web.Endpoint, :url, :host]) - defp accept_host?(host), do: host in Config.get([:mrf_steal_emoji, :hosts], []) defp steal_emoji({shortcode, url}, emoji_dir_path) do url = Pleroma.Web.MediaProxy.url(url) - {:ok, response} = Pleroma.HTTP.get(url) - size_limit = Config.get([:mrf_steal_emoji, :size_limit], 50_000) - if byte_size(response.body) <= size_limit do - extension = - url - |> URI.parse() - |> Map.get(:path) - |> Path.basename() - |> Path.extname() + with {:ok, %{status: status} = response} when status in 200..299 <- Pleroma.HTTP.get(url) do + size_limit = Config.get([:mrf_steal_emoji, :size_limit], 50_000) - file_path = Path.join([emoji_dir_path, shortcode <> (extension || ".png")]) + if byte_size(response.body) <= size_limit do + extension = + url + |> URI.parse() + |> Map.get(:path) + |> Path.basename() + |> Path.extname() - with :ok <- File.write(file_path, response.body) do - shortcode + file_path = Path.join(emoji_dir_path, shortcode <> (extension || ".png")) + + case File.write(file_path, response.body) do + :ok -> + shortcode + + e -> + Logger.warn("MRF.StealEmojiPolicy: Failed to write to #{file_path}: #{inspect(e)}") + nil + end else - e -> - Logger.warn("MRF.StealEmojiPolicy: Failed to write to #{file_path}: #{inspect(e)}") - nil + Logger.debug( + "MRF.StealEmojiPolicy: :#{shortcode}: at #{url} (#{byte_size(response.body)} B) over size limit (#{ + size_limit + } B)" + ) + + nil end else - Logger.debug( - "MRF.StealEmojiPolicy: :#{shortcode}: at #{url} (#{byte_size(response.body)} B) over size limit (#{ - size_limit - } B)" - ) - - nil + e -> + Logger.warn("MRF.StealEmojiPolicy: Failed to fetch #{url}: #{inspect(e)}") + nil end - rescue - e -> - Logger.warn("MRF.StealEmojiPolicy: Failed to fetch #{url}: #{inspect(e)}") - nil end @impl true def filter(%{"object" => %{"emoji" => foreign_emojis, "actor" => actor}} = message) do host = URI.parse(actor).host - if remote_host?(host) and accept_host?(host) do + if host != Pleroma.Web.Endpoint.host() and accept_host?(host) do installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end) emoji_dir_path = @@ -70,10 +71,11 @@ def filter(%{"object" => %{"emoji" => foreign_emojis, "actor" => actor}} = messa new_emojis = foreign_emojis - |> Enum.filter(fn {shortcode, _url} -> shortcode not in installed_emoji end) + |> Enum.reject(fn {shortcode, _url} -> shortcode in installed_emoji end) |> Enum.filter(fn {shortcode, _url} -> reject_emoji? = - Config.get([:mrf_steal_emoji, :rejected_shortcodes], []) + [:mrf_steal_emoji, :rejected_shortcodes] + |> Config.get([]) |> Enum.find(false, fn regex -> String.match?(shortcode, regex) end) !reject_emoji? diff --git a/test/pleroma/web/activity_pub/mrf/steal_emoji_policy_test.exs b/test/pleroma/web/activity_pub/mrf/steal_emoji_policy_test.exs index 3f8222736..7665d00d0 100644 --- a/test/pleroma/web/activity_pub/mrf/steal_emoji_policy_test.exs +++ b/test/pleroma/web/activity_pub/mrf/steal_emoji_policy_test.exs @@ -6,6 +6,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do use Pleroma.DataCase alias Pleroma.Config + alias Pleroma.Emoji alias Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy setup_all do @@ -14,55 +15,91 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do end setup do - emoji_path = Path.join(Config.get([:instance, :static_dir]), "emoji/stolen") - File.rm_rf!(emoji_path) - File.mkdir!(emoji_path) + emoji_path = [:instance, :static_dir] |> Config.get() |> Path.join("emoji/stolen") - Pleroma.Emoji.reload() + Emoji.reload() + + message = %{ + "type" => "Create", + "object" => %{ + "emoji" => [{"firedfox", "https://example.org/emoji/firedfox.png"}], + "actor" => "https://example.org/users/admin" + } + } on_exit(fn -> File.rm_rf!(emoji_path) end) - :ok + [message: message, path: emoji_path] end - test "does nothing by default" do - installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end) - refute "firedfox" in installed_emoji + test "does nothing by default", %{message: message} do + refute "firedfox" in installed() - message = %{ - "type" => "Create", - "object" => %{ - "emoji" => [{"firedfox", "https://example.org/emoji/firedfox.png"}], - "actor" => "https://example.org/users/admin" - } - } + assert {:ok, _message} = StealEmojiPolicy.filter(message) - assert {:ok, message} == StealEmojiPolicy.filter(message) - - installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end) - refute "firedfox" in installed_emoji + refute "firedfox" in installed() end - test "Steals emoji on unknown shortcode from allowed remote host" do - installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end) - refute "firedfox" in installed_emoji + test "Steals emoji on unknown shortcode from allowed remote host", %{ + message: message, + path: path + } do + refute "firedfox" in installed() + refute File.exists?(path) - message = %{ - "type" => "Create", - "object" => %{ - "emoji" => [{"firedfox", "https://example.org/emoji/firedfox.png"}], - "actor" => "https://example.org/users/admin" - } - } + clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 284_468) - clear_config([:mrf_steal_emoji, :hosts], ["example.org"]) - clear_config([:mrf_steal_emoji, :size_limit], 284_468) + assert {:ok, _message} = StealEmojiPolicy.filter(message) - assert {:ok, message} == StealEmojiPolicy.filter(message) + assert "firedfox" in installed() + assert File.exists?(path) - installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end) - assert "firedfox" in installed_emoji + assert path + |> Path.join("firedfox.png") + |> File.exists?() end + + test "reject shortcode", %{message: message} do + refute "firedfox" in installed() + + clear_config(:mrf_steal_emoji, + hosts: ["example.org"], + size_limit: 284_468, + rejected_shortcodes: [~r/firedfox/] + ) + + assert {:ok, _message} = StealEmojiPolicy.filter(message) + + refute "firedfox" in installed() + end + + test "reject if size is above the limit", %{message: message} do + refute "firedfox" in installed() + + clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 50_000) + + assert {:ok, _message} = StealEmojiPolicy.filter(message) + + refute "firedfox" in installed() + end + + test "reject if host returns error", %{message: message} do + refute "firedfox" in installed() + + Tesla.Mock.mock(fn %{method: :get, url: "https://example.org/emoji/firedfox.png"} -> + {:ok, %Tesla.Env{status: 404, body: "Not found"}} + end) + + clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 284_468) + + ExUnit.CaptureLog.capture_log(fn -> + assert {:ok, _message} = StealEmojiPolicy.filter(message) + end) =~ "MRF.StealEmojiPolicy: Failed to fetch https://example.org/emoji/firedfox.png" + + refute "firedfox" in installed() + end + + defp installed, do: Emoji.get_all() |> Enum.map(fn {k, _} -> k end) end From dad76703aaf750e3811b0c963a92e39aa06b9c76 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Fri, 25 Dec 2020 11:34:09 +0300 Subject: [PATCH 10/24] not needed --- lib/pleroma/config/transfer_task.ex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/pleroma/config/transfer_task.ex b/lib/pleroma/config/transfer_task.ex index 8a6d66891..a0d7b7d71 100644 --- a/lib/pleroma/config/transfer_task.ex +++ b/lib/pleroma/config/transfer_task.ex @@ -28,8 +28,7 @@ defmodule Pleroma.Config.TransferTask do {:pleroma, Pleroma.Captcha, [:seconds_valid]}, {:pleroma, Pleroma.Upload, [:proxy_remote]}, {:pleroma, :instance, [:upload_limit]}, - {:pleroma, :gopher, [:enabled]}, - {:pleroma, :mrf, [:policies]} + {:pleroma, :gopher, [:enabled]} ] def start_link(restart_pleroma? \\ true) do From 546da68a1186ba4f8f901f9da1f1f6065cd9846a Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Fri, 25 Dec 2020 11:53:01 +0300 Subject: [PATCH 11/24] changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1604ab3a..716fbb75d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fix ability to update Pleroma Chat push notifications with PUT /api/v1/push/subscription and alert type pleroma:chat_mention - Emoji Reaction activity filtering from blocked and muted accounts. +- StealEmojiPolicy creates dir for emojis, if it doesn't exist. ## [2.2.1] - 2020-12-22 From 2e859794ee25bdf22216587f8c8260e47b2a038f Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Sun, 27 Dec 2020 21:58:15 +0300 Subject: [PATCH 12/24] non condition dir creation --- .../web/activity_pub/mrf/steal_emoji_policy.ex | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex b/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex index 0311ca433..788f21261 100644 --- a/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex @@ -65,9 +65,7 @@ def filter(%{"object" => %{"emoji" => foreign_emojis, "actor" => actor}} = messa Path.join(Config.get([:instance, :static_dir]), "emoji/stolen") ) - if not Config.get([:mrf_steal_emoji, :dir_exists?], false) do - create_dir(emoji_dir_path) - end + File.mkdir_p(emoji_dir_path) new_emojis = foreign_emojis @@ -98,12 +96,4 @@ def filter(message), do: {:ok, message} def describe do {:ok, %{}} end - - defp create_dir(path) do - if not File.exists?(path) do - File.mkdir_p!(path) - end - - Config.put([:mrf_steal_emoji, :dir_exists?], true) - end end From e1e7e4d379a67779a799049728d143eee2b88a7e Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 4 Jan 2021 13:38:31 +0100 Subject: [PATCH 13/24] Object: Rework how Object.normalize works Now it defaults to not fetching, and the option is named. --- lib/pleroma/activity.ex | 2 +- lib/pleroma/activity/ir/topics.ex | 2 +- lib/pleroma/conversation.ex | 3 +- lib/pleroma/emails/user_email.ex | 4 +- lib/pleroma/gopher/server.ex | 2 +- lib/pleroma/html.ex | 2 +- lib/pleroma/notification.ex | 4 +- lib/pleroma/object.ex | 33 ++++++++------- lib/pleroma/object/fetcher.ex | 4 +- .../activity_pub/activity_pub_controller.ex | 6 +-- lib/pleroma/web/activity_pub/builder.ex | 2 +- .../activity_pub/mrf/ensure_re_prepended.ex | 2 +- .../web/activity_pub/object_validator.ex | 2 +- lib/pleroma/web/activity_pub/publisher.ex | 2 +- lib/pleroma/web/activity_pub/side_effects.ex | 2 +- .../web/activity_pub/transmogrifier.ex | 10 +++-- .../web/activity_pub/views/object_view.ex | 4 +- lib/pleroma/web/common_api.ex | 12 +++--- lib/pleroma/web/common_api/utils.ex | 4 +- lib/pleroma/web/embed_controller.ex | 2 +- lib/pleroma/web/feed/feed_view.ex | 2 +- .../controllers/status_controller.ex | 4 +- .../mastodon_api/views/notification_view.ex | 2 +- .../web/mastodon_api/views/status_view.ex | 16 ++++---- .../web/o_status/o_status_controller.ex | 6 +-- .../controllers/chat_controller.ex | 2 +- .../controllers/emoji_reaction_controller.ex | 2 +- .../web/pleroma_api/views/scrobble_view.ex | 2 +- lib/pleroma/web/push/impl.ex | 2 +- lib/pleroma/web/rich_media/helpers.ex | 2 +- .../web/static_fe/static_fe_controller.ex | 2 +- lib/pleroma/web/streamer.ex | 2 +- test/mix/tasks/pleroma/user_test.exs | 4 +- test/pleroma/activity_test.exs | 4 +- test/pleroma/bbs/handler_test.exs | 6 +-- .../conversation/participation_test.exs | 4 +- test/pleroma/conversation_test.exs | 8 ++-- test/pleroma/html_test.exs | 12 +++--- test/pleroma/object_test.exs | 41 ++++++++++++------- .../user/welcome_chat_message_test.exs | 6 ++- test/pleroma/user/welcome_message_test.exs | 4 +- test/pleroma/user_test.exs | 6 +-- .../activity_pub_controller_test.exs | 28 ++++++------- .../web/activity_pub/activity_pub_test.exs | 6 +-- .../announce_validation_test.exs | 4 +- .../chat_validation_test.exs | 2 +- .../web/activity_pub/publisher_test.exs | 2 +- .../web/activity_pub/side_effects_test.exs | 6 +-- .../transmogrifier/announce_handling_test.exs | 4 +- .../transmogrifier/answer_handling_test.exs | 6 +-- .../transmogrifier/article_handling_test.exs | 4 +- .../transmogrifier/audio_handling_test.exs | 4 +- .../transmogrifier/delete_handling_test.exs | 4 +- .../transmogrifier/note_handling_test.exs | 24 +++++------ .../transmogrifier/question_handling_test.exs | 8 ++-- .../transmogrifier/video_handling_test.exs | 6 +-- .../web/activity_pub/transmogrifier_test.exs | 2 +- test/pleroma/web/activity_pub/utils_test.exs | 14 +++---- .../activity_pub/views/object_view_test.exs | 6 +-- .../controllers/chat_controller_test.exs | 6 +-- test/pleroma/web/common_api_test.exs | 24 +++++------ test/pleroma/web/feed/tag_controller_test.exs | 8 ++-- .../pleroma/web/feed/user_controller_test.exs | 2 +- .../controllers/poll_controller_test.exs | 14 +++---- .../controllers/search_controller_test.exs | 2 +- .../controllers/status_controller_test.exs | 6 ++- .../views/notification_view_test.exs | 2 +- .../web/mastodon_api/views/poll_view_test.exs | 12 +++--- .../mastodon_api/views/status_view_test.exs | 6 +-- .../web/o_status/o_status_controller_test.exs | 12 +++--- .../controllers/chat_controller_test.exs | 8 ++-- .../chat_message_reference_view_test.exs | 4 +- .../web/pleroma_api/views/chat_view_test.exs | 2 +- test/pleroma/web/push/impl_test.exs | 26 ++++++------ test/pleroma/web/streamer_test.exs | 4 +- .../scheduled_activity_worker_test.exs | 2 +- test/support/factory.ex | 2 +- 77 files changed, 269 insertions(+), 246 deletions(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 9d970a808..62fa9cca3 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -274,7 +274,7 @@ defp get_in_reply_to_activity_from_object(%Object{data: %{"inReplyTo" => ap_id}} defp get_in_reply_to_activity_from_object(_), do: nil def get_in_reply_to_activity(%Activity{} = activity) do - get_in_reply_to_activity_from_object(Object.normalize(activity)) + get_in_reply_to_activity_from_object(Object.normalize(activity, fetch: false)) end def normalize(obj) when is_map(obj), do: get_by_ap_id_with_object(obj["id"]) diff --git a/lib/pleroma/activity/ir/topics.ex b/lib/pleroma/activity/ir/topics.ex index fe2e8cb5c..6a26d7fdd 100644 --- a/lib/pleroma/activity/ir/topics.ex +++ b/lib/pleroma/activity/ir/topics.ex @@ -8,7 +8,7 @@ defmodule Pleroma.Activity.Ir.Topics do def get_activity_topics(activity) do activity - |> Object.normalize() + |> Object.normalize(fetch: false) |> generate_topics(activity) |> List.flatten() end diff --git a/lib/pleroma/conversation.ex b/lib/pleroma/conversation.ex index 77933f0be..e15259091 100644 --- a/lib/pleroma/conversation.ex +++ b/lib/pleroma/conversation.ex @@ -5,6 +5,7 @@ defmodule Pleroma.Conversation do alias Pleroma.Conversation.Participation alias Pleroma.Conversation.Participation.RecipientShip + alias Pleroma.Object alias Pleroma.Repo alias Pleroma.User use Ecto.Schema @@ -58,7 +59,7 @@ def maybe_create_recipientships(participation, activity) do def create_or_bump_for(activity, opts \\ []) do with true <- Pleroma.Web.ActivityPub.Visibility.is_direct?(activity), "Create" <- activity.data["type"], - object <- Pleroma.Object.normalize(activity), + %Object{} = object <- Object.normalize(activity, fetch: false), true <- object.data["type"] in ["Note", "Question"], ap_id when is_binary(ap_id) and byte_size(ap_id) > 0 <- object.data["context"] do {:ok, conversation} = create_for_ap_id(ap_id) diff --git a/lib/pleroma/emails/user_email.ex b/lib/pleroma/emails/user_email.ex index d3625dbf2..2b51d5b05 100644 --- a/lib/pleroma/emails/user_email.ex +++ b/lib/pleroma/emails/user_email.ex @@ -119,7 +119,7 @@ def digest_email(user) do notifications |> Enum.filter(&(&1.activity.data["type"] == "Create")) |> Enum.map(fn notification -> - object = Pleroma.Object.normalize(notification.activity) + object = Pleroma.Object.normalize(notification.activity, fetch: false) if not is_nil(object) do object = update_in(object.data["content"], &format_links/1) @@ -142,7 +142,7 @@ def digest_email(user) do if not is_nil(from) do %{ data: notification, - object: Pleroma.Object.normalize(notification.activity), + object: Pleroma.Object.normalize(notification.activity, fetch: false), from: User.get_by_ap_id(notification.activity.actor) } end diff --git a/lib/pleroma/gopher/server.ex b/lib/pleroma/gopher/server.ex index e9f54c4c0..8ac8d18c1 100644 --- a/lib/pleroma/gopher/server.ex +++ b/lib/pleroma/gopher/server.ex @@ -76,7 +76,7 @@ def render_activities(activities) do |> Enum.map(fn activity -> user = User.get_cached_by_ap_id(activity.data["actor"]) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) like_count = object.data["like_count"] || 0 announcement_count = object.data["announcement_count"] || 0 diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index c848c782c..c5ece7350 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -59,7 +59,7 @@ def get_cached_scrubbed_html_for_activity( key = "#{key}#{generate_scrubber_signature(scrubbers)}|#{activity.id}" @cachex.fetch!(:scrubber_cache, key, fn _key -> - object = Pleroma.Object.normalize(activity) + object = Pleroma.Object.normalize(activity, fetch: false) ensure_scrubbed_html(content, scrubbers, object.data["fake"] || false, callback) end) end diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index dd7a1c824..4efea9f7d 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -358,7 +358,7 @@ def dismiss(%{id: user_id} = _user, id) do def create_notifications(activity, options \\ []) def create_notifications(%Activity{data: %{"to" => _, "type" => "Create"}} = activity, options) do - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) if object && object.data["type"] == "Answer" do {:ok, []} @@ -625,7 +625,7 @@ def skip?(:recently_followed, %Activity{data: %{"type" => "Follow"}} = activity, def skip?(:filtered, %{data: %{"type" => type}}, _) when type in ["Follow", "Move"], do: false def skip?(:filtered, activity, user) do - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) cond do is_nil(object) -> diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index b4a994da9..4fb4ec364 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -108,39 +108,42 @@ defp warn_on_no_object_preloaded(ap_id) do Logger.debug("Backtrace: #{inspect(Process.info(:erlang.self(), :current_stacktrace))}") end - def normalize(_, fetch_remote \\ true, options \\ []) + def normalize(_, options \\ [fetch: false]) # If we pass an Activity to Object.normalize(), we can try to use the preloaded object. # Use this whenever possible, especially when walking graphs in an O(N) loop! - def normalize(%Object{} = object, _, _), do: object - def normalize(%Activity{object: %Object{} = object}, _, _), do: object + def normalize(%Object{} = object, _), do: object + def normalize(%Activity{object: %Object{} = object}, _), do: object # A hack for fake activities - def normalize(%Activity{data: %{"object" => %{"fake" => true} = data}}, _, _) do + def normalize(%Activity{data: %{"object" => %{"fake" => true} = data}}, _) do %Object{id: "pleroma:fake_object_id", data: data} end # No preloaded object - def normalize(%Activity{data: %{"object" => %{"id" => ap_id}}}, fetch_remote, _) do + def normalize(%Activity{data: %{"object" => %{"id" => ap_id}}}, options) do warn_on_no_object_preloaded(ap_id) - normalize(ap_id, fetch_remote) + normalize(ap_id, options) end # No preloaded object - def normalize(%Activity{data: %{"object" => ap_id}}, fetch_remote, _) do + def normalize(%Activity{data: %{"object" => ap_id}}, options) do warn_on_no_object_preloaded(ap_id) - normalize(ap_id, fetch_remote) + normalize(ap_id, options) end # Old way, try fetching the object through cache. - def normalize(%{"id" => ap_id}, fetch_remote, _), do: normalize(ap_id, fetch_remote) - def normalize(ap_id, false, _) when is_binary(ap_id), do: get_cached_by_ap_id(ap_id) + def normalize(%{"id" => ap_id}, options), do: normalize(ap_id, options) - def normalize(ap_id, true, options) when is_binary(ap_id) do - Fetcher.fetch_object_from_id!(ap_id, options) + def normalize(ap_id, options) when is_binary(ap_id) do + if Keyword.get(options, :fetch) do + Fetcher.fetch_object_from_id!(ap_id, options) + else + get_cached_by_ap_id(ap_id) + end end - def normalize(_, _, _), do: nil + def normalize(_, _), do: nil # Owned objects can only be accessed by their owner def authorize_access(%Object{data: %{"actor" => actor}}, %User{ap_id: ap_id}) do @@ -285,7 +288,7 @@ def decrease_replies_count(ap_id) do end def increase_vote_count(ap_id, name, actor) do - with %Object{} = object <- Object.normalize(ap_id), + with %Object{} = object <- Object.normalize(ap_id, fetch: false), "Question" <- object.data["type"] do key = if poll_is_multiple?(object), do: "anyOf", else: "oneOf" @@ -326,7 +329,7 @@ def local?(%Object{data: %{"id" => id}}) do end def replies(object, opts \\ []) do - object = Object.normalize(object) + object = Object.normalize(object, fetch: false) query = Object diff --git a/lib/pleroma/object/fetcher.ex b/lib/pleroma/object/fetcher.ex index 20d8f687d..18c383881 100644 --- a/lib/pleroma/object/fetcher.ex +++ b/lib/pleroma/object/fetcher.ex @@ -83,13 +83,13 @@ def fetch_object_from_id(id, options \\ []) do with {_, nil} <- {:fetch_object, Object.get_cached_by_ap_id(id)}, {_, true} <- {:allowed_depth, Federator.allowed_thread_distance?(options[:depth])}, {_, {:ok, data}} <- {:fetch, fetch_and_contain_remote_object_from_id(id)}, - {_, nil} <- {:normalize, Object.normalize(data, false)}, + {_, nil} <- {:normalize, Object.normalize(data, fetch: false)}, params <- prepare_activity_params(data), {_, :ok} <- {:containment, Containment.contain_origin(id, params)}, {_, {:ok, activity}} <- {:transmogrifier, Transmogrifier.handle_incoming(params, options)}, {_, _data, %Object{} = object} <- - {:object, data, Object.normalize(activity, false)} do + {:object, data, Object.normalize(activity, fetch: false)} do {:ok, object} else {:allowed_depth, false} -> diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index 7e5647f8f..8d9b69cc7 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -128,7 +128,7 @@ def activity(conn, _params) do end defp maybe_set_tracking_data(conn, %Activity{data: %{"type" => "Create"}} = activity) do - object_id = Object.normalize(activity).id + object_id = Object.normalize(activity, fetch: false).id assign(conn, :tracking_fun_data, object_id) end @@ -434,7 +434,7 @@ defp handle_user_activity( end defp handle_user_activity(%User{} = user, %{"type" => "Delete"} = params) do - with %Object{} = object <- Object.normalize(params["object"]), + with %Object{} = object <- Object.normalize(params["object"], fetch: false), true <- user.is_moderator || user.ap_id == object.data["actor"], {:ok, delete_data, _} <- Builder.delete(user, object.data["id"]), {:ok, delete, _} <- Pipeline.common_pipeline(delete_data, local: true) do @@ -445,7 +445,7 @@ defp handle_user_activity(%User{} = user, %{"type" => "Delete"} = params) do end defp handle_user_activity(%User{} = user, %{"type" => "Like"} = params) do - with %Object{} = object <- Object.normalize(params["object"]), + with %Object{} = object <- Object.normalize(params["object"], fetch: false), {_, {:ok, like_object, meta}} <- {:build_object, Builder.like(user, object)}, {_, {:ok, %Activity{} = activity, _meta}} <- {:common_pipeline, diff --git a/lib/pleroma/web/activity_pub/builder.ex b/lib/pleroma/web/activity_pub/builder.ex index e99f6fd83..74ddc2506 100644 --- a/lib/pleroma/web/activity_pub/builder.ex +++ b/lib/pleroma/web/activity_pub/builder.ex @@ -80,7 +80,7 @@ def undo(actor, object) do @spec delete(User.t(), String.t()) :: {:ok, map(), keyword()} def delete(actor, object_id) do - object = Object.normalize(object_id, false) + object = Object.normalize(object_id, fetch: false) user = !object && User.get_cached_by_ap_id(object_id) diff --git a/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex index 3bf70b894..c8c40c702 100644 --- a/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex +++ b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex @@ -31,7 +31,7 @@ def filter(%{"type" => "Create", "object" => child_object} = object) when is_map(child_object) do child = child_object["inReplyTo"] - |> Object.normalize(child_object["inReplyTo"]) + |> Object.normalize(fetch: false) |> filter_by_summary(child_object) object = Map.put(object, "object", child) diff --git a/lib/pleroma/web/activity_pub/object_validator.ex b/lib/pleroma/web/activity_pub/object_validator.ex index ce8e7341b..244753c02 100644 --- a/lib/pleroma/web/activity_pub/object_validator.ex +++ b/lib/pleroma/web/activity_pub/object_validator.ex @@ -288,7 +288,7 @@ def fetch_actor(object) do def fetch_actor_and_object(object) do fetch_actor(object) - Object.normalize(object["object"], true) + Object.normalize(object["object"], fetch: true) :ok end end diff --git a/lib/pleroma/web/activity_pub/publisher.ex b/lib/pleroma/web/activity_pub/publisher.ex index 5ab3562bf..dca28e5bd 100644 --- a/lib/pleroma/web/activity_pub/publisher.ex +++ b/lib/pleroma/web/activity_pub/publisher.ex @@ -129,7 +129,7 @@ defp recipients(actor, activity) do fetchers = with %Activity{data: %{"type" => "Delete"}} <- activity, - %Object{id: object_id} <- Object.normalize(activity), + %Object{id: object_id} <- Object.normalize(activity, fetch: false), fetchers <- User.get_delivered_users_by_object_id(object_id), _ <- Delivery.delete_all_by_object_id(object_id) do fetchers diff --git a/lib/pleroma/web/activity_pub/side_effects.ex b/lib/pleroma/web/activity_pub/side_effects.ex index 55c99ad0c..679ea1a4d 100644 --- a/lib/pleroma/web/activity_pub/side_effects.ex +++ b/lib/pleroma/web/activity_pub/side_effects.ex @@ -268,7 +268,7 @@ def handle(%{data: %{"type" => "EmojiReact"}} = object, meta) do @impl true def handle(%{data: %{"type" => "Delete", "object" => deleted_object}} = object, meta) do deleted_object = - Object.normalize(deleted_object, false) || + Object.normalize(deleted_object, fetch: false) || User.get_cached_by_ap_id(deleted_object) result = diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 565d32433..dd0e1f13c 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -653,7 +653,9 @@ def handle_incoming(_, _), do: :error @spec get_obj_helper(String.t(), Keyword.t()) :: {:ok, Object.t()} | nil def get_obj_helper(id, options \\ []) do - case Object.normalize(id, true, options) do + options = Keyword.put(options, :fetch, true) + + case Object.normalize(id, options) do %Object{} = object -> {:ok, object} _ -> nil end @@ -672,7 +674,7 @@ def get_embedded_obj_helper(%{"attributedTo" => attributed_to, "id" => object_id "actor" => attributed_to, "object" => data }) do - {:ok, Object.normalize(activity)} + {:ok, Object.normalize(activity, fetch: false)} else _ -> get_obj_helper(object_id) end @@ -763,7 +765,7 @@ def prepare_outgoing(%{"type" => activity_type, "object" => object_id} = data) when activity_type in ["Create", "Listen"] do object = object_id - |> Object.normalize() + |> Object.normalize(fetch: false) |> Map.get(:data) |> prepare_object @@ -779,7 +781,7 @@ def prepare_outgoing(%{"type" => activity_type, "object" => object_id} = data) def prepare_outgoing(%{"type" => "Announce", "actor" => ap_id, "object" => object_id} = data) do object = object_id - |> Object.normalize() + |> Object.normalize(fetch: false) data = if Visibility.is_private?(object) && object.data["actor"] == ap_id do diff --git a/lib/pleroma/web/activity_pub/views/object_view.ex b/lib/pleroma/web/activity_pub/views/object_view.ex index e555e9999..44bc5621b 100644 --- a/lib/pleroma/web/activity_pub/views/object_view.ex +++ b/lib/pleroma/web/activity_pub/views/object_view.ex @@ -18,7 +18,7 @@ def render("object.json", %{object: %Object{} = object}) do def render("object.json", %{object: %Activity{data: %{"type" => activity_type}} = activity}) when activity_type in ["Create", "Listen"] do base = Pleroma.Web.ActivityPub.Utils.make_json_ld_header() - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) additional = Transmogrifier.prepare_object(activity.data) @@ -29,7 +29,7 @@ def render("object.json", %{object: %Activity{data: %{"type" => activity_type}} def render("object.json", %{object: %Activity{} = activity}) do base = Pleroma.Web.ActivityPub.Utils.make_json_ld_header() - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) additional = Transmogrifier.prepare_object(activity.data) diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index e59254791..87343df75 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -142,7 +142,7 @@ def delete(activity_id, user) do with {_, %Activity{data: %{"object" => _, "type" => "Create"}} = activity} <- {:find_activity, Activity.get_by_id(activity_id)}, {_, %Object{} = object, _} <- - {:find_object, Object.normalize(activity, false), activity}, + {:find_object, Object.normalize(activity, fetch: false), activity}, true <- User.superuser?(user) || user.ap_id == object.data["actor"], {:ok, delete_data, _} <- Builder.delete(user, object.data["id"]), {:ok, delete, _} <- Pipeline.common_pipeline(delete_data, local: true) do @@ -173,7 +173,7 @@ def delete(activity_id, user) do def repeat(id, user, params \\ %{}) do with %Activity{data: %{"type" => "Create"}} = activity <- Activity.get_by_id(id), - object = %Object{} <- Object.normalize(activity, false), + object = %Object{} <- Object.normalize(activity, fetch: false), {_, nil} <- {:existing_announce, Utils.get_existing_announce(user.ap_id, object)}, public = public_announce?(object, params), {:ok, announce, _} <- Builder.announce(user, object, public: public), @@ -191,7 +191,7 @@ def repeat(id, user, params \\ %{}) do def unrepeat(id, user) do with {_, %Activity{data: %{"type" => "Create"}} = activity} <- {:find_activity, Activity.get_by_id(id)}, - %Object{} = note <- Object.normalize(activity, false), + %Object{} = note <- Object.normalize(activity, fetch: false), %Activity{} = announce <- Utils.get_existing_announce(user.ap_id, note), {:ok, undo, _} <- Builder.undo(user, announce), {:ok, activity, _} <- Pipeline.common_pipeline(undo, local: true) do @@ -253,7 +253,7 @@ def favorite_helper(user, id) do def unfavorite(id, user) do with {_, %Activity{data: %{"type" => "Create"}} = activity} <- {:find_activity, Activity.get_by_id(id)}, - %Object{} = note <- Object.normalize(activity, false), + %Object{} = note <- Object.normalize(activity, fetch: false), %Activity{} = like <- Utils.get_existing_like(user.ap_id, note), {:ok, undo, _} <- Builder.undo(user, like), {:ok, activity, _} <- Pipeline.common_pipeline(undo, local: true) do @@ -266,7 +266,7 @@ def unfavorite(id, user) do def react_with_emoji(id, user, emoji) do with %Activity{} = activity <- Activity.get_by_id(id), - object <- Object.normalize(activity), + object <- Object.normalize(activity, fetch: false), {:ok, emoji_react, _} <- Builder.emoji_react(user, object, emoji), {:ok, activity, _} <- Pipeline.common_pipeline(emoji_react, local: true) do {:ok, activity} @@ -377,7 +377,7 @@ def get_visibility(_, in_reply_to, _), do: {"public", get_replied_to_visibility( def get_replied_to_visibility(nil), do: nil def get_replied_to_visibility(activity) do - with %Object{} = object <- Object.normalize(activity) do + with %Object{} = object <- Object.normalize(activity, fetch: false) do Visibility.get_visibility(object) end end diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 1c74ea787..ddbdb3376 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -319,7 +319,7 @@ def make_note_data(%ActivityDraft{} = draft) do defp add_in_reply_to(object, nil), do: object defp add_in_reply_to(object, in_reply_to) do - with %Object{} = in_reply_to_object <- Object.normalize(in_reply_to) do + with %Object{} = in_reply_to_object <- Object.normalize(in_reply_to, fetch: false) do Map.put(object, "inReplyTo", in_reply_to_object.data["id"]) else _ -> object @@ -399,7 +399,7 @@ def maybe_notify_mentioned_recipients( %Activity{data: %{"to" => _to, "type" => type} = data} = activity ) when type == "Create" do - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) object_data = cond do diff --git a/lib/pleroma/web/embed_controller.ex b/lib/pleroma/web/embed_controller.ex index f6b8a5ee1..f8623d4d6 100644 --- a/lib/pleroma/web/embed_controller.ex +++ b/lib/pleroma/web/embed_controller.ex @@ -31,7 +31,7 @@ def show(conn, %{"id" => id}) do end defp get_counts(%Activity{} = activity) do - %Object{data: data} = Object.normalize(activity) + %Object{data: data} = Object.normalize(activity, fetch: false) %{ likes: Map.get(data, "like_count", 0), diff --git a/lib/pleroma/web/feed/feed_view.ex b/lib/pleroma/web/feed/feed_view.ex index 30e0a2a55..bc0114e26 100644 --- a/lib/pleroma/web/feed/feed_view.ex +++ b/lib/pleroma/web/feed/feed_view.ex @@ -23,7 +23,7 @@ def pub_date(date) when is_binary(date) do def pub_date(%DateTime{} = date), do: Timex.format!(date, "{RFC822}") def prepare_activity(activity, opts \\ []) do - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) actor = if opts[:actor] do diff --git a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex index 9e3a584f0..acca9d3b2 100644 --- a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex @@ -318,7 +318,7 @@ def favourited_by(%{assigns: %{user: user}} = conn, %{id: id}) do with true <- Pleroma.Config.get([:instance, :show_reactions]), %Activity{} = activity <- Activity.get_by_id_with_object(id), {:visible, true} <- {:visible, Visibility.visible_for_user?(activity, user)}, - %Object{data: %{"likes" => likes}} <- Object.normalize(activity) do + %Object{data: %{"likes" => likes}} <- Object.normalize(activity, fetch: false) do users = User |> Ecto.Query.where([u], u.ap_id in ^likes) @@ -339,7 +339,7 @@ def reblogged_by(%{assigns: %{user: user}} = conn, %{id: id}) do with %Activity{} = activity <- Activity.get_by_id_with_object(id), {:visible, true} <- {:visible, Visibility.visible_for_user?(activity, user)}, %Object{data: %{"announcements" => announces, "id" => ap_id}} <- - Object.normalize(activity) do + Object.normalize(activity, fetch: false) do announces = "Announce" |> Activity.Queries.by_type() diff --git a/lib/pleroma/web/mastodon_api/views/notification_view.ex b/lib/pleroma/web/mastodon_api/views/notification_view.ex index 5b06a6b51..9ec0f311d 100644 --- a/lib/pleroma/web/mastodon_api/views/notification_view.ex +++ b/lib/pleroma/web/mastodon_api/views/notification_view.ex @@ -139,7 +139,7 @@ defp put_emoji(response, activity) do end defp put_chat_message(response, activity, reading_user, opts) do - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) author = User.get_cached_by_ap_id(object.data["actor"]) chat = Pleroma.Chat.get(reading_user.id, author.ap_id) cm_ref = MessageReference.for_chat_and_object(chat, object) diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 2301e21cf..b8a35cd38 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -41,7 +41,7 @@ defp get_replied_to_activities(activities) do activities |> Enum.map(fn %{data: %{"type" => "Create"}} = activity -> - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) object && object.data["inReplyTo"] != "" && object.data["inReplyTo"] _ -> @@ -51,7 +51,7 @@ defp get_replied_to_activities(activities) do |> Activity.create_by_object_ap_id_with_object() |> Repo.all() |> Enum.reduce(%{}, fn activity, acc -> - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) if object, do: Map.put(acc, object.data["id"], activity), else: acc end) end @@ -65,7 +65,7 @@ defp get_context_id(%{data: %{"context" => context}}) when is_binary(context), defp get_context_id(_), do: nil defp reblogged?(activity, user) do - object = Object.normalize(activity) || %{} + object = Object.normalize(activity, fetch: false) || %{} present?(user && user.ap_id in (object.data["announcements"] || [])) end @@ -84,7 +84,7 @@ def render("index.json", opts) do parent_activities = activities |> Enum.filter(&(&1.data["type"] == "Announce" && &1.data["object"])) - |> Enum.map(&Object.normalize(&1).data["id"]) + |> Enum.map(&Object.normalize(&1, fetch: false).data["id"]) |> Activity.create_by_object_ap_id() |> Activity.with_preloaded_object(:left) |> Activity.with_preloaded_bookmark(reading_user) @@ -124,7 +124,7 @@ def render( ) do user = CommonAPI.get_user(activity.data["actor"]) created_at = Utils.to_masto_date(activity.data["published"]) - activity_object = Object.normalize(activity) + activity_object = Object.normalize(activity, fetch: false) reblogged_parent_activity = if opts[:parent_activities] do @@ -193,7 +193,7 @@ def render( end def render("show.json", %{activity: %{data: %{"object" => _object}} = activity} = opts) do - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) user = CommonAPI.get_user(activity.data["actor"]) user_follower_address = user.follower_address @@ -451,7 +451,7 @@ def render("context.json", %{activity: activity, activities: activities, user: u end def get_reply_to(activity, %{replied_to_activities: replied_to_activities}) do - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) with nil <- replied_to_activities[object.data["inReplyTo"]] do # If user didn't participate in the thread @@ -460,7 +460,7 @@ def get_reply_to(activity, %{replied_to_activities: replied_to_activities}) do end def get_reply_to(%{data: %{"object" => _object}} = activity, _) do - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) if object.data["inReplyTo"] && object.data["inReplyTo"] != "" do Activity.get_create_by_object_ap_id(object.data["inReplyTo"]) diff --git a/lib/pleroma/web/o_status/o_status_controller.ex b/lib/pleroma/web/o_status/o_status_controller.ex index 668ae0ea4..ea182d698 100644 --- a/lib/pleroma/web/o_status/o_status_controller.ex +++ b/lib/pleroma/web/o_status/o_status_controller.ex @@ -74,14 +74,14 @@ def notice(%{assigns: %{format: format}} = conn, %{"id" => id}) do cond do format in ["json", "activity+json"] -> if activity.local do - %{data: %{"id" => redirect_url}} = Object.normalize(activity) + %{data: %{"id" => redirect_url}} = Object.normalize(activity, fetch: false) redirect(conn, external: redirect_url) else {:error, :not_found} end activity.data["type"] == "Create" -> - %Object{} = object = Object.normalize(activity) + %Object{} = object = Object.normalize(activity, fetch: false) RedirectController.redirector_with_meta( conn, @@ -112,7 +112,7 @@ def notice_player(conn, %{"id" => id}) do with %Activity{data: %{"type" => "Create"}} = activity <- Activity.get_by_id_with_object(id), true <- Visibility.is_public?(activity), {_, true} <- {:visible?, Visibility.visible_for_user?(activity, _reading_user = nil)}, - %Object{} = object <- Object.normalize(activity), + %Object{} = object <- Object.normalize(activity, fetch: false), %{data: %{"attachment" => [%{"url" => [url | _]} | _]}} <- object, true <- String.starts_with?(url["mediaType"], ["audio", "video"]) do conn diff --git a/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex b/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex index bfc0a1f19..1825e2168 100644 --- a/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex +++ b/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex @@ -82,7 +82,7 @@ def post_chat_message( media_id: params[:media_id], idempotency_key: idempotency_key(conn) ), - message <- Object.normalize(activity, false), + message <- Object.normalize(activity, fetch: false), cm_ref <- MessageReference.for_chat_and_object(chat, message) do conn |> put_view(MessageReferenceView) diff --git a/lib/pleroma/web/pleroma_api/controllers/emoji_reaction_controller.ex b/lib/pleroma/web/pleroma_api/controllers/emoji_reaction_controller.ex index dd9c746dc..dee04f045 100644 --- a/lib/pleroma/web/pleroma_api/controllers/emoji_reaction_controller.ex +++ b/lib/pleroma/web/pleroma_api/controllers/emoji_reaction_controller.ex @@ -29,7 +29,7 @@ def index(%{assigns: %{user: user}} = conn, %{id: activity_id} = params) do with true <- Pleroma.Config.get([:instance, :show_reactions]), %Activity{} = activity <- Activity.get_by_id_with_object(activity_id), %Object{data: %{"reactions" => reactions}} when is_list(reactions) <- - Object.normalize(activity) do + Object.normalize(activity, fetch: false) do reactions = reactions |> filter(params) diff --git a/lib/pleroma/web/pleroma_api/views/scrobble_view.ex b/lib/pleroma/web/pleroma_api/views/scrobble_view.ex index 95bd4c368..98b95c721 100644 --- a/lib/pleroma/web/pleroma_api/views/scrobble_view.ex +++ b/lib/pleroma/web/pleroma_api/views/scrobble_view.ex @@ -15,7 +15,7 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleView do alias Pleroma.Web.MastodonAPI.AccountView def render("show.json", %{activity: %Activity{data: %{"type" => "Listen"}} = activity} = opts) do - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) user = CommonAPI.get_user(activity.data["actor"]) created_at = Utils.to_masto_date(activity.data["published"]) diff --git a/lib/pleroma/web/push/impl.ex b/lib/pleroma/web/push/impl.ex index 82152dffa..a9c46f63a 100644 --- a/lib/pleroma/web/push/impl.ex +++ b/lib/pleroma/web/push/impl.ex @@ -32,7 +32,7 @@ def perform( mastodon_type = notification.type gcm_api_key = Application.get_env(:web_push_encryption, :gcm_api_key) avatar_url = User.avatar_url(actor) - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) user = User.get_cached_by_id(user_id) direct_conversation_id = Activity.direct_conversation_id(activity, user) diff --git a/lib/pleroma/web/rich_media/helpers.ex b/lib/pleroma/web/rich_media/helpers.ex index 442bf9995..566fc8c8a 100644 --- a/lib/pleroma/web/rich_media/helpers.ex +++ b/lib/pleroma/web/rich_media/helpers.ex @@ -69,7 +69,7 @@ def fetch_data_for_object(object) do def fetch_data_for_activity(%Activity{data: %{"type" => "Create"}} = activity) do with true <- Config.get([:rich_media, :enabled]), - %Object{} = object <- Object.normalize(activity) do + %Object{} = object <- Object.normalize(activity, fetch: false) do fetch_data_for_object(object) else _ -> %{} diff --git a/lib/pleroma/web/static_fe/static_fe_controller.ex b/lib/pleroma/web/static_fe/static_fe_controller.ex index bdec0897a..404cb0473 100644 --- a/lib/pleroma/web/static_fe/static_fe_controller.ex +++ b/lib/pleroma/web/static_fe/static_fe_controller.ex @@ -122,7 +122,7 @@ defp not_found(conn, message) do end defp get_counts(%Activity{} = activity) do - %Object{data: data} = Object.normalize(activity) + %Object{data: data} = Object.normalize(activity, fetch: false) %{ likes: data["like_count"] || 0, diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex index 7d4a1304a..1fb8ac1c5 100644 --- a/lib/pleroma/web/streamer.ex +++ b/lib/pleroma/web/streamer.ex @@ -151,7 +151,7 @@ def filtered_by_user?(%User{} = user, %Activity{} = item, streamed_type) do recipients = MapSet.new(item.recipients) domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.domain_blocks) - with parent <- Object.normalize(item) || item, + with parent <- Object.normalize(item, fetch: false) || item, true <- Enum.all?([blocked_ap_ids, muted_ap_ids], &(item.actor not in &1)), true <- item.data["type"] != "Announce" || item.actor not in reblog_muted_ap_ids, true <- diff --git a/test/mix/tasks/pleroma/user_test.exs b/test/mix/tasks/pleroma/user_test.exs index de8ab27e5..9f898d8f3 100644 --- a/test/mix/tasks/pleroma/user_test.exs +++ b/test/mix/tasks/pleroma/user_test.exs @@ -114,7 +114,7 @@ test "a remote user's create activity is deleted when the object has been pruned {:ok, post} = CommonAPI.post(user, %{status: "uguu"}) {:ok, post2} = CommonAPI.post(user2, %{status: "test"}) - obj = Object.normalize(post2) + obj = Object.normalize(post2, fetch: false) {:ok, like_object, meta} = Pleroma.Web.ActivityPub.Builder.like(user, obj) @@ -130,7 +130,7 @@ test "a remote user's create activity is deleted when the object has been pruned clear_config([:instance, :federating], true) - object = Object.normalize(post) + object = Object.normalize(post, fetch: false) Object.prune(object) with_mock Pleroma.Web.Federator, diff --git a/test/pleroma/activity_test.exs b/test/pleroma/activity_test.exs index 105f9f766..acaa9adb4 100644 --- a/test/pleroma/activity_test.exs +++ b/test/pleroma/activity_test.exs @@ -25,7 +25,7 @@ test "returns an activity by it's AP id" do test "returns activities by it's objects AP ids" do activity = insert(:note_activity) - object_data = Object.normalize(activity).data + object_data = Object.normalize(activity, fetch: false).data [found_activity] = Activity.get_all_create_by_object_ap_id(object_data["id"]) @@ -34,7 +34,7 @@ test "returns activities by it's objects AP ids" do test "returns the activity that created an object" do activity = insert(:note_activity) - object_data = Object.normalize(activity).data + object_data = Object.normalize(activity, fetch: false).data found_activity = Activity.get_create_by_object_ap_id(object_data["id"]) diff --git a/test/pleroma/bbs/handler_test.exs b/test/pleroma/bbs/handler_test.exs index bba8fab0f..8033828f0 100644 --- a/test/pleroma/bbs/handler_test.exs +++ b/test/pleroma/bbs/handler_test.exs @@ -54,7 +54,7 @@ test "posting" do ) assert activity.actor == user.ap_id - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["content"] == "this is a test post" end @@ -63,7 +63,7 @@ test "replying" do another_user = insert(:user) {:ok, activity} = CommonAPI.post(another_user, %{status: "this is a test post"}) - activity_object = Object.normalize(activity) + activity_object = Object.normalize(activity, fetch: false) output = capture_io(fn -> @@ -82,7 +82,7 @@ test "replying" do assert reply.actor == user.ap_id - reply_object_data = Object.normalize(reply).data + reply_object_data = Object.normalize(reply, fetch: false).data assert reply_object_data["content"] == "this is a reply" assert reply_object_data["inReplyTo"] == activity_object.data["id"] end diff --git a/test/pleroma/conversation/participation_test.exs b/test/pleroma/conversation/participation_test.exs index 122b10486..917fb2b98 100644 --- a/test/pleroma/conversation/participation_test.exs +++ b/test/pleroma/conversation/participation_test.exs @@ -175,8 +175,8 @@ test "gets all the participations for a user, ordered by updated at descending" assert [participation_one, participation_two] = Participation.for_user(user) - object2 = Pleroma.Object.normalize(activity_two) - object3 = Pleroma.Object.normalize(activity_three) + object2 = Pleroma.Object.normalize(activity_two, fetch: false) + object3 = Pleroma.Object.normalize(activity_three, fetch: false) user = Repo.get(Pleroma.User, user.id) diff --git a/test/pleroma/conversation_test.exs b/test/pleroma/conversation_test.exs index 359aa6840..4643140dc 100644 --- a/test/pleroma/conversation_test.exs +++ b/test/pleroma/conversation_test.exs @@ -48,7 +48,7 @@ test "public posts don't create conversations" do user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: "Hey"}) - object = Pleroma.Object.normalize(activity) + object = Pleroma.Object.normalize(activity, fetch: false) context = object.data["context"] conversation = Conversation.get_for_ap_id(context) @@ -64,7 +64,7 @@ test "it creates or updates a conversation and participations for a given DM" do {:ok, activity} = CommonAPI.post(har, %{status: "Hey @#{jafnhar.nickname}", visibility: "direct"}) - object = Pleroma.Object.normalize(activity) + object = Pleroma.Object.normalize(activity, fetch: false) context = object.data["context"] conversation = @@ -86,7 +86,7 @@ test "it creates or updates a conversation and participations for a given DM" do in_reply_to_status_id: activity.id }) - object = Pleroma.Object.normalize(activity) + object = Pleroma.Object.normalize(activity, fetch: false) context = object.data["context"] conversation_two = @@ -110,7 +110,7 @@ test "it creates or updates a conversation and participations for a given DM" do in_reply_to_status_id: activity.id }) - object = Pleroma.Object.normalize(activity) + object = Pleroma.Object.normalize(activity, fetch: false) context = object.data["context"] conversation_three = diff --git a/test/pleroma/html_test.exs b/test/pleroma/html_test.exs index 9737f2458..3a926f077 100644 --- a/test/pleroma/html_test.exs +++ b/test/pleroma/html_test.exs @@ -175,7 +175,7 @@ test "extracts the url" do "I think I just found the best github repo https://github.com/komeiji-satori/Dress" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) {:ok, url} = HTML.extract_first_external_url_from_object(object) assert url == "https://github.com/komeiji-satori/Dress" end @@ -190,7 +190,7 @@ test "skips mentions" do "@#{other_user.nickname} install misskey! https://github.com/syuilo/misskey/blob/develop/docs/setup.en.md" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) {:ok, url} = HTML.extract_first_external_url_from_object(object) assert url == "https://github.com/syuilo/misskey/blob/develop/docs/setup.en.md" @@ -206,7 +206,7 @@ test "skips hashtags" do status: "#cofe https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) {:ok, url} = HTML.extract_first_external_url_from_object(object) assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140" @@ -222,7 +222,7 @@ test "skips microformats hashtags" do content_type: "text/html" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) {:ok, url} = HTML.extract_first_external_url_from_object(object) assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140" @@ -233,7 +233,7 @@ test "does not crash when there is an HTML entity in a link" do {:ok, activity} = CommonAPI.post(user, %{status: "\"http://cofe.com/?boomer=ok&foo=bar\""}) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert {:ok, nil} = HTML.extract_first_external_url_from_object(object) end @@ -247,7 +247,7 @@ test "skips attachment links" do "image.png" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert {:ok, nil} = HTML.extract_first_external_url_from_object(object) end diff --git a/test/pleroma/object_test.exs b/test/pleroma/object_test.exs index 5d4e6fb84..fe7f37e7c 100644 --- a/test/pleroma/object_test.exs +++ b/test/pleroma/object_test.exs @@ -256,23 +256,22 @@ test "With custom base_url" do end describe "normalizer" do - test "fetches unknown objects by default" do - %Object{} = - object = Object.normalize("http://mastodon.example.org/@admin/99541947525187367") - - assert object.data["url"] == "http://mastodon.example.org/@admin/99541947525187367" + @url "http://mastodon.example.org/@admin/99541947525187367" + test "does not fetch unknown objects by default" do + assert nil == Object.normalize(@url) end - test "fetches unknown objects when fetch_remote is explicitly true" do - %Object{} = - object = Object.normalize("http://mastodon.example.org/@admin/99541947525187367", true) + test "fetches unknown objects when fetch is explicitly true" do + %Object{} = object = Object.normalize(@url, fetch: true) - assert object.data["url"] == "http://mastodon.example.org/@admin/99541947525187367" + assert object.data["url"] == @url end - test "does not fetch unknown objects when fetch_remote is false" do + test "does not fetch unknown objects when fetch is false" do assert is_nil( - Object.normalize("http://mastodon.example.org/@admin/99541947525187367", false) + Object.normalize(@url, + fetch: false + ) ) end end @@ -310,7 +309,10 @@ test "refetches if the time since the last refetch is greater than the interval" mock_modified: mock_modified } do %Object{} = - object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d") + object = + Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d", + fetch: true + ) Object.set_cache(object) @@ -332,7 +334,10 @@ test "refetches if the time since the last refetch is greater than the interval" test "returns the old object if refetch fails", %{mock_modified: mock_modified} do %Object{} = - object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d") + object = + Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d", + fetch: true + ) Object.set_cache(object) @@ -355,7 +360,10 @@ test "does not refetch if the time since the last refetch is greater than the in mock_modified: mock_modified } do %Object{} = - object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d") + object = + Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d", + fetch: true + ) Object.set_cache(object) @@ -377,7 +385,10 @@ test "does not refetch if the time since the last refetch is greater than the in test "preserves internal fields on refetch", %{mock_modified: mock_modified} do %Object{} = - object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d") + object = + Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d", + fetch: true + ) Object.set_cache(object) diff --git a/test/pleroma/user/welcome_chat_message_test.exs b/test/pleroma/user/welcome_chat_message_test.exs index fe26d6e4d..0b744fc1b 100644 --- a/test/pleroma/user/welcome_chat_message_test.exs +++ b/test/pleroma/user/welcome_chat_message_test.exs @@ -28,8 +28,10 @@ test "send a chat welcome message" do {:ok, %Pleroma.Activity{} = activity} = WelcomeChatMessage.post_message(user) assert user.ap_id in activity.recipients - assert Pleroma.Object.normalize(activity).data["type"] == "ChatMessage" - assert Pleroma.Object.normalize(activity).data["content"] == "Hello, welcome to Blob/Cat!" + assert Pleroma.Object.normalize(activity, fetch: false).data["type"] == "ChatMessage" + + assert Pleroma.Object.normalize(activity, fetch: false).data["content"] == + "Hello, welcome to Blob/Cat!" end end end diff --git a/test/pleroma/user/welcome_message_test.exs b/test/pleroma/user/welcome_message_test.exs index 3cd6f5cb7..a1779ddec 100644 --- a/test/pleroma/user/welcome_message_test.exs +++ b/test/pleroma/user/welcome_message_test.exs @@ -28,7 +28,9 @@ test "send a direct welcome message" do {:ok, %Pleroma.Activity{} = activity} = WelcomeMessage.post_message(user) assert user.ap_id in activity.recipients assert activity.data["directMessage"] == true - assert Pleroma.Object.normalize(activity).data["content"] =~ "Hello. Welcome to Pleroma" + + assert Pleroma.Object.normalize(activity, fetch: false).data["content"] =~ + "Hello. Welcome to Pleroma" end end end diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs index 40bbcad0b..f0f5d6071 100644 --- a/test/pleroma/user_test.exs +++ b/test/pleroma/user_test.exs @@ -438,7 +438,7 @@ test "it sends a welcome message if it is set" do activity = Repo.one(Pleroma.Activity) assert registered_user.ap_id in activity.recipients - assert Object.normalize(activity).data["content"] =~ "direct message" + assert Object.normalize(activity, fetch: false).data["content"] =~ "direct message" assert activity.actor == welcome_user.ap_id end @@ -454,7 +454,7 @@ test "it sends a welcome chat message if it is set" do activity = Repo.one(Pleroma.Activity) assert registered_user.ap_id in activity.recipients - assert Object.normalize(activity).data["content"] =~ "chat message" + assert Object.normalize(activity, fetch: false).data["content"] =~ "chat message" assert activity.actor == welcome_user.ap_id end @@ -493,7 +493,7 @@ test "it sends a welcome chat message when Simple policy applied to local instan activity = Repo.one(Pleroma.Activity) assert registered_user.ap_id in activity.recipients - assert Object.normalize(activity).data["content"] =~ "chat message" + assert Object.normalize(activity, fetch: false).data["content"] =~ "chat message" assert activity.actor == welcome_user.ap_id end diff --git a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs index 0063d0482..03aed794f 100644 --- a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs @@ -219,7 +219,7 @@ test "it doesn't return a local-only object", %{conn: conn} do assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post) - object = Object.normalize(post, false) + object = Object.normalize(post, fetch: false) uuid = String.split(object.data["id"], "/") |> List.last() conn = @@ -712,7 +712,7 @@ test "it rejects reads from other users", %{conn: conn} do test "it returns a note activity in a collection", %{conn: conn} do note_activity = insert(:direct_note_activity) - note_object = Object.normalize(note_activity) + note_object = Object.normalize(note_activity, fetch: false) user = User.get_cached_by_ap_id(hd(note_activity.data["to"])) conn = @@ -999,7 +999,7 @@ test "it returns 200 even if there're no activities", %{conn: conn} do test "it returns a note activity in a collection", %{conn: conn} do note_activity = insert(:note_activity) - note_object = Object.normalize(note_activity) + note_object = Object.normalize(note_activity, fetch: false) user = User.get_cached_by_ap_id(note_activity.data["actor"]) conn = @@ -1073,7 +1073,7 @@ test "it inserts an incoming create activity into the database", %{ assert Activity.get_by_ap_id(result["id"]) assert result["object"] - assert %Object{data: object} = Object.normalize(result["object"]) + assert %Object{data: object} = Object.normalize(result["object"], fetch: false) assert object["content"] == activity["object"]["content"] end @@ -1109,7 +1109,7 @@ test "it inserts an incoming sensitive activity into the database", %{ assert Activity.get_by_ap_id(response["id"]) assert response["object"] - assert %Object{data: response_object} = Object.normalize(response["object"]) + assert %Object{data: response_object} = Object.normalize(response["object"], fetch: false) assert response_object["sensitive"] == true assert response_object["content"] == activity["object"]["content"] @@ -1137,7 +1137,7 @@ test "it rejects an incoming activity with bogus type", %{conn: conn, activity: test "it erects a tombstone when receiving a delete activity", %{conn: conn} do note_activity = insert(:note_activity) - note_object = Object.normalize(note_activity) + note_object = Object.normalize(note_activity, fetch: false) user = User.get_cached_by_ap_id(note_activity.data["actor"]) data = %{ @@ -1162,7 +1162,7 @@ test "it erects a tombstone when receiving a delete activity", %{conn: conn} do test "it rejects delete activity of object from other actor", %{conn: conn} do note_activity = insert(:note_activity) - note_object = Object.normalize(note_activity) + note_object = Object.normalize(note_activity, fetch: false) user = insert(:user) data = %{ @@ -1183,7 +1183,7 @@ test "it rejects delete activity of object from other actor", %{conn: conn} do test "it increases like count when receiving a like action", %{conn: conn} do note_activity = insert(:note_activity) - note_object = Object.normalize(note_activity) + note_object = Object.normalize(note_activity, fetch: false) user = User.get_cached_by_ap_id(note_activity.data["actor"]) data = %{ @@ -1240,7 +1240,7 @@ test "it doesn't spreads faulty attributedTo or actor fields", %{ assert cirno_outbox["attributedTo"] == nil assert cirno_outbox["actor"] == cirno.ap_id - assert cirno_object = Object.normalize(cirno_outbox["object"]) + assert cirno_object = Object.normalize(cirno_outbox["object"], fetch: false) assert cirno_object.data["actor"] == cirno.ap_id assert cirno_object.data["attributedTo"] == cirno.ap_id end @@ -1503,7 +1503,7 @@ test "does not require authentication", %{conn: conn} do test "it tracks a signed object fetch", %{conn: conn} do user = insert(:user, local: false) activity = insert(:note_activity) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url()) @@ -1519,7 +1519,7 @@ test "it tracks a signed object fetch", %{conn: conn} do test "it tracks a signed activity fetch", %{conn: conn} do user = insert(:user, local: false) activity = insert(:note_activity) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) activity_path = String.trim_leading(activity.data["id"], Pleroma.Web.Endpoint.url()) @@ -1536,7 +1536,7 @@ test "it tracks a signed object fetch when the json is cached", %{conn: conn} do user = insert(:user, local: false) other_user = insert(:user, local: false) activity = insert(:note_activity) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url()) @@ -1560,7 +1560,7 @@ test "it tracks a signed activity fetch when the json is cached", %{conn: conn} user = insert(:user, local: false) other_user = insert(:user, local: false) activity = insert(:note_activity) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) activity_path = String.trim_leading(activity.data["id"], Pleroma.Web.Endpoint.url()) @@ -1650,7 +1650,7 @@ test "POST /api/ap/upload_media", %{conn: conn} do assert activity_response["actor"] == user.ap_id assert %Object{data: %{"attachment" => [attachment]}} = - Object.normalize(activity_response["object"]) + Object.normalize(activity_response["object"], fetch: false) assert attachment["type"] == "Document" assert attachment["name"] == desc diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs index 9eb7ae86b..0d30ba20b 100644 --- a/test/pleroma/web/activity_pub/activity_pub_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_test.exs @@ -321,7 +321,7 @@ test "adds a context when none is there" do } {:ok, %Activity{} = activity} = ActivityPub.insert(data) - object = Pleroma.Object.normalize(activity) + object = Pleroma.Object.normalize(activity, fetch: false) assert is_binary(activity.data["context"]) assert is_binary(object.data["context"]) @@ -344,7 +344,7 @@ test "adds an id to a given object if it lacks one and is a note and inserts it } {:ok, %Activity{} = activity} = ActivityPub.insert(data) - assert object = Object.normalize(activity) + assert object = Object.normalize(activity, fetch: false) assert is_binary(object.data["id"]) end end @@ -678,7 +678,7 @@ test "doesn't return announce activities with blocked users in 'cc'" do {:ok, activity_two} = CommonAPI.post(blockee, %{status: "hey! @#{friend.nickname}"}) - assert object = Pleroma.Object.normalize(activity_two) + assert object = Pleroma.Object.normalize(activity_two, fetch: false) data = %{ "actor" => friend.ap_id, diff --git a/test/pleroma/web/activity_pub/object_validators/announce_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/announce_validation_test.exs index 9613dea9b..da60ac844 100644 --- a/test/pleroma/web/activity_pub/object_validators/announce_validation_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/announce_validation_test.exs @@ -18,7 +18,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnnounceValidationTest do announcer = insert(:user) {:ok, post_activity} = CommonAPI.post(user, %{status: "uguu"}) - object = Object.normalize(post_activity, false) + object = Object.normalize(post_activity, fetch: false) {:ok, valid_announce, []} = Builder.announce(announcer, object) %{ @@ -81,7 +81,7 @@ test "returns an error if the actor can't announce the object", %{ {:ok, post_activity} = CommonAPI.post(user, %{status: "a secret post", visibility: "private"}) - object = Object.normalize(post_activity, false) + object = Object.normalize(post_activity, fetch: false) # Another user can't announce it {:ok, announce, []} = Builder.announce(announcer, object, public: false) diff --git a/test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs index d7e299224..941a8a3e3 100644 --- a/test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs @@ -17,7 +17,7 @@ test "it is invalid if the object already exists" do user = insert(:user) recipient = insert(:user) {:ok, activity} = CommonAPI.post_chat_message(user, recipient, "hey") - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) {:ok, create_data, _} = Builder.create(user, object.data, [recipient.ap_id]) diff --git a/test/pleroma/web/activity_pub/publisher_test.exs b/test/pleroma/web/activity_pub/publisher_test.exs index 3503d25b2..6d15e1640 100644 --- a/test/pleroma/web/activity_pub/publisher_test.exs +++ b/test/pleroma/web/activity_pub/publisher_test.exs @@ -322,7 +322,7 @@ test "publish to url with with different ports" do actor = insert(:user) note_activity = insert(:note_activity, user: actor) - object = Object.normalize(note_activity) + object = Object.normalize(note_activity, fetch: false) activity_path = String.trim_leading(note_activity.data["id"], Pleroma.Web.Endpoint.url()) object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url()) diff --git a/test/pleroma/web/activity_pub/side_effects_test.exs b/test/pleroma/web/activity_pub/side_effects_test.exs index 297fc0b84..16a598002 100644 --- a/test/pleroma/web/activity_pub/side_effects_test.exs +++ b/test/pleroma/web/activity_pub/side_effects_test.exs @@ -139,7 +139,7 @@ test "it uses a given changeset to update", %{user: user, update: update} do {:ok, op} = CommonAPI.post(other_user, %{status: "big oof"}) {:ok, post} = CommonAPI.post(user, %{status: "hey", in_reply_to_id: op}) {:ok, favorite} = CommonAPI.favorite(user, post.id) - object = Object.normalize(post) + object = Object.normalize(post, fetch: false) {:ok, delete_data, _meta} = Builder.delete(user, object.data["id"]) {:ok, delete_user_data, _meta} = Builder.delete(user, user.ap_id) {:ok, delete, _meta} = ActivityPub.persist(delete_data, local: true) @@ -182,7 +182,7 @@ test "it handles object deletions", %{ user = User.get_by_id(user.id) assert user.note_count == 0 - object = Object.normalize(op.data["object"], false) + object = Object.normalize(op.data["object"], fetch: false) assert object.data["repliesCount"] == 0 end @@ -211,7 +211,7 @@ test "it handles object deletions when the object itself has been pruned", %{ user = User.get_by_id(user.id) assert user.note_count == 0 - object = Object.normalize(op.data["object"], false) + object = Object.normalize(op.data["object"], fetch: false) assert object.data["repliesCount"] == 0 end diff --git a/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs index c06bbc5e9..6ec7e1a0a 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs @@ -130,7 +130,7 @@ test "it works for incoming announces with an inlined activity" do assert data["id"] == "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity" - object = Object.normalize(data["object"]) + object = Object.normalize(data["object"], fetch: false) assert object.data["id"] == "http://mastodon.example.org/@admin/99541947525187368" assert object.data["content"] == "this is a private toot" @@ -158,7 +158,7 @@ test "it does not clobber the addressing on announce activities" do data = File.read!("test/fixtures/mastodon-announce.json") |> Jason.decode!() - |> Map.put("object", Object.normalize(activity).data["id"]) + |> Map.put("object", Object.normalize(activity, fetch: false).data["id"]) |> Map.put("to", ["http://mastodon.example.org/users/admin/followers"]) |> Map.put("cc", []) diff --git a/test/pleroma/web/activity_pub/transmogrifier/answer_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/answer_handling_test.exs index a1c2ba28a..c6483ccaf 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/answer_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/answer_handling_test.exs @@ -26,7 +26,7 @@ test "incoming, rewrites Note to Answer and increments vote counters" do poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10} }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["repliesCount"] == nil data = @@ -37,7 +37,7 @@ test "incoming, rewrites Note to Answer and increments vote counters" do |> Kernel.put_in(["object", "to"], user.ap_id) {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - answer_object = Object.normalize(activity) + answer_object = Object.normalize(activity, fetch: false) assert answer_object.data["type"] == "Answer" assert answer_object.data["inReplyTo"] == object.data["id"] @@ -62,7 +62,7 @@ test "outgoing, rewrites Answer to Note" do poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10} }) - poll_object = Object.normalize(poll_activity) + poll_object = Object.normalize(poll_activity, fetch: false) # TODO: Replace with CommonAPI vote creation when implemented data = File.read!("test/fixtures/mastodon-vote.json") diff --git a/test/pleroma/web/activity_pub/transmogrifier/article_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/article_handling_test.exs index b0ae804c5..26216f7fc 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/article_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/article_handling_test.exs @@ -25,7 +25,7 @@ test "Pterotype (Wordpress Plugin) Article" do {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) - object = Object.normalize(data["object"]) + object = Object.normalize(data["object"], fetch: false) assert object.data["name"] == "The end is near: Mastodon plans to drop OStatus support" @@ -75,7 +75,7 @@ test "Prismo Article" do data = File.read!("test/fixtures/prismo-url-map.json") |> Jason.decode!() {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) - object = Object.normalize(data["object"]) + object = Object.normalize(data["object"], fetch: false) assert object.data["url"] == "https://prismo.news/posts/83" end diff --git a/test/pleroma/web/activity_pub/transmogrifier/audio_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/audio_handling_test.exs index 7a2ac5d4d..ac80d0ddd 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/audio_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/audio_handling_test.exs @@ -35,7 +35,7 @@ test "it works for incoming listens" do {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["title"] == "lain radio episode 1" assert object.data["artist"] == "lain" @@ -57,7 +57,7 @@ test "Funkwhale Audio object" do {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - assert object = Object.normalize(activity, false) + assert object = Object.normalize(activity, fetch: false) assert object.data["to"] == ["https://www.w3.org/ns/activitystreams#Public"] diff --git a/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs index 1f9e73ff8..6dd508894 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs @@ -40,7 +40,7 @@ test "it works for incoming deletes" do assert actor == deleting_user.ap_id # Objects are replaced by a tombstone object. - object = Object.normalize(activity.data["object"]) + object = Object.normalize(activity.data["object"], fetch: false) assert object.data["type"] == "Tombstone" end @@ -48,7 +48,7 @@ test "it works for incoming when the object has been pruned" do activity = insert(:note_activity) {:ok, object} = - Object.normalize(activity.data["object"]) + Object.normalize(activity.data["object"], fetch: false) |> Repo.delete() # TODO: mock cachex diff --git a/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs index b4a006aec..b61e5013a 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs @@ -28,7 +28,7 @@ test "it works for incoming notices with tag not being an array (kroeg)" do data = File.read!("test/fixtures/kroeg-array-less-emoji.json") |> Jason.decode!() {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) - object = Object.normalize(data["object"]) + object = Object.normalize(data["object"], fetch: false) assert object.data["emoji"] == %{ "icon_e_smile" => "https://puckipedia.com/forum/images/smilies/icon_e_smile.png" @@ -37,7 +37,7 @@ test "it works for incoming notices with tag not being an array (kroeg)" do data = File.read!("test/fixtures/kroeg-array-less-hashtag.json") |> Jason.decode!() {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) - object = Object.normalize(data["object"]) + object = Object.normalize(data["object"], fetch: false) assert "test" in object.data["tag"] end @@ -66,7 +66,7 @@ test "it cleans up incoming notices which are not really DMs" do assert data["to"] == [] assert data["cc"] == to - object_data = Object.normalize(activity).data + object_data = Object.normalize(activity, fetch: false).data assert object_data["to"] == [] assert object_data["cc"] == to @@ -78,7 +78,7 @@ test "it ignores an incoming notice if we already have it" do data = File.read!("test/fixtures/mastodon-post-activity.json") |> Jason.decode!() - |> Map.put("object", Object.normalize(activity).data) + |> Map.put("object", Object.normalize(activity, fetch: false).data) {:ok, returned_activity} = Transmogrifier.handle_incoming(data) @@ -97,7 +97,7 @@ test "it fetches reply-to activities if we don't have them" do data = Map.put(data, "object", object) {:ok, returned_activity} = Transmogrifier.handle_incoming(data) - returned_object = Object.normalize(returned_activity, false) + returned_object = Object.normalize(returned_activity, fetch: false) assert %Activity{} = Activity.get_create_by_object_ap_id( @@ -123,7 +123,7 @@ test "it does not fetch reply-to activities beyond max replies depth limit" do allowed_thread_distance?: fn _ -> false end do {:ok, returned_activity} = Transmogrifier.handle_incoming(data) - returned_object = Object.normalize(returned_activity, false) + returned_object = Object.normalize(returned_activity, fetch: false) refute Activity.get_create_by_object_ap_id( "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment" @@ -179,7 +179,7 @@ test "it works for incoming notices" do assert data["actor"] == "http://mastodon.example.org/users/admin" - object_data = Object.normalize(data["object"]).data + object_data = Object.normalize(data["object"], fetch: false).data assert object_data["id"] == "http://mastodon.example.org/users/admin/statuses/99512778738411822" @@ -209,7 +209,7 @@ test "it works for incoming notices without the sensitive property but an nsfw h {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) - object_data = Object.normalize(data["object"], false).data + object_data = Object.normalize(data["object"], fetch: false).data assert object_data["sensitive"] == true end @@ -218,7 +218,7 @@ test "it works for incoming notices with hashtags" do data = File.read!("test/fixtures/mastodon-post-activity-hashtag.json") |> Jason.decode!() {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) - object = Object.normalize(data["object"]) + object = Object.normalize(data["object"], fetch: false) assert Enum.at(object.data["tag"], 2) == "moo" end @@ -227,7 +227,7 @@ test "it works for incoming notices with contentMap" do data = File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Jason.decode!() {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) - object = Object.normalize(data["object"]) + object = Object.normalize(data["object"], fetch: false) assert object.data["content"] == "

@lain

" @@ -237,7 +237,7 @@ 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!() {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) - object = Object.normalize(data["object"]) + object = Object.normalize(data["object"], fetch: false) assert object.data["content"] == "

henlo from my Psion netBook

message sent from my Psion netBook

" @@ -725,7 +725,7 @@ test "sets `replies` collection with a limited number of self-replies" do in_reply_to_status_id: id1 }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) replies_uris = Enum.map([self_reply1, self_reply2], fn a -> a.object.data["id"] end) assert %{"type" => "Collection", "items" => ^replies_uris} = diff --git a/test/pleroma/web/activity_pub/transmogrifier/question_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/question_handling_test.exs index 47f92cf4d..ae470f984 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/question_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/question_handling_test.exs @@ -22,7 +22,7 @@ test "Mastodon Question activity" do {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) assert object.data["url"] == "https://mastodon.sdf.org/@rinpatch/102070944809637304" @@ -65,7 +65,7 @@ test "Mastodon Question activity" do {:ok, reply_activity} = CommonAPI.post(user, %{status: "hewwo", in_reply_to_id: activity.id}) - reply_object = Object.normalize(reply_activity, false) + reply_object = Object.normalize(reply_activity, fetch: false) assert reply_object.data["context"] == object.data["context"] assert reply_object.data["context_id"] == object.data["context_id"] @@ -101,7 +101,7 @@ test "Mastodon Question activity with HTML tags in plaintext" do |> Kernel.put_in(["object", "oneOf"], options) {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) assert Enum.sort(object.data["oneOf"]) == Enum.sort(options) end @@ -147,7 +147,7 @@ test "Mastodon Question activity with custom emojis" do |> Kernel.put_in(["object", "tag"], tag) {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) assert object.data["oneOf"] == options diff --git a/test/pleroma/web/activity_pub/transmogrifier/video_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/video_handling_test.exs index 57411fafa..be4ac4c13 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/video_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/video_handling_test.exs @@ -24,7 +24,7 @@ test "skip converting the content when it is nil" do {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - assert object = Object.normalize(activity, false) + assert object = Object.normalize(activity, fetch: false) assert object.data["content"] == nil end @@ -34,7 +34,7 @@ test "it converts content of object to html" do {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - assert object = Object.normalize(activity, false) + assert object = Object.normalize(activity, fetch: false) assert object.data["content"] == "

Après avoir mené avec un certain succès la campagne « Dégooglisons Internet » en 2014, l’association Framasoft annonce fin 2019 arrêter progressivement un certain nombre de ses services alternatifs aux GAFAM. Pourquoi ?

Transcription par @aprilorg ici : https://www.april.org/deframasoftisons-internet-pierre-yves-gosset-framasoft

" @@ -70,7 +70,7 @@ test "it remaps video URLs as attachments if necessary" do {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - assert object = Object.normalize(activity, false) + assert object = Object.normalize(activity, fetch: false) assert object.data["attachment"] == [ %{ diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs index 66ea7664a..741147bf4 100644 --- a/test/pleroma/web/activity_pub/transmogrifier_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier_test.exs @@ -56,7 +56,7 @@ test "it accepts Flag activities" do other_user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: "test post"}) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) note_obj = %{ "type" => "Note", diff --git a/test/pleroma/web/activity_pub/utils_test.exs b/test/pleroma/web/activity_pub/utils_test.exs index 2263b6091..83668caa4 100644 --- a/test/pleroma/web/activity_pub/utils_test.exs +++ b/test/pleroma/web/activity_pub/utils_test.exs @@ -165,7 +165,7 @@ test "fetches existing votes" do } }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) {:ok, votes, object} = CommonAPI.vote(other_user, object, [0, 1]) assert Enum.sort(Utils.get_existing_votes(other_user.ap_id, object)) == Enum.sort(votes) end @@ -183,7 +183,7 @@ test "fetches only Create activities" do } }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) {:ok, [vote], object} = CommonAPI.vote(other_user, object, [0]) {:ok, _activity} = CommonAPI.favorite(user, activity.id) [fetched_vote] = Utils.get_existing_votes(other_user.ap_id, object) @@ -242,7 +242,7 @@ test "updates the state of the given follow activity" do test "updates likes" do user = insert(:user) activity = insert(:note_activity) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert {:ok, updated_object} = Utils.update_element_in_object( @@ -302,7 +302,7 @@ test "removes ap_id from likes" do describe "get_existing_like/2" do test "fetches existing like" do note_activity = insert(:note_activity) - assert object = Object.normalize(note_activity) + assert object = Object.normalize(note_activity, fetch: false) user = insert(:user) refute Utils.get_existing_like(user.ap_id, object) @@ -320,7 +320,7 @@ test "returns nil if announce not found" do test "fetches existing announce" do note_activity = insert(:note_activity) - assert object = Object.normalize(note_activity) + assert object = Object.normalize(note_activity, fetch: false) actor = insert(:user) {:ok, announce} = CommonAPI.repeat(note_activity.id, actor) @@ -412,7 +412,7 @@ test "returns false" do describe "lazy_put_activity_defaults/2" do test "returns map with id and published data" do note_activity = insert(:note_activity) - object = Object.normalize(note_activity) + object = Object.normalize(note_activity, fetch: false) res = Utils.lazy_put_activity_defaults(%{"context" => object.data["id"]}) assert res["context"] == object.data["id"] assert res["context_id"] == object.id @@ -431,7 +431,7 @@ test "returns map with fake id and published data" do test "returns activity data with object" do note_activity = insert(:note_activity) - object = Object.normalize(note_activity) + object = Object.normalize(note_activity, fetch: false) res = Utils.lazy_put_activity_defaults(%{ diff --git a/test/pleroma/web/activity_pub/views/object_view_test.exs b/test/pleroma/web/activity_pub/views/object_view_test.exs index f0389845d..967acad19 100644 --- a/test/pleroma/web/activity_pub/views/object_view_test.exs +++ b/test/pleroma/web/activity_pub/views/object_view_test.exs @@ -24,7 +24,7 @@ test "renders a note object" do test "renders a note activity" do note = insert(:note_activity) - object = Object.normalize(note) + object = Object.normalize(note, fetch: false) result = ObjectView.render("object.json", %{object: note}) @@ -56,7 +56,7 @@ test "renders `replies` collection for a note activity" do test "renders a like activity" do note = insert(:note_activity) - object = Object.normalize(note) + object = Object.normalize(note, fetch: false) user = insert(:user) {:ok, like_activity} = CommonAPI.favorite(user, note.id) @@ -70,7 +70,7 @@ test "renders a like activity" do test "renders an announce activity" do note = insert(:note_activity) - object = Object.normalize(note) + object = Object.normalize(note, fetch: false) user = insert(:user) {:ok, announce_activity} = CommonAPI.repeat(note.id, user) diff --git a/test/pleroma/web/admin_api/controllers/chat_controller_test.exs b/test/pleroma/web/admin_api/controllers/chat_controller_test.exs index dead1c09e..00e67a91c 100644 --- a/test/pleroma/web/admin_api/controllers/chat_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/chat_controller_test.exs @@ -36,7 +36,7 @@ test "it deletes a message from the chat", %{conn: conn, admin: admin} do {:ok, message} = CommonAPI.post_chat_message(user, recipient, "Hello darkness my old friend") - object = Object.normalize(message, false) + object = Object.normalize(message, fetch: false) chat = Chat.get(user.id, recipient.ap_id) recipient_chat = Chat.get(recipient.id, user.ap_id) @@ -143,7 +143,7 @@ test "it returns a chat", %{conn: conn} do recipient = insert(:user) {:ok, message} = CommonAPI.post_chat_message(user, recipient, "Yo") - object = Object.normalize(message, false) + object = Object.normalize(message, fetch: false) chat = Chat.get(user.id, recipient.ap_id) cm_ref = MessageReference.for_chat_and_object(chat, object) @@ -183,7 +183,7 @@ test "GET /api/pleroma/admin/chats/:id", %{conn: conn, chat: chat} do recipient = insert(:user) {:ok, message} = CommonAPI.post_chat_message(user, recipient, "Yo") - object = Object.normalize(message, false) + object = Object.normalize(message, fetch: false) chat = Chat.get(user.id, recipient.ap_id) cm_ref = MessageReference.for_chat_and_object(chat, object) diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index 585b2c174..52d6ccd0c 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -39,7 +39,7 @@ test "it posts a poll" do poll: %{expires_in: 600, options: ["reimu", "marisa"]} }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["type"] == "Question" assert object.data["oneOf"] |> length() == 2 @@ -174,7 +174,7 @@ test "it adds html newlines" do assert other_user.ap_id not in activity.recipients - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) assert object.data["content"] == "uguu
uguuu" end @@ -194,7 +194,7 @@ test "it linkifies" do assert other_user.ap_id not in activity.recipients - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) assert object.data["content"] == "https://example.org is the site of Object.prune() with_mock Pleroma.Web.Federator, @@ -491,7 +491,7 @@ test "it de-duplicates tags" do user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: "#2hu #2HU"}) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["tag"] == ["2hu"] end @@ -500,7 +500,7 @@ test "it adds emoji in the object" do user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: ":firefox:"}) - assert Object.normalize(activity).data["emoji"]["firefox"] + assert Object.normalize(activity, fetch: false).data["emoji"]["firefox"] end describe "posting" do @@ -539,7 +539,7 @@ test "it filters out obviously bad tags when accepting a post as HTML" do content_type: "text/html" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["content"] == "

2hu

alert('xss')" assert object.data["source"] == post @@ -556,7 +556,7 @@ test "it filters out obviously bad tags when accepting a post as Markdown" do content_type: "text/markdown" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["content"] == "

2hu

alert('xss')" assert object.data["source"] == post @@ -1211,7 +1211,7 @@ test "does not allow to vote twice" do poll: %{options: ["Yes", "No"], expires_in: 20} }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) {:ok, _, object} = CommonAPI.vote(other_user, object, [0]) @@ -1231,7 +1231,7 @@ test "returns a valid activity" do length: 180_000 }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["title"] == "lain radio episode 1" @@ -1250,7 +1250,7 @@ test "respects visibility=private" do visibility: "private" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["title"] == "lain radio episode 1" diff --git a/test/pleroma/web/feed/tag_controller_test.exs b/test/pleroma/web/feed/tag_controller_test.exs index b4abcf6f2..48dc3b404 100644 --- a/test/pleroma/web/feed/tag_controller_test.exs +++ b/test/pleroma/web/feed/tag_controller_test.exs @@ -24,7 +24,7 @@ test "gets a feed (ATOM)", %{conn: conn} do user = insert(:user) {:ok, activity1} = CommonAPI.post(user, %{status: "yeah #PleromaArt"}) - object = Object.normalize(activity1) + object = Object.normalize(activity1, fetch: false) object_data = Map.put(object.data, "attachment", [ @@ -91,7 +91,7 @@ test "gets a feed (RSS)", %{conn: conn} do user = insert(:user) {:ok, activity1} = CommonAPI.post(user, %{status: "yeah #PleromaArt"}) - object = Object.normalize(activity1) + object = Object.normalize(activity1, fetch: false) object_data = Map.put(object.data, "attachment", [ @@ -147,8 +147,8 @@ test "gets a feed (RSS)", %{conn: conn} do "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4" ] - obj1 = Object.normalize(activity1) - obj2 = Object.normalize(activity2) + obj1 = Object.normalize(activity1, fetch: false) + obj2 = Object.normalize(activity2, fetch: false) assert xpath(xml, ~x"//channel/item/description/text()"sl) == [ HtmlEntities.decode(FeedView.activity_content(obj2.data)), diff --git a/test/pleroma/web/feed/user_controller_test.exs b/test/pleroma/web/feed/user_controller_test.exs index 16f002717..50445862b 100644 --- a/test/pleroma/web/feed/user_controller_test.exs +++ b/test/pleroma/web/feed/user_controller_test.exs @@ -58,7 +58,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do ) note_activity2 = insert(:note_activity, note: note2) - object = Object.normalize(note_activity) + object = Object.normalize(note_activity, fetch: false) [user: user, object: object, max_id: note_activity2.id] end diff --git a/test/pleroma/web/mastodon_api/controllers/poll_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/poll_controller_test.exs index 95e27623d..71cea8462 100644 --- a/test/pleroma/web/mastodon_api/controllers/poll_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/poll_controller_test.exs @@ -20,7 +20,7 @@ test "returns poll entity for object id", %{user: user, conn: conn} do poll: %{options: ["what Mastodon't", "n't what Mastodoes"], expires_in: 20} }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) conn = get(conn, "/api/v1/polls/#{object.id}") @@ -39,7 +39,7 @@ test "does not expose polls for private statuses", %{conn: conn} do visibility: "private" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) conn = get(conn, "/api/v1/polls/#{object.id}") @@ -63,7 +63,7 @@ test "votes are added to the poll", %{conn: conn} do } }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) conn = conn @@ -85,7 +85,7 @@ test "author can't vote", %{user: user, conn: conn} do poll: %{options: ["Yes", "No"], expires_in: 20} }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert conn |> put_req_header("content-type", "application/json") @@ -106,7 +106,7 @@ test "does not allow multiple choices on a single-choice question", %{conn: conn poll: %{options: ["half empty", "half full"], expires_in: 20} }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert conn |> put_req_header("content-type", "application/json") @@ -129,7 +129,7 @@ test "does not allow choice index to be greater than options count", %{conn: con poll: %{options: ["Yes", "No"], expires_in: 20} }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) conn = conn @@ -158,7 +158,7 @@ test "returns 404 when poll is private and not available for user", %{conn: conn visibility: "private" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) conn = conn diff --git a/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs index 1045ab265..664bdce01 100644 --- a/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs @@ -309,7 +309,7 @@ test "search doesn't show statuses that it shouldn't", %{conn: conn} do }) capture_log(fn -> - q = Object.normalize(activity).data["id"] + q = Object.normalize(activity, fetch: false).data["id"] results = conn diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs index de542e5df..ffff0ae9d 100644 --- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs @@ -800,7 +800,7 @@ test "if user is authenticated", %{local: local, remote: remote} do test "when you created it" do %{user: author, conn: conn} = oauth_access(["write:statuses"]) activity = insert(:note_activity, user: author) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) content = object.data["content"] source = object.data["source"] @@ -1374,7 +1374,9 @@ test "Repeated posts that are replies incorrectly have in_reply_to_id null", %{c activity = Activity.get_by_id_with_object(id) - assert Object.normalize(activity).data["inReplyTo"] == Object.normalize(replied_to).data["id"] + assert Object.normalize(activity, fetch: false).data["inReplyTo"] == + Object.normalize(replied_to, fetch: false).data["id"] + assert Activity.get_in_reply_to_activity(activity).id == replied_to.id # Reblog from the third user diff --git a/test/pleroma/web/mastodon_api/views/notification_view_test.exs b/test/pleroma/web/mastodon_api/views/notification_view_test.exs index 9de11a87e..79dd23a51 100644 --- a/test/pleroma/web/mastodon_api/views/notification_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/notification_view_test.exs @@ -44,7 +44,7 @@ test "ChatMessage notification" do {:ok, [notification]} = Notification.create_notifications(activity) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) chat = Chat.get(recipient.id, user.ap_id) cm_ref = MessageReference.for_chat_and_object(chat, object) diff --git a/test/pleroma/web/mastodon_api/views/poll_view_test.exs b/test/pleroma/web/mastodon_api/views/poll_view_test.exs index c655ca438..f83e5b368 100644 --- a/test/pleroma/web/mastodon_api/views/poll_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/poll_view_test.exs @@ -29,7 +29,7 @@ test "renders a poll" do } }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) expected = %{ emojis: [], @@ -72,7 +72,7 @@ test "detects if it is multiple choice" do voter = insert(:user) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) {:ok, _votes, object} = CommonAPI.vote(voter, object, [0, 1]) @@ -98,7 +98,7 @@ test "detects emoji" do } }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert %{emojis: [%{shortcode: "blank"}]} = PollView.render("show.json", %{object: object}) end @@ -117,7 +117,7 @@ test "detects vote status" do } }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) {:ok, _, object} = CommonAPI.vote(other_user, object, [1, 2]) @@ -129,7 +129,7 @@ test "detects vote status" do end test "does not crash on polls with no end date" do - object = Object.normalize("https://skippers-bin.com/notes/7x9tmrp97i") + object = Object.normalize("https://skippers-bin.com/notes/7x9tmrp97i", fetch: true) result = PollView.render("show.json", %{object: object}) assert result[:expires_at] == nil @@ -153,7 +153,7 @@ test "doesn't strips HTML tags" do } }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert %{ options: [ diff --git a/test/pleroma/web/mastodon_api/views/status_view_test.exs b/test/pleroma/web/mastodon_api/views/status_view_test.exs index fa9066716..789acb487 100644 --- a/test/pleroma/web/mastodon_api/views/status_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/status_view_test.exs @@ -61,7 +61,7 @@ test "works correctly with badly formatted emojis" do {:ok, activity} = CommonAPI.post(user, %{status: "yo"}) activity - |> Object.normalize(false) + |> Object.normalize(fetch: false) |> Object.update_data(%{"reactions" => %{"☕" => [user.ap_id], "x" => 1}}) activity = Activity.get_by_id(activity.id) @@ -204,7 +204,7 @@ test "tries to get a user by nickname if fetching by ap_id doesn't work" do test "a note with null content" do note = insert(:note_activity) - note_object = Object.normalize(note) + note_object = Object.normalize(note, fetch: false) data = note_object.data @@ -223,7 +223,7 @@ test "a note with null content" do test "a note activity" do note = insert(:note_activity) - object_data = Object.normalize(note).data + object_data = Object.normalize(note, fetch: false).data user = User.get_cached_by_ap_id(note.data["actor"]) convo_id = Utils.context_to_conversation_id(object_data["context"]) diff --git a/test/pleroma/web/o_status/o_status_controller_test.exs b/test/pleroma/web/o_status/o_status_controller_test.exs index 65b2c22db..f21180a89 100644 --- a/test/pleroma/web/o_status/o_status_controller_test.exs +++ b/test/pleroma/web/o_status/o_status_controller_test.exs @@ -72,7 +72,7 @@ test "redirects to /notice/:id for html format for activity", %{ test "redirects to /notice/id for html format", %{conn: conn} do note_activity = insert(:note_activity) - object = Object.normalize(note_activity) + object = Object.normalize(note_activity, fetch: false) [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"])) url = "/objects/#{uuid}" @@ -82,7 +82,7 @@ test "redirects to /notice/id for html format", %{conn: conn} do test "404s on private objects", %{conn: conn} do note_activity = insert(:direct_note_activity) - object = Object.normalize(note_activity) + object = Object.normalize(note_activity, fetch: false) [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"])) conn @@ -133,7 +133,7 @@ test "redirects to a proper object URL when json requested and the object is loc conn: conn } do note_activity = insert(:note_activity) - expected_redirect_url = Object.normalize(note_activity).data["id"] + expected_redirect_url = Object.normalize(note_activity, fetch: false).data["id"] redirect_url = conn @@ -230,7 +230,7 @@ test "does not require authentication on non-federating instances", %{ describe "GET /notice/:id/embed_player" do setup do note_activity = insert(:note_activity) - object = Pleroma.Object.normalize(note_activity) + object = Pleroma.Object.normalize(note_activity, fetch: false) object_data = Map.put(object.data, "attachment", [ @@ -287,7 +287,7 @@ test "404s when activity is direct message", %{conn: conn} do test "404s when attachment is empty", %{conn: conn} do note_activity = insert(:note_activity) - object = Pleroma.Object.normalize(note_activity) + object = Pleroma.Object.normalize(note_activity, fetch: false) object_data = Map.put(object.data, "attachment", []) object @@ -301,7 +301,7 @@ test "404s when attachment is empty", %{conn: conn} do test "404s when attachment isn't audio or video", %{conn: conn} do note_activity = insert(:note_activity) - object = Pleroma.Object.normalize(note_activity) + object = Pleroma.Object.normalize(note_activity, fetch: false) object_data = Map.put(object.data, "attachment", [ diff --git a/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs index 415c3decd..24efeeb73 100644 --- a/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs @@ -22,7 +22,7 @@ test "it marks one message as read", %{conn: conn, user: user} do {:ok, create} = CommonAPI.post_chat_message(other_user, user, "sup") {:ok, _create} = CommonAPI.post_chat_message(other_user, user, "sup part 2") {:ok, chat} = Chat.get_or_create(user.id, other_user.ap_id) - object = Object.normalize(create, false) + object = Object.normalize(create, fetch: false) cm_ref = MessageReference.for_chat_and_object(chat, object) assert cm_ref.unread == true @@ -52,7 +52,7 @@ test "given a `last_read_id`, it marks everything until then as read", %{ {:ok, create} = CommonAPI.post_chat_message(other_user, user, "sup") {:ok, _create} = CommonAPI.post_chat_message(other_user, user, "sup part 2") {:ok, chat} = Chat.get_or_create(user.id, other_user.ap_id) - object = Object.normalize(create, false) + object = Object.normalize(create, fetch: false) cm_ref = MessageReference.for_chat_and_object(chat, object) assert cm_ref.unread == true @@ -158,7 +158,7 @@ test "it deletes a message from the chat", %{conn: conn, user: user} do {:ok, other_message} = CommonAPI.post_chat_message(recipient, user, "nico nico ni") - object = Object.normalize(message, false) + object = Object.normalize(message, fetch: false) chat = Chat.get(user.id, recipient.ap_id) @@ -176,7 +176,7 @@ test "it deletes a message from the chat", %{conn: conn, user: user} do assert %{data: %{"type" => "Tombstone"}} = Object.get_by_id(object.id) # Deleting other people's messages just removes the reference - object = Object.normalize(other_message, false) + object = Object.normalize(other_message, fetch: false) cm_ref = MessageReference.for_chat_and_object(chat, object) result = diff --git a/test/pleroma/web/pleroma_api/views/chat_message_reference_view_test.exs b/test/pleroma/web/pleroma_api/views/chat_message_reference_view_test.exs index 93eef00a2..0966e9166 100644 --- a/test/pleroma/web/pleroma_api/views/chat_message_reference_view_test.exs +++ b/test/pleroma/web/pleroma_api/views/chat_message_reference_view_test.exs @@ -31,7 +31,7 @@ test "it displays a chat message" do chat = Chat.get(user.id, recipient.ap_id) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) cm_ref = MessageReference.for_chat_and_object(chat, object) @@ -58,7 +58,7 @@ test "it displays a chat message" do media_id: upload.id ) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) cm_ref = MessageReference.for_chat_and_object(chat, object) diff --git a/test/pleroma/web/pleroma_api/views/chat_view_test.exs b/test/pleroma/web/pleroma_api/views/chat_view_test.exs index b60b597e8..1cc5f16ba 100644 --- a/test/pleroma/web/pleroma_api/views/chat_view_test.exs +++ b/test/pleroma/web/pleroma_api/views/chat_view_test.exs @@ -35,7 +35,7 @@ test "it represents a chat" do {:ok, chat_message_creation} = CommonAPI.post_chat_message(user, recipient, "hello") - chat_message = Object.normalize(chat_message_creation, false) + chat_message = Object.normalize(chat_message_creation, fetch: false) {:ok, chat} = Chat.get_or_create(user.id, recipient.ap_id) diff --git a/test/pleroma/web/push/impl_test.exs b/test/pleroma/web/push/impl_test.exs index 326a67963..d14e0bdef 100644 --- a/test/pleroma/web/push/impl_test.exs +++ b/test/pleroma/web/push/impl_test.exs @@ -118,7 +118,7 @@ test "renders title and body for create activity" do "Lorem ipsum dolor sit amet, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis." }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.format_body( %{ @@ -137,7 +137,7 @@ test "renders title and body for follow activity" do user = insert(:user, nickname: "Bob") other_user = insert(:user) {:ok, _, _, activity} = CommonAPI.follow(user, other_user) - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) assert Impl.format_body(%{activity: activity, type: "follow"}, user, object) == "@Bob has followed you" @@ -156,7 +156,7 @@ test "renders title and body for announce activity" do }) {:ok, announce_activity} = CommonAPI.repeat(activity.id, user) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.format_body(%{activity: announce_activity}, user, object) == "@#{user.nickname} repeated: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..." @@ -175,7 +175,7 @@ test "renders title and body for like activity" do }) {:ok, activity} = CommonAPI.favorite(user, activity.id) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.format_body(%{activity: activity, type: "favourite"}, user, object) == "@Bob has favorited your post" @@ -193,7 +193,7 @@ test "renders title and body for pleroma:emoji_reaction activity" do }) {:ok, activity} = CommonAPI.react_with_emoji(activity.id, user, "👍") - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.format_body(%{activity: activity, type: "pleroma:emoji_reaction"}, user, object) == "@Bob reacted with 👍" @@ -221,7 +221,7 @@ test "builds content for chat messages" do recipient = insert(:user) {:ok, chat} = CommonAPI.post_chat_message(user, recipient, "hey") - object = Object.normalize(chat, false) + object = Object.normalize(chat, fetch: false) [notification] = Notification.for_user(recipient) res = Impl.build_content(notification, user, object) @@ -245,7 +245,7 @@ test "builds content for chat messages with no content" do {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id) {:ok, chat} = CommonAPI.post_chat_message(user, recipient, nil, media_id: upload.id) - object = Object.normalize(chat, false) + object = Object.normalize(chat, fetch: false) [notification] = Notification.for_user(recipient) res = Impl.build_content(notification, user, object) @@ -271,7 +271,7 @@ test "hides contents of notifications when option enabled" do notif = insert(:notification, user: user2, activity: activity) actor = User.get_cached_by_ap_id(notif.activity.data["actor"]) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.build_content(notif, actor, object) == %{ body: "New Direct Message" @@ -286,7 +286,7 @@ test "hides contents of notifications when option enabled" do notif = insert(:notification, user: user2, activity: activity, type: "mention") actor = User.get_cached_by_ap_id(notif.activity.data["actor"]) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.build_content(notif, actor, object) == %{ body: "New Mention" @@ -297,7 +297,7 @@ test "hides contents of notifications when option enabled" do notif = insert(:notification, user: user2, activity: activity, type: "favourite") actor = User.get_cached_by_ap_id(notif.activity.data["actor"]) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.build_content(notif, actor, object) == %{ body: "New Favorite" @@ -320,7 +320,7 @@ test "returns regular content when hiding contents option disabled" do notif = insert(:notification, user: user2, activity: activity) actor = User.get_cached_by_ap_id(notif.activity.data["actor"]) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.build_content(notif, actor, object) == %{ body: @@ -338,7 +338,7 @@ test "returns regular content when hiding contents option disabled" do notif = insert(:notification, user: user2, activity: activity, type: "mention") actor = User.get_cached_by_ap_id(notif.activity.data["actor"]) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.build_content(notif, actor, object) == %{ body: @@ -351,7 +351,7 @@ test "returns regular content when hiding contents option disabled" do notif = insert(:notification, user: user2, activity: activity, type: "favourite") actor = User.get_cached_by_ap_id(notif.activity.data["actor"]) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.build_content(notif, actor, object) == %{ body: "@Bob has favorited your post", diff --git a/test/pleroma/web/streamer_test.exs b/test/pleroma/web/streamer_test.exs index ad66ddc9d..764b799bb 100644 --- a/test/pleroma/web/streamer_test.exs +++ b/test/pleroma/web/streamer_test.exs @@ -266,7 +266,7 @@ test "it sends chat messages to the 'user:pleroma_chat' stream", %{ {:ok, create_activity} = CommonAPI.post_chat_message(other_user, user, "hey cirno", idempotency_key: "123") - object = Object.normalize(create_activity, false) + object = Object.normalize(create_activity, fetch: false) chat = Chat.get(user.id, other_user.ap_id) cm_ref = MessageReference.for_chat_and_object(chat, object) cm_ref = %{cm_ref | chat: chat, object: object} @@ -284,7 +284,7 @@ test "it sends chat messages to the 'user' stream", %{user: user, token: oauth_t other_user = insert(:user) {:ok, create_activity} = CommonAPI.post_chat_message(other_user, user, "hey cirno") - object = Object.normalize(create_activity, false) + object = Object.normalize(create_activity, fetch: false) chat = Chat.get(user.id, other_user.ap_id) cm_ref = MessageReference.for_chat_and_object(chat, object) cm_ref = %{cm_ref | chat: chat, object: object} diff --git a/test/pleroma/workers/scheduled_activity_worker_test.exs b/test/pleroma/workers/scheduled_activity_worker_test.exs index f3eddf7b1..c9e2091a9 100644 --- a/test/pleroma/workers/scheduled_activity_worker_test.exs +++ b/test/pleroma/workers/scheduled_activity_worker_test.exs @@ -36,7 +36,7 @@ test "creates a status from the scheduled activity" do refute Repo.get(ScheduledActivity, scheduled_activity.id) activity = Repo.all(Pleroma.Activity) |> Enum.find(&(&1.actor == user.ap_id)) - assert Pleroma.Object.normalize(activity).data["content"] == "hi" + assert Pleroma.Object.normalize(activity, fetch: false).data["content"] == "hi" end test "adds log message if ScheduledActivity isn't find" do diff --git a/test/support/factory.ex b/test/support/factory.ex index 8eb07dc3c..e02acb89b 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -259,7 +259,7 @@ def announce_activity_factory(attrs \\ %{}) do def like_activity_factory(attrs \\ %{}) do note_activity = attrs[:note_activity] || insert(:note_activity) - object = Object.normalize(note_activity) + object = Object.normalize(note_activity, fetch: false) user = insert(:user) data = From 83f27282ba5c40c69cf7945e724685166bb3e5d4 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 4 Jan 2021 10:13:17 -0600 Subject: [PATCH 14/24] Do not try to guess which pagination we need by the existence of an :offset param. Require explicit request to get offset pagination. --- lib/pleroma/web/activity_pub/activity_pub.ex | 6 +----- .../web/admin_api/controllers/admin_api_controller.ex | 3 ++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 15f298bb8..9db72d6b2 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -603,11 +603,7 @@ def fetch_user_activities(user, reading_user, params \\ %{}) do |> Map.put(:muting_user, reading_user) end - pagination_type = - cond do - !Map.has_key?(params, :offset) -> :keyset - true -> :offset - end + pagination_type = Map.get(params, :pagination_type) || :keyset %{ godmode: params[:godmode], diff --git a/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex b/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex index 6ef8d6061..1c7c26d98 100644 --- a/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex @@ -110,7 +110,8 @@ def list_user_statuses(%{assigns: %{user: admin}} = conn, %{"nickname" => nickna limit: page_size, offset: (page - 1) * page_size, godmode: godmode, - exclude_reblogs: not with_reblogs + exclude_reblogs: not with_reblogs, + pagination_type: :offset }) conn From 0e93775ed0a35e348a0d13003680a478612fd6e3 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 4 Jan 2021 11:04:58 -0600 Subject: [PATCH 15/24] Add test to validate profile pagination works with keyset --- .../controllers/account_controller_test.exs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs index f6285853a..ba2f196f2 100644 --- a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs @@ -469,6 +469,19 @@ test "muted reactions", %{user: user, conn: conn} do } ] = result end + + test "paginates a user's statuses", %{user: user, conn: conn} do + {:ok, post1} = CommonAPI.post(user, %{status: "first post"}) + {:ok, _} = CommonAPI.post(user, %{status: "second post"}) + + response1 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1") + assert json_response(response1, 200) |> length() == 1 + + response2 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1&min_id=#{post1.id}") + assert json_response(response2, 200) |> length() == 1 + + refute response1 == response2 + end end defp local_and_remote_activities(%{local: local, remote: remote}) do From 95a0ae8a35f97eb27423ca0e7da722e8f7f135e5 Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 5 Jan 2021 11:48:40 +0100 Subject: [PATCH 16/24] AccountControllerTest: Fix test logic --- .../controllers/account_controller_test.exs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs index ba2f196f2..cc7b3cf8b 100644 --- a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs @@ -471,16 +471,18 @@ test "muted reactions", %{user: user, conn: conn} do end test "paginates a user's statuses", %{user: user, conn: conn} do - {:ok, post1} = CommonAPI.post(user, %{status: "first post"}) - {:ok, _} = CommonAPI.post(user, %{status: "second post"}) + {:ok, post_1} = CommonAPI.post(user, %{status: "first post"}) + {:ok, post_2} = CommonAPI.post(user, %{status: "second post"}) - response1 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1") - assert json_response(response1, 200) |> length() == 1 + response_1 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1") + assert [res] = json_response(response_1, 200) + assert res["id"] == post_2.id - response2 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1&min_id=#{post1.id}") - assert json_response(response2, 200) |> length() == 1 + response_2 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1&max_id=#{res["id"]}") + assert [res] = json_response(response_2, 200) + assert res["id"] == post_1.id - refute response1 == response2 + refute response_1 == response_2 end end From 64116f63d99a1eab9b697fc7a103e72dc80a095c Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 5 Jan 2021 12:25:30 -0600 Subject: [PATCH 17/24] URI.encode custom emojis --- lib/pleroma/web/activity_pub/transmogrifier.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 565d32433..5499f8a08 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -919,7 +919,7 @@ def add_emoji_tags(object), do: object defp build_emoji_tag({name, url}) do %{ - "icon" => %{"url" => url, "type" => "Image"}, + "icon" => %{"url" => "#{URI.encode(url)}", "type" => "Image"}, "name" => ":" <> name <> ":", "type" => "Emoji", "updated" => "1970-01-01T00:00:00Z", From 8864ac65c693eb19a36a6e0116abc13bcfe70ddb Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 5 Jan 2021 13:25:14 -0600 Subject: [PATCH 18/24] Add dinosaur gif from https://gifs.cc "Our animations are free to be used to enhance your website." --- config/emoji.txt | 1 + priv/static/emoji/dino walking.gif | Bin 0 -> 11213 bytes 2 files changed, 1 insertion(+) create mode 100644 priv/static/emoji/dino walking.gif diff --git a/config/emoji.txt b/config/emoji.txt index 200768ad1..52b714ee5 100644 --- a/config/emoji.txt +++ b/config/emoji.txt @@ -1,2 +1,3 @@ firefox, /emoji/Firefox.gif, Gif,Fun blank, /emoji/blank.png, Fun +dinosaur, /emoji/dino walking.gif, Gif diff --git a/priv/static/emoji/dino walking.gif b/priv/static/emoji/dino walking.gif new file mode 100644 index 0000000000000000000000000000000000000000..694a541e7f694393f6730e18d807d5a48b667a21 GIT binary patch literal 11213 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 O^Y9wEr$_=o#Qy?@3b;D} literal 0 HcmV?d00001 From f9090e00e6f6bec903c8df030c4af74ac378fccf Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 5 Jan 2021 13:58:49 -0600 Subject: [PATCH 19/24] Add test to validate URLs to custom emojis are properly encoded --- .../web/activity_pub/transmogrifier_test.exs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs index 66ea7664a..aa32ebaab 100644 --- a/test/pleroma/web/activity_pub/transmogrifier_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier_test.exs @@ -281,6 +281,21 @@ test "it can handle Listen activities" do {:ok, _modified} = Transmogrifier.prepare_outgoing(activity.data) end + + test "custom emoji urls are URI encoded" do + # :dinosaur: filename has a space -> dino walking.gif + user = insert(:user) + + {:ok, activity} = CommonAPI.post(user, %{status: "everybody do the dinosaur :dinosaur:"}) + + {:ok, prepared} = Transmogrifier.prepare_outgoing(activity.data) + + assert length(prepared["object"]["tag"]) == 1 + + url = prepared["object"]["tag"] |> List.first() |> Map.get("icon") |> Map.get("url") + + assert url == "http://localhost:4001/emoji/dino%20walking.gif" + end end describe "user upgrade" do From d69c78ceb969c8bef50743d03308d145f0b08a75 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 5 Jan 2021 15:06:00 -0600 Subject: [PATCH 20/24] Remove configurability of upload proxy opts, simplify --- config/config.exs | 8 -------- lib/pleroma/web/plugs/uploaded_media.ex | 9 ++++++++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/config/config.exs b/config/config.exs index d6d116314..7b14fbfe5 100644 --- a/config/config.exs +++ b/config/config.exs @@ -63,14 +63,6 @@ filters: [Pleroma.Upload.Filter.Dedupe], link_name: false, proxy_remote: false, - proxy_opts: [ - redirect_on_failure: false, - max_body_length: 25 * 1_048_576, - http: [ - follow_redirect: true, - pool: :upload - ] - ], filename_display_max_length: 30, default_description: nil diff --git a/lib/pleroma/web/plugs/uploaded_media.ex b/lib/pleroma/web/plugs/uploaded_media.ex index 402a8bb34..94b4c2177 100644 --- a/lib/pleroma/web/plugs/uploaded_media.ex +++ b/lib/pleroma/web/plugs/uploaded_media.ex @@ -87,8 +87,15 @@ defp get_media(conn, {:static_dir, directory}, _, opts) do end defp get_media(conn, {:url, url}, true, _) do + proxy_opts = [ + http: [ + follow_redirect: true, + pool: :upload + ] + ] + conn - |> Pleroma.ReverseProxy.call(url, Pleroma.Config.get([Pleroma.Upload, :proxy_opts], [])) + |> Pleroma.ReverseProxy.call(url, proxy_opts) end defp get_media(conn, {:url, url}, _, _) do From 48cd336a720086695613decc2a1a6852245c1df5 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 6 Feb 2019 18:05:34 +0100 Subject: [PATCH 21/24] allow external emoji --- config/emoji.txt | 1 + lib/pleroma/emoji/formatter.ex | 3 ++- test/pleroma/web/common_api_test.exs | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/config/emoji.txt b/config/emoji.txt index 52b714ee5..a2c5add2e 100644 --- a/config/emoji.txt +++ b/config/emoji.txt @@ -1,3 +1,4 @@ firefox, /emoji/Firefox.gif, Gif,Fun blank, /emoji/blank.png, Fun dinosaur, /emoji/dino walking.gif, Gif +external_emoji, https://example.com/emoji.png diff --git a/lib/pleroma/emoji/formatter.ex b/lib/pleroma/emoji/formatter.ex index dc45b8a38..992b20e12 100644 --- a/lib/pleroma/emoji/formatter.ex +++ b/lib/pleroma/emoji/formatter.ex @@ -5,6 +5,7 @@ defmodule Pleroma.Emoji.Formatter do alias Pleroma.Emoji alias Pleroma.HTML + alias Pleroma.Web alias Pleroma.Web.MediaProxy def emojify(text) do @@ -43,7 +44,7 @@ def get_emoji_map(text) when is_binary(text) do Emoji.get_all() |> Enum.filter(fn {emoji, %Emoji{}} -> String.contains?(text, ":#{emoji}:") end) |> Enum.reduce(%{}, fn {name, %Emoji{file: file}}, acc -> - Map.put(acc, name, "#{Pleroma.Web.Endpoint.static_url()}#{file}") + Map.put(acc, name, to_string(URI.merge(Web.base_url(), file))) end) end diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index 585b2c174..b81035a9d 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -504,6 +504,19 @@ test "it adds emoji in the object" do end describe "posting" do + test "it adds an emoji on an external site" do + user = insert(:user) + {:ok, activity} = CommonAPI.post(user, %{status: "hey :external_emoji:"}) + + assert %{"external_emoji" => url} = Object.normalize(activity).data["emoji"] + assert url == "https://example.com/emoji.png" + + {:ok, activity} = CommonAPI.post(user, %{status: "hey :blank:"}) + + assert %{"blank" => url} = Object.normalize(activity).data["emoji"] + assert url == "#{Pleroma.Web.base_url()}/emoji/blank.png" + end + test "deactivated users can't post" do user = insert(:user, deactivated: true) assert {:error, _} = CommonAPI.post(user, %{status: "ye"}) From 20af025c65dac642f664760a1428b2ab88920641 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 6 Jan 2021 11:30:32 -0600 Subject: [PATCH 22/24] AdminAPI: return user email --- lib/pleroma/web/admin_api/views/account_view.ex | 1 + test/pleroma/web/admin_api/controllers/user_controller_test.exs | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/pleroma/web/admin_api/views/account_view.ex b/lib/pleroma/web/admin_api/views/account_view.ex index 8bac24d3e..ebf90b91b 100644 --- a/lib/pleroma/web/admin_api/views/account_view.ex +++ b/lib/pleroma/web/admin_api/views/account_view.ex @@ -69,6 +69,7 @@ def render("show.json", %{user: user}) do %{ "id" => user.id, + "email" => user.email, "avatar" => avatar, "nickname" => user.nickname, "display_name" => display_name, diff --git a/test/pleroma/web/admin_api/controllers/user_controller_test.exs b/test/pleroma/web/admin_api/controllers/user_controller_test.exs index 5705306c7..67b0c578c 100644 --- a/test/pleroma/web/admin_api/controllers/user_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/user_controller_test.exs @@ -953,6 +953,7 @@ defp user_response(user, attrs \\ %{}) do %{ "deactivated" => user.deactivated, "id" => user.id, + "email" => user.email, "nickname" => user.nickname, "roles" => %{"admin" => false, "moderator" => false}, "local" => user.local, From 9f6fa5877faee2de0bbec27d434e04972ce13a96 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 6 Jan 2021 11:43:07 -0600 Subject: [PATCH 23/24] Add AdminAPI.AccountViewTest --- .../web/admin_api/views/account_view_test.exs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/pleroma/web/admin_api/views/account_view_test.exs diff --git a/test/pleroma/web/admin_api/views/account_view_test.exs b/test/pleroma/web/admin_api/views/account_view_test.exs new file mode 100644 index 000000000..f54214575 --- /dev/null +++ b/test/pleroma/web/admin_api/views/account_view_test.exs @@ -0,0 +1,16 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.AdminAPI.AccountViewTest do + use Pleroma.DataCase, async: true + import Pleroma.Factory + alias Pleroma.Web.AdminAPI.AccountView + + describe "show.json" do + test "renders the user's email" do + user = insert(:user, email: "yolo@yolofam.tld") + assert %{"email" => "yolo@yolofam.tld"} = AccountView.render("show.json", %{user: user}) + end + end +end From 3342f6a7efb4a731592972bacbcecf17d0e359d0 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 7 Jan 2021 13:06:22 -0600 Subject: [PATCH 24/24] Backups: render ID in API --- .../web/pleroma_api/views/backup_view.ex | 1 + .../web/pleroma_api/views/backup_view_test.exs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 test/pleroma/web/pleroma_api/views/backup_view_test.exs diff --git a/lib/pleroma/web/pleroma_api/views/backup_view.ex b/lib/pleroma/web/pleroma_api/views/backup_view.ex index af75876aa..39affe979 100644 --- a/lib/pleroma/web/pleroma_api/views/backup_view.ex +++ b/lib/pleroma/web/pleroma_api/views/backup_view.ex @@ -10,6 +10,7 @@ defmodule Pleroma.Web.PleromaAPI.BackupView do def render("show.json", %{backup: %Backup{} = backup}) do %{ + id: backup.id, content_type: backup.content_type, url: download_url(backup), file_size: backup.file_size, diff --git a/test/pleroma/web/pleroma_api/views/backup_view_test.exs b/test/pleroma/web/pleroma_api/views/backup_view_test.exs new file mode 100644 index 000000000..7dda8480b --- /dev/null +++ b/test/pleroma/web/pleroma_api/views/backup_view_test.exs @@ -0,0 +1,18 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.PleromaAPI.BackupViewTest do + use Pleroma.DataCase, async: true + alias Pleroma.User.Backup + alias Pleroma.Web.PleromaAPI.BackupView + import Pleroma.Factory + + test "it renders the ID" do + user = insert(:user) + backup = Backup.new(user) + + result = BackupView.render("show.json", backup: backup) + assert result.id == backup.id + end +end