wf_akkoma/patches/pr814_08_federation-with-multi-ld-profiles.patch

72 lines
2.7 KiB
Diff

From ca182a0ae7cde1838b6f1c63b7348af7eb6b45b1 Mon Sep 17 00:00:00 2001
From: Oneric <oneric@oneric.stub>
Date: Thu, 20 Jun 2024 19:52:43 +0200
Subject: [PATCH] Correctly parse content types with multiple profiles
Multiple profiles can be specified as a space-separated list
and the possibility of additional profiles is explicitly brought up
in ActivityStream spec
---
lib/pleroma/object/fetcher.ex | 8 ++++++--
test/pleroma/object/fetcher_test.exs | 22 +++++++++++++++++++++-
3 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/lib/pleroma/object/fetcher.ex b/lib/pleroma/object/fetcher.ex
index 937026e04..54ea9e74e 100644
--- a/lib/pleroma/object/fetcher.ex
+++ b/lib/pleroma/object/fetcher.ex
@@ -369,8 +369,12 @@ defmodule Pleroma.Object.Fetcher do
{"activity+json", _} ->
{:ok, final_id, body}
- {"ld+json", %{"profile" => "https://www.w3.org/ns/activitystreams"}} ->
- {:ok, final_id, body}
+ {"ld+json", %{"profile" => profiles}} ->
+ if "https://www.w3.org/ns/activitystreams" in String.split(profiles) do
+ {:ok, final_id, body}
+ else
+ {:error, {:content_type, content_type}}
+ end
_ ->
{:error, {:content_type, content_type}}
diff --git a/test/pleroma/object/fetcher_test.exs b/test/pleroma/object/fetcher_test.exs
index 74f2cd31f..62dd64625 100644
--- a/test/pleroma/object/fetcher_test.exs
+++ b/test/pleroma/object/fetcher_test.exs
@@ -754,7 +754,7 @@ defmodule Pleroma.Object.FetcherTest do
assert {:ok, _, "{}"} = Fetcher.get_object("https://mastodon.social/2")
end
- test "should return ok if the content type is application/ld+json with a profile" do
+ test "should return ok if the content type is application/ld+json with the ActivityStream profile" do
Tesla.Mock.mock(fn
%{
method: :get,
@@ -774,6 +774,26 @@ defmodule Pleroma.Object.FetcherTest do
assert {:ok, _, "{}"} = Fetcher.get_object("https://mastodon.social/2")
end
+ test "should return ok if the content type is application/ld+json with several profiles" do
+ Tesla.Mock.mock(fn
+ %{
+ method: :get,
+ url: "https://mastodon.social/2"
+ } ->
+ %Tesla.Env{
+ status: 200,
+ url: "https://mastodon.social/2",
+ headers: [
+ {"content-type",
+ "application/ld+json; profile=\"https://example.org/ns/superduperspec https://www.w3.org/ns/activitystreams\""}
+ ],
+ body: "{}"
+ }
+ end)
+
+ assert {:ok, _, "{}"} = Fetcher.get_object("https://mastodon.social/2")
+ end
+
test "should not return ok with other content types" do
Tesla.Mock.mock(fn
%{