Add more information about failed verifications
authorFloatingGhost <hannah@coffee-and-dreams.uk>
Fri, 10 Mar 2023 03:51:24 +0000 (03:51 +0000)
committerFloatingGhost <hannah@coffee-and-dreams.uk>
Fri, 10 Mar 2023 03:51:24 +0000 (03:51 +0000)
lib/pleroma/user.ex
lib/pleroma/web/rel_me.ex
test/pleroma/web/rel_me_test.exs

index 7a1e5628eccd63fb2c242945a18e08fdbc348750..f94202af5df22510d19f30fb73a5133ae923e9c7 100644 (file)
@@ -2077,10 +2077,14 @@ defmodule Pleroma.User do
     # TODO: get profile URLs other than user.ap_id
     profile_urls = [user.ap_id]
 
-    bio
-    |> CommonUtils.format_input("text/plain",
+    CommonUtils.format_input(bio, "text/plain",
       mentions_format: :full,
-      rel: &RelMe.maybe_put_rel_me(&1, profile_urls)
+      rel: fn link ->
+        case RelMe.maybe_put_rel_me(link, profile_urls) do
+          "me" -> "me"
+          _ -> nil
+        end
+      end
     )
     |> elem(0)
   end
index 98a3ae8ee5858cc12c43001766e4ab266b8f720a..afb525dbe7c4ddeb7bc6e8fdf922431282bc6045 100644 (file)
@@ -37,15 +37,18 @@ defmodule Pleroma.Web.RelMe do
   end
 
   def maybe_put_rel_me("http" <> _ = target_page, profile_urls) when is_list(profile_urls) do
-    {:ok, rel_me_hrefs} = parse(target_page)
-    true = Enum.any?(rel_me_hrefs, fn x -> x in profile_urls end)
-
-    "me"
+    with {:parse, {:ok, rel_me_hrefs}} <- {:parse, parse(target_page)},
+         {:link_match, true} <-
+           {:link_match, Enum.any?(rel_me_hrefs, fn x -> x in profile_urls end)} do
+      "me"
+    else
+      e -> {:error, {:could_not_verify, target_page, e}}
+    end
   rescue
-    _ -> nil
+    e -> {:error, {:could_not_fetch, target_page, e}}
   end
 
   def maybe_put_rel_me(_, _) do
-    nil
+    {:error, :invalid_url}
   end
 end
index 313b163b5c7f6872be59d4cca73b60a047ba3230..fc7abd7321bda1bf108dfda4138687c7de208665 100644 (file)
@@ -26,13 +26,12 @@ defmodule Pleroma.Web.RelMeTest do
   test "maybe_put_rel_me/2" do
     profile_urls = ["https://social.example.org/users/lain"]
     attr = "me"
-    fallback = nil
 
     assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/null", profile_urls) ==
-             fallback
+             {:error, {:could_not_verify, "http://example.com/rel_me/null", {:link_match, false}}}
 
-    assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/error", profile_urls) ==
-             fallback
+    assert {:error, {:could_not_fetch, "http://example.com/rel_me/error", _}} =
+             Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/error", profile_urls)
 
     assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/anchor", profile_urls) ==
              attr