commit: 68b4de75585cac4c4e58cf1e9a44887b61efa35e
parent b6e16877e613342adf6730823a6b245864f3ef89
Author: nicole mikołajczyk <me@mkljczk.pl>
Date: Sat, 1 Nov 2025 11:25:17 +0100
Merge branch 'authorized-fetch-fix' into 'develop'
Fix fetching public keys with authorized fetch enabled
See merge request pleroma/pleroma!4383
Diffstat:
4 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/changelog.d/authorized_fetch.fix b/changelog.d/authorized_fetch.fix
@@ -0,0 +1 @@
+Fix fetching public keys with authorized fetch enabled
+\ No newline at end of file
diff --git a/lib/pleroma/signature.ex b/lib/pleroma/signature.ex
@@ -54,7 +54,7 @@ defmodule Pleroma.Signature do
def fetch_public_key(conn) do
with {:ok, actor_id} <- get_actor_id(conn),
- {:ok, public_key} <- User.get_public_key_for_ap_id(actor_id) do
+ {:ok, public_key} <- User.get_or_fetch_public_key_for_ap_id(actor_id) do
{:ok, public_key}
else
e ->
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
@@ -2307,6 +2307,15 @@ defmodule Pleroma.User do
def public_key(_), do: {:error, "key not found"}
+ def get_or_fetch_public_key_for_ap_id(ap_id) do
+ with {:ok, %User{} = user} <- get_or_fetch_by_ap_id(ap_id),
+ {:ok, public_key} <- public_key(user) do
+ {:ok, public_key}
+ else
+ _ -> :error
+ end
+ end
+
def get_public_key_for_ap_id(ap_id) do
with %User{} = user <- get_cached_by_ap_id(ap_id),
{:ok, public_key} <- public_key(user) do
diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs
@@ -1881,6 +1881,11 @@ defmodule Pleroma.UserTest do
end
end
+ test "get_or_fetch_public_key_for_ap_id fetches a user that's not in the db" do
+ assert {:ok, _key} =
+ User.get_or_fetch_public_key_for_ap_id("http://mastodon.example.org/users/admin")
+ end
+
test "get_public_key_for_ap_id returns correctly for user that's not in the db" do
assert :error = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
end