Normalize Hubzilla alsoKnownAs from string to array

This commit is contained in:
Phantasm 2026-02-12 18:45:36 +01:00
commit f80c5744b1
No known key found for this signature in database
GPG key ID: 2669E588BCC634C8
4 changed files with 36 additions and 1 deletions

View file

@ -0,0 +1 @@
Fix fetching Hubzilla Actors with alsoKnownAs as string

View file

@ -1618,6 +1618,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
defp normalize_image(urls) when is_list(urls), do: urls |> List.first() |> normalize_image()
defp normalize_image(_), do: nil
defp normalize_also_known_as(urls) when is_list(urls), do: urls
defp normalize_also_known_as(url) when is_binary(url), do: [url]
defp normalize_also_known_as(nil), do: []
defp maybe_put_description(map, %{"name" => description}) when is_binary(description) do
Map.put(map, "name", description)
end
@ -1693,7 +1697,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
featured_address: featured_address,
bio: data["summary"] || "",
actor_type: actor_type,
also_known_as: Map.get(data, "alsoKnownAs", []),
also_known_as: normalize_also_known_as(data["alsoKnownAs"]),
public_key: public_key,
inbox: data["inbox"],
shared_inbox: shared_inbox,

File diff suppressed because one or more lines are too long

View file

@ -499,6 +499,35 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
"https://queef.in/storage/banner.gif"
end
test "works with alsoKnownAs as string" do
user_id = "https://hub.netzgemeinde.eu/channel/jupiter_rowland"
user_data =
"test/fixtures/users_mock/hubzilla-actor-alsoknownas-string.json"
|> File.read!()
user_data_decoded =
user_data
|> Jason.decode!()
Tesla.Mock.mock(fn
%{
method: :get,
url: ^user_id
} ->
%Tesla.Env{
status: 200,
body: user_data,
headers: [{"content-type", "application/activity+json"}]
}
end)
{:ok, user} = ActivityPub.make_user_from_ap_id(user_id)
assert is_list(user.also_known_as)
assert user.also_known_as == [user_data_decoded["alsoKnownAs"]]
end
test "it fetches the appropriate tag-restricted posts" do
user = insert(:user)