allow http AS profile in ld+json header
authorFloatingGhost <hannah@coffee-and-dreams.uk>
Mon, 12 Dec 2022 19:06:04 +0000 (19:06 +0000)
committerFloatingGhost <hannah@coffee-and-dreams.uk>
Mon, 12 Dec 2022 19:06:04 +0000 (19:06 +0000)
lib/pleroma/object/fetcher.ex
test/pleroma/object/fetcher_test.exs

index 8309ef64a042de3ffbb1da16a36c6869fca50fc8..aeaf05986430d6404b9c21d7292a97ca0ec59a1e 100644 (file)
@@ -262,7 +262,7 @@ defmodule Pleroma.Object.Fetcher do
   def fetch_and_contain_remote_object_from_id(_id),
     do: {:error, "id must be a string"}
 
-  defp get_object(id) do
+  def get_object(id) do
     date = Pleroma.Signature.signed_date()
 
     headers =
@@ -282,6 +282,11 @@ defmodule Pleroma.Object.Fetcher do
                %{"profile" => "https://www.w3.org/ns/activitystreams"}} ->
                 {:ok, body}
 
+              # pixelfed sometimes (and only sometimes) responds with http instead of https
+              {:ok, "application", "ld+json",
+               %{"profile" => "http://www.w3.org/ns/activitystreams"}} ->
+                {:ok, body}
+
               _ ->
                 {:error, {:content_type, content_type}}
             end
index c76a09fd7142e7c3f82961afb2dc315376ea988f..e26443a81bdb41f67c6460e10748046bc1fbe018 100644 (file)
@@ -572,4 +572,75 @@ defmodule Pleroma.Object.FetcherTest do
              } = object.data
     end
   end
+
+  describe "get_object/1" do
+    test "should return ok if the content type is application/activity+json" do
+      Tesla.Mock.mock(fn
+        %{
+          method: :get,
+          url: "https://mastodon.social/2"
+        } ->
+          %Tesla.Env{
+            status: 200,
+            headers: [{"content-type", "application/activity+json"}],
+            body: "{}"
+          }
+      end)
+
+      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
+      Tesla.Mock.mock(fn
+        %{
+          method: :get,
+          url: "https://mastodon.social/2"
+        } ->
+          %Tesla.Env{
+            status: 200,
+            headers: [
+              {"content-type",
+               "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""}
+            ],
+            body: "{}"
+          }
+      end)
+
+      assert {:ok, "{}"} = Fetcher.get_object("https://mastodon.social/2")
+
+      Tesla.Mock.mock(fn
+        %{
+          method: :get,
+          url: "https://mastodon.social/2"
+        } ->
+          %Tesla.Env{
+            status: 200,
+            headers: [
+              {"content-type",
+               "application/ld+json; profile=\"http://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
+        %{
+          method: :get,
+          url: "https://mastodon.social/2"
+        } ->
+          %Tesla.Env{
+            status: 200,
+            headers: [{"content-type", "application/json"}],
+            body: "{}"
+          }
+      end)
+
+      assert {:error, {:content_type, "application/json"}} =
+               Fetcher.get_object("https://mastodon.social/2")
+    end
+  end
 end