From 54fdf3a5de3ed2bbfe0792b5193774db8797044c Mon Sep 17 00:00:00 2001 From: Walter Huf Date: Sun, 22 Jan 2023 09:32:58 -0800 Subject: [PATCH 1/4] Use any custom WebFinger domain for page metadata --- lib/pleroma/web/metadata/utils.ex | 2 +- lib/pleroma/web/web_finger.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/metadata/utils.ex b/lib/pleroma/web/metadata/utils.ex index 7308726f5..92622ef15 100644 --- a/lib/pleroma/web/metadata/utils.ex +++ b/lib/pleroma/web/metadata/utils.ex @@ -55,7 +55,7 @@ def scrub_html(content), do: content def user_name_string(user) do "#{user.name} " <> if user.local do - "(@#{user.nickname}@#{Pleroma.Web.Endpoint.host()})" + "(@#{user.nickname}@#{Pleroma.Web.WebFinger.domain()})" else "(@#{user.nickname})" end diff --git a/lib/pleroma/web/web_finger.ex b/lib/pleroma/web/web_finger.ex index 364d0e0e6..ae3993f90 100644 --- a/lib/pleroma/web/web_finger.ex +++ b/lib/pleroma/web/web_finger.ex @@ -96,7 +96,7 @@ def represent_user(user, "XML") do |> XmlBuilder.to_doc() end - defp domain do + def domain do Pleroma.Config.get([__MODULE__, :domain]) || Pleroma.Web.Endpoint.host() end From 1377ec33fe6fa62734215d2061941bc301347a25 Mon Sep 17 00:00:00 2001 From: Walter Huf Date: Thu, 27 Jul 2023 09:01:46 -0700 Subject: [PATCH 2/4] Add a unit test for custom WebFinger domain --- test/pleroma/web/web_finger/web_finger_controller_test.exs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/pleroma/web/web_finger/web_finger_controller_test.exs b/test/pleroma/web/web_finger/web_finger_controller_test.exs index 29cb6e01b..f2e8e4717 100644 --- a/test/pleroma/web/web_finger/web_finger_controller_test.exs +++ b/test/pleroma/web/web_finger/web_finger_controller_test.exs @@ -8,6 +8,7 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do import ExUnit.CaptureLog import Pleroma.Factory import Tesla.Mock + alias Pleroma.Web.Metadata.Utils setup do mock(fn env -> apply(HttpRequestMock, :request, [env]) end) @@ -60,6 +61,8 @@ test "reach user on tld, while pleroma is runned on subdomain" do user = insert(:user, ap_id: "https://sub.example.com/users/bobby", nickname: "bobby") + assert Utils.user_name_string(user) == "#{user.name} (@bobby@example.com)" + response = build_conn() |> put_req_header("accept", "application/jrd+json") From c38f1aefb1200169e2603834fc7116f88d30843c Mon Sep 17 00:00:00 2001 From: Walter Huf Date: Fri, 28 Jul 2023 07:35:00 -0700 Subject: [PATCH 3/4] Add unit tests for Utils.user_name_string --- test/pleroma/web/metadata/utils_test.exs | 28 +++++++++++++++++++ .../web_finger/web_finger_controller_test.exs | 2 -- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/test/pleroma/web/metadata/utils_test.exs b/test/pleroma/web/metadata/utils_test.exs index 665efb9ca..15aa1243b 100644 --- a/test/pleroma/web/metadata/utils_test.exs +++ b/test/pleroma/web/metadata/utils_test.exs @@ -77,4 +77,32 @@ test "it returns text without encode HTML" do assert Utils.scrub_html_and_truncate("Pleroma's really cool!") == "Pleroma's really cool!" end end + + describe "user_name_string/1" do + test "it uses the Endpoint by default" do + Pleroma.Web.Endpoint.config_change( + [{Pleroma.Web.Endpoint, url: [host: "sub.example.com"]}], + [] + ) + + user = insert(:user) + + assert Utils.user_name_string(user) == "#{user.name} (@#{user.nickname}@sub.example.com)" + end + + test "it uses any custom WebFinger domain" do + Pleroma.Web.Endpoint.config_change( + [{Pleroma.Web.Endpoint, url: [host: "sub.example.com"]}], + [] + ) + + clear_config([Pleroma.Web.Endpoint, :url, :host], "sub.example.com") + + clear_config([Pleroma.Web.WebFinger, :domain], "example.com") + + user = insert(:user) + + assert Utils.user_name_string(user) == "#{user.name} (@#{user.nickname}@example.com)" + end + end end diff --git a/test/pleroma/web/web_finger/web_finger_controller_test.exs b/test/pleroma/web/web_finger/web_finger_controller_test.exs index f2e8e4717..47e72662c 100644 --- a/test/pleroma/web/web_finger/web_finger_controller_test.exs +++ b/test/pleroma/web/web_finger/web_finger_controller_test.exs @@ -61,8 +61,6 @@ test "reach user on tld, while pleroma is runned on subdomain" do user = insert(:user, ap_id: "https://sub.example.com/users/bobby", nickname: "bobby") - assert Utils.user_name_string(user) == "#{user.name} (@bobby@example.com)" - response = build_conn() |> put_req_header("accept", "application/jrd+json") From b65aafe1e3ef97812686bd7fd6dabd45cebb0649 Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Wed, 2 Aug 2023 12:05:30 +0100 Subject: [PATCH 4/4] Fix tests breaking on config changes --- test/pleroma/web/metadata/utils_test.exs | 14 +------------- .../web/web_finger/web_finger_controller_test.exs | 1 - 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/test/pleroma/web/metadata/utils_test.exs b/test/pleroma/web/metadata/utils_test.exs index 15aa1243b..32bc86942 100644 --- a/test/pleroma/web/metadata/utils_test.exs +++ b/test/pleroma/web/metadata/utils_test.exs @@ -80,24 +80,12 @@ test "it returns text without encode HTML" do describe "user_name_string/1" do test "it uses the Endpoint by default" do - Pleroma.Web.Endpoint.config_change( - [{Pleroma.Web.Endpoint, url: [host: "sub.example.com"]}], - [] - ) - user = insert(:user) - assert Utils.user_name_string(user) == "#{user.name} (@#{user.nickname}@sub.example.com)" + assert Utils.user_name_string(user) == "#{user.name} (@#{user.nickname}@localhost)" end test "it uses any custom WebFinger domain" do - Pleroma.Web.Endpoint.config_change( - [{Pleroma.Web.Endpoint, url: [host: "sub.example.com"]}], - [] - ) - - clear_config([Pleroma.Web.Endpoint, :url, :host], "sub.example.com") - clear_config([Pleroma.Web.WebFinger, :domain], "example.com") user = insert(:user) diff --git a/test/pleroma/web/web_finger/web_finger_controller_test.exs b/test/pleroma/web/web_finger/web_finger_controller_test.exs index 47e72662c..29cb6e01b 100644 --- a/test/pleroma/web/web_finger/web_finger_controller_test.exs +++ b/test/pleroma/web/web_finger/web_finger_controller_test.exs @@ -8,7 +8,6 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do import ExUnit.CaptureLog import Pleroma.Factory import Tesla.Mock - alias Pleroma.Web.Metadata.Utils setup do mock(fn env -> apply(HttpRequestMock, :request, [env]) end)