From f0d96534a4645f0996b3fab7ab5ba3b482fd4e23 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 11 Jun 2019 18:55:55 +0300 Subject: [PATCH 1/6] Import release config from env variable or /etc/pleroma/config.exs and warn if the file is missing --- config/releases.exs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/config/releases.exs b/config/releases.exs index becde7693..f8494dd34 100644 --- a/config/releases.exs +++ b/config/releases.exs @@ -1 +1,16 @@ import Config + +config_path = System.get_env("PLEROMA_CONFIG_PATH") || "/etc/pleroma/config.exs" + +if File.exists?(config_path) do + import_config config_path +else + warning = [ + IO.ANSI.red(), + IO.ANSI.bright(), + "!!! #{config_path} not found! Please ensure it exists and that PLEROMA_CONFIG_PATH is unset or points to an existing file", + IO.ANSI.reset() + ] + + IO.puts(warning) +end From ced59be1ae8deb4dd505215062d45be3e262710e Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 11 Jun 2019 22:15:28 +0300 Subject: [PATCH 2/6] Document TagPolicy in `rewrite_policy` section --- docs/config.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/config.md b/docs/config.md index b62b80490..54632fbda 100644 --- a/docs/config.md +++ b/docs/config.md @@ -86,6 +86,7 @@ config :pleroma, Pleroma.Emails.Mailer, * `Pleroma.Web.ActivityPub.MRF.NoOpPolicy`: Doesn’t modify activities (default) * `Pleroma.Web.ActivityPub.MRF.DropPolicy`: Drops all activities. It generally doesn’t makes sense to use in production * `Pleroma.Web.ActivityPub.MRF.SimplePolicy`: Restrict the visibility of activities from certains instances (See ``:mrf_simple`` section) + * `Pleroma.Web.ActivityPub.MRF.TagPolicy`: Applies policies to individual users based on tags, which can be set using pleroma-fe/admin-fe/any other app that supports Pleroma Admin API. For example it allows marking posts from individual users nsfw (sensitive) * `Pleroma.Web.ActivityPub.MRF.SubchainPolicy`: Selectively runs other MRF policies when messages match (see ``:mrf_subchain`` section) * `Pleroma.Web.ActivityPub.MRF.RejectNonPublic`: Drops posts with non-public visibility settings (See ``:mrf_rejectnonpublic`` section) * `Pleroma.Web.ActivityPub.MRF.EnsureRePrepended`: Rewrites posts to ensure that replies to posts with subjects do not have an identical subject and instead begin with re:. From bf22ed5fbd5d5087eb08e0bf0dc2ff6a29e90e0d Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Wed, 12 Jun 2019 15:53:33 +0700 Subject: [PATCH 3/6] Update `auto_linker` dependency --- lib/pleroma/web/rich_media/helpers.ex | 2 +- mix.exs | 2 +- mix.lock | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/rich_media/helpers.ex b/lib/pleroma/web/rich_media/helpers.ex index 9bc8f2559..f377125d7 100644 --- a/lib/pleroma/web/rich_media/helpers.ex +++ b/lib/pleroma/web/rich_media/helpers.ex @@ -9,7 +9,7 @@ defmodule Pleroma.Web.RichMedia.Helpers do alias Pleroma.Web.RichMedia.Parser defp validate_page_url(page_url) when is_binary(page_url) do - if AutoLinker.Parser.is_url?(page_url, true) do + if AutoLinker.Parser.url?(page_url, true) do URI.parse(page_url) |> validate_page_url else :error diff --git a/mix.exs b/mix.exs index bfa9bf18b..db7a30f99 100644 --- a/mix.exs +++ b/mix.exs @@ -126,7 +126,7 @@ defp deps do {:ueberauth, "~> 0.4"}, {:auto_linker, git: "https://git.pleroma.social/pleroma/auto_linker.git", - ref: "c00c4e75b35367fa42c95ffd9b8c455bf9995829"}, + ref: "e2385402bcd24fc659fee83b3eb8863b0528ad42"}, {:http_signatures, git: "https://git.pleroma.social/pleroma/http_signatures.git", ref: "9789401987096ead65646b52b5a2ca6bf52fc531"}, diff --git a/mix.lock b/mix.lock index de9d811e6..90cdf41f7 100644 --- a/mix.lock +++ b/mix.lock @@ -1,6 +1,6 @@ %{ "accept": {:hex, :accept, "0.3.5", "b33b127abca7cc948bbe6caa4c263369abf1347cfa9d8e699c6d214660f10cd1", [:rebar3], [], "hexpm"}, - "auto_linker": {:git, "https://git.pleroma.social/pleroma/auto_linker.git", "c00c4e75b35367fa42c95ffd9b8c455bf9995829", [ref: "c00c4e75b35367fa42c95ffd9b8c455bf9995829"]}, + "auto_linker": {:git, "https://git.pleroma.social/pleroma/auto_linker.git", "e2385402bcd24fc659fee83b3eb8863b0528ad42", [ref: "e2385402bcd24fc659fee83b3eb8863b0528ad42"]}, "base64url": {:hex, :base64url, "0.0.1", "36a90125f5948e3afd7be97662a1504b934dd5dac78451ca6e9abf85a10286be", [:rebar], [], "hexpm"}, "bbcode": {:hex, :bbcode, "0.1.0", "400e618b640b635261611d7fb7f79d104917fc5b084aae371ab6b08477cb035b", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"}, "benchee": {:hex, :benchee, "1.0.1", "66b211f9bfd84bd97e6d1beaddf8fc2312aaabe192f776e8931cb0c16f53a521", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}], "hexpm"}, From 817c66bc3ecf26596cbbc6086a9dc9b95b88fc0a Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Wed, 12 Jun 2019 16:22:56 +0700 Subject: [PATCH 4/6] Remove search result order for non-RUM indexes --- lib/pleroma/activity/search.ex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/pleroma/activity/search.ex b/lib/pleroma/activity/search.ex index 8cbb64cc4..0aa2aab23 100644 --- a/lib/pleroma/activity/search.ex +++ b/lib/pleroma/activity/search.ex @@ -39,8 +39,7 @@ defp query_with(q, :gin, search_query) do "to_tsvector('english', ?->>'content') @@ plainto_tsquery('english', ?)", o.data, ^search_query - ), - order_by: [desc: :id] + ) ) end From afae3ada22fb714735fd75448c574276353f2e1d Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 13 Jun 2019 16:34:03 +0700 Subject: [PATCH 5/6] Handle HTTP "410 Gone" response --- lib/pleroma/object/fetcher.ex | 3 +++ test/object/fetcher_test.exs | 24 +++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/object/fetcher.ex b/lib/pleroma/object/fetcher.ex index ca980c629..f7d724668 100644 --- a/lib/pleroma/object/fetcher.ex +++ b/lib/pleroma/object/fetcher.ex @@ -85,6 +85,9 @@ def fetch_and_contain_remote_object_from_id(id) do :ok <- Containment.contain_origin_from_id(id, data) do {:ok, data} else + {:ok, %{status: 410}} -> + {:error, "Object has been deleted"} + e -> {:error, e} end diff --git a/test/object/fetcher_test.exs b/test/object/fetcher_test.exs index d604fd5f5..58abcfe55 100644 --- a/test/object/fetcher_test.exs +++ b/test/object/fetcher_test.exs @@ -7,7 +7,14 @@ defmodule Pleroma.Object.FetcherTest do import Tesla.Mock setup do - mock(fn env -> apply(HttpRequestMock, :request, [env]) end) + mock(fn + %{method: :get, url: "https://mastodon.example.org/users/userisgone"} -> + %Tesla.Env{status: 410} + + env -> + apply(HttpRequestMock, :request, [env]) + end) + :ok end @@ -81,10 +88,17 @@ test "it can fetch peertube videos" do end test "all objects with fake directions are rejected by the object fetcher" do - {:error, _} = - Fetcher.fetch_and_contain_remote_object_from_id( - "https://info.pleroma.site/activity4.json" - ) + assert {:error, _} = + Fetcher.fetch_and_contain_remote_object_from_id( + "https://info.pleroma.site/activity4.json" + ) + end + + test "handle HTTP 410 Gone response" do + assert {:error, "Object has been deleted"} == + Fetcher.fetch_and_contain_remote_object_from_id( + "https://mastodon.example.org/users/userisgone" + ) end end From 30e54fd7e2f967364f2c1c17d739b629d2900167 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 13 Jun 2019 17:13:35 +0700 Subject: [PATCH 6/6] Handle HTTP 404 response --- lib/pleroma/object/fetcher.ex | 2 +- test/object/fetcher_test.exs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/object/fetcher.ex b/lib/pleroma/object/fetcher.ex index f7d724668..c422490ac 100644 --- a/lib/pleroma/object/fetcher.ex +++ b/lib/pleroma/object/fetcher.ex @@ -85,7 +85,7 @@ def fetch_and_contain_remote_object_from_id(id) do :ok <- Containment.contain_origin_from_id(id, data) do {:ok, data} else - {:ok, %{status: 410}} -> + {:ok, %{status: code}} when code in [404, 410] -> {:error, "Object has been deleted"} e -> diff --git a/test/object/fetcher_test.exs b/test/object/fetcher_test.exs index 58abcfe55..26dc9496d 100644 --- a/test/object/fetcher_test.exs +++ b/test/object/fetcher_test.exs @@ -11,6 +11,9 @@ defmodule Pleroma.Object.FetcherTest do %{method: :get, url: "https://mastodon.example.org/users/userisgone"} -> %Tesla.Env{status: 410} + %{method: :get, url: "https://mastodon.example.org/users/userisgone404"} -> + %Tesla.Env{status: 404} + env -> apply(HttpRequestMock, :request, [env]) end) @@ -100,6 +103,13 @@ test "handle HTTP 410 Gone response" do "https://mastodon.example.org/users/userisgone" ) end + + test "handle HTTP 404 response" do + assert {:error, "Object has been deleted"} == + Fetcher.fetch_and_contain_remote_object_from_id( + "https://mastodon.example.org/users/userisgone404" + ) + end end describe "pruning" do