From 5fcab23aa3a6187d2e8746ff92330ab2aed807f6 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 28 Jan 2021 14:57:24 -0600 Subject: [PATCH 1/4] Improve error message for ConfigDB --- lib/pleroma/web/admin_api/controllers/admin_api_controller.ex | 2 +- lib/pleroma/web/admin_api/controllers/config_controller.ex | 2 +- .../web/admin_api/controllers/config_controller_test.exs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) 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 709c863ec..06883cf2d 100644 --- a/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex @@ -404,7 +404,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do if Config.get(:configurable_from_database) do :ok else - {:error, "To use this endpoint you need to enable configuration from database."} + {:error, "You must enable configurable_from_database in your config file."} end end diff --git a/lib/pleroma/web/admin_api/controllers/config_controller.ex b/lib/pleroma/web/admin_api/controllers/config_controller.ex index 7872fe2d8..4ebf2a305 100644 --- a/lib/pleroma/web/admin_api/controllers/config_controller.ex +++ b/lib/pleroma/web/admin_api/controllers/config_controller.ex @@ -122,7 +122,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigController do if Config.get(:configurable_from_database) do :ok else - {:error, "To use this endpoint you need to enable configuration from database."} + {:error, "You must enable configurable_from_database in your config file."} end end diff --git a/test/pleroma/web/admin_api/controllers/config_controller_test.exs b/test/pleroma/web/admin_api/controllers/config_controller_test.exs index 77688c7a3..578a4c914 100644 --- a/test/pleroma/web/admin_api/controllers/config_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/config_controller_test.exs @@ -31,7 +31,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do assert json_response_and_validate_schema(conn, 400) == %{ - "error" => "To use this endpoint you need to enable configuration from database." + "error" => "You must enable configurable_from_database in your config file." } end @@ -170,7 +170,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do |> post("/api/pleroma/admin/config", %{"configs" => []}) assert json_response_and_validate_schema(conn, 400) == - %{"error" => "To use this endpoint you need to enable configuration from database."} + %{"error" => "You must enable configurable_from_database in your config file."} end describe "POST /api/pleroma/admin/config" do From 887db076b55764f1cc7757df06f5ff8587de9798 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 3 Feb 2021 16:36:45 -0600 Subject: [PATCH 2/4] Load an emoji.txt specific to the test env --- config/emoji.txt | 1 - lib/pleroma/emoji/loader.ex | 11 ++++++++++- test/config/emoji.txt | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 test/config/emoji.txt diff --git a/config/emoji.txt b/config/emoji.txt index a2c5add2e..52b714ee5 100644 --- a/config/emoji.txt +++ b/config/emoji.txt @@ -1,4 +1,3 @@ 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/loader.ex b/lib/pleroma/emoji/loader.ex index 028cf5ea8..cc25dabf9 100644 --- a/lib/pleroma/emoji/loader.ex +++ b/lib/pleroma/emoji/loader.ex @@ -77,10 +77,19 @@ defmodule Pleroma.Emoji.Loader do # it should run even if there are no emoji packs shortcode_globs = Config.get([:emoji, :shortcode_globs], []) + # for testing emoji.txt entries we do not want exposed in normal operation + test_emoji = + if Mix.env() == :test do + load_from_file("test/config/emoji.txt", emoji_groups) + else + [] + end + emojis_txt = (load_from_file("config/emoji.txt", emoji_groups) ++ load_from_file("config/custom_emoji.txt", emoji_groups) ++ - load_from_globs(shortcode_globs, emoji_groups)) + load_from_globs(shortcode_globs, emoji_groups) ++ + test_emoji) |> Enum.reject(fn value -> value == nil end) Enum.map(emojis ++ emojis_txt, &prepare_emoji/1) diff --git a/test/config/emoji.txt b/test/config/emoji.txt new file mode 100644 index 000000000..14dd0c332 --- /dev/null +++ b/test/config/emoji.txt @@ -0,0 +1 @@ +external_emoji, https://example.com/emoji.png From ecff02741817e5622da58365855dce09c789ca83 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Wed, 3 Feb 2021 17:53:09 +0100 Subject: [PATCH 3/4] Redirect non-local activities when /notice/:id is used Related-to: https://git.pleroma.social/pleroma/pleroma/-/issues/2496 --- CHANGELOG.md | 1 + lib/pleroma/web/o_status/o_status_controller.ex | 8 ++------ .../web/o_status/o_status_controller_test.exs | 16 +++++++++++----- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f439d3a4..e9dfac97e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Deprecated `Pleroma.Uploaders.S3, :public_endpoint`. Now `Pleroma.Upload, :base_url` is the standard configuration key for all uploaders. - Improved Apache webserver support: updated sample configuration, MediaProxy cache invalidation verified with the included sample script - Improve OAuth 2.0 provider support. A missing `fqn` field was added to the response, but does not expose the user's email address. +- Provide redirect of external posts from `/notice/:id` to their original URL ### Added diff --git a/lib/pleroma/web/o_status/o_status_controller.ex b/lib/pleroma/web/o_status/o_status_controller.ex index 450aae042..da3264149 100644 --- a/lib/pleroma/web/o_status/o_status_controller.ex +++ b/lib/pleroma/web/o_status/o_status_controller.ex @@ -73,12 +73,8 @@ defmodule Pleroma.Web.OStatus.OStatusController do %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do cond do format in ["json", "activity+json"] -> - if activity.local do - %{data: %{"id" => redirect_url}} = Object.normalize(activity, fetch: false) - redirect(conn, external: redirect_url) - else - {:error, :not_found} - end + %{data: %{"id" => redirect_url}} = Object.normalize(activity, fetch: false) + redirect(conn, external: redirect_url) activity.data["type"] == "Create" -> %Object{} = object = Object.normalize(activity, fetch: false) 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 5cdca019a..2038f4ddd 100644 --- a/test/pleroma/web/o_status/o_status_controller_test.exs +++ b/test/pleroma/web/o_status/o_status_controller_test.exs @@ -144,13 +144,19 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do assert redirect_url == expected_redirect_url end - test "returns a 404 on remote notice when json requested", %{conn: conn} do + test "redirects to a proper object URL when json requested and the object is remote", %{ + conn: conn + } do note_activity = insert(:note_activity, local: false) + expected_redirect_url = Object.normalize(note_activity, fetch: false).data["id"] - conn - |> put_req_header("accept", "application/activity+json") - |> get("/notice/#{note_activity.id}") - |> response(404) + redirect_url = + conn + |> put_req_header("accept", "application/activity+json") + |> get("/notice/#{note_activity.id}") + |> redirected_to() + + assert redirect_url == expected_redirect_url end test "500s when actor not found", %{conn: conn} do From bf9cd4a0e24e2279a7560f6fb5e58d2d69362125 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 4 Feb 2021 10:11:48 -0600 Subject: [PATCH 4/4] Standardize the way we capture and use Mix.env() --- lib/pleroma/application.ex | 10 +++++----- lib/pleroma/emoji/loader.ex | 4 +++- lib/pleroma/uploaders/uploader.ex | 4 +++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 9e262235e..375507de1 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -14,7 +14,7 @@ defmodule Pleroma.Application do @name Mix.Project.config()[:name] @version Mix.Project.config()[:version] @repository Mix.Project.config()[:source_url] - @env Mix.env() + @mix_env Mix.env() def name, do: @name def version, do: @version @@ -92,15 +92,15 @@ defmodule Pleroma.Application do Pleroma.Web.Plugs.RateLimiter.Supervisor ] ++ cachex_children() ++ - http_children(adapter, @env) ++ + http_children(adapter, @mix_env) ++ [ Pleroma.Stats, Pleroma.JobQueueMonitor, {Majic.Pool, [name: Pleroma.MajicPool, pool_size: Config.get([:majic_pool, :size], 2)]}, {Oban, Config.get(Oban)} ] ++ - task_children(@env) ++ - dont_run_in_test(@env) ++ + task_children(@mix_env) ++ + dont_run_in_test(@mix_env) ++ chat_child(chat_enabled?()) ++ [ Pleroma.Web.Endpoint, @@ -145,7 +145,7 @@ defmodule Pleroma.Application do raise "Invalid custom modules" {:ok, modules, _warnings} -> - if @env != :test do + if @mix_env != :test do Enum.each(modules, fn mod -> Logger.info("Custom module loaded: #{inspect(mod)}") end) diff --git a/lib/pleroma/emoji/loader.ex b/lib/pleroma/emoji/loader.ex index cc25dabf9..67acd7069 100644 --- a/lib/pleroma/emoji/loader.ex +++ b/lib/pleroma/emoji/loader.ex @@ -15,6 +15,8 @@ defmodule Pleroma.Emoji.Loader do require Logger + @mix_env Mix.env() + @type pattern :: Regex.t() | module() | String.t() @type patterns :: pattern() | [pattern()] @type group_patterns :: keyword(patterns()) @@ -79,7 +81,7 @@ defmodule Pleroma.Emoji.Loader do # for testing emoji.txt entries we do not want exposed in normal operation test_emoji = - if Mix.env() == :test do + if @mix_env == :test do load_from_file("test/config/emoji.txt", emoji_groups) else [] diff --git a/lib/pleroma/uploaders/uploader.ex b/lib/pleroma/uploaders/uploader.ex index af99d001c..0be878ca2 100644 --- a/lib/pleroma/uploaders/uploader.ex +++ b/lib/pleroma/uploaders/uploader.ex @@ -5,6 +5,8 @@ defmodule Pleroma.Uploaders.Uploader do import Pleroma.Web.Gettext + @mix_env Mix.env() + @moduledoc """ Defines the contract to put and get an uploaded file to any backend. """ @@ -74,7 +76,7 @@ defmodule Pleroma.Uploaders.Uploader do end defp callback_timeout do - case Mix.env() do + case @mix_env do :test -> 1_000 _ -> 30_000 end