object containment: handle all cases where ID is invalid (missing, nil, non-string)
authorAriadne Conill <ariadne@dereferenced.org>
Fri, 8 Nov 2019 20:51:28 +0000 (14:51 -0600)
committerrinpatch <rinpatch@sdf.org>
Fri, 8 Nov 2019 22:41:34 +0000 (01:41 +0300)
lib/pleroma/object/containment.ex
test/object/containment_test.exs

index f077a9f32436841f1ffb01975c970d3082fd80a7..5f9d7523101f68c445264b180e9737520da3c136 100644 (file)
@@ -51,9 +51,7 @@ defmodule Pleroma.Object.Containment do
   def contain_origin(id, %{"attributedTo" => actor} = params),
     do: contain_origin(id, Map.put(params, "actor", actor))
 
-  def contain_origin_from_id(_id, %{"id" => nil}), do: :error
-
-  def contain_origin_from_id(id, %{"id" => other_id} = _params) do
+  def contain_origin_from_id(id, %{"id" => other_id} = _params) when is_binary(other_id) do
     id_uri = URI.parse(id)
     other_uri = URI.parse(other_id)
 
@@ -64,6 +62,8 @@ defmodule Pleroma.Object.Containment do
     end
   end
 
+  def contain_origin_from_id(_id, _data), do: :error
+
   def contain_child(%{"object" => %{"id" => id, "attributedTo" => _} = object}),
     do: contain_origin(id, object)
 
index 61cd1b41228d896e72f4596789e331ce3e2a2f66..a909f6db258a509f4fd7e954b1e3d976acc53d10 100644 (file)
@@ -67,6 +67,20 @@ defmodule Pleroma.Object.ContainmentTest do
              end) =~
                "[error] Could not decode user at fetch https://n1u.moe/users/rye, {:error, :error}"
     end
+
+    test "contain_origin_from_id() gracefully handles cases where no ID is present" do
+      data = %{
+        "type" => "Create",
+        "object" => %{
+          "id" => "http://example.net/~alyssa/activities/1234",
+          "attributedTo" => "http://example.org/~alyssa"
+        },
+        "actor" => "http://example.com/~bob"
+      }
+
+      :error =
+        Containment.contain_origin_from_id("http://example.net/~alyssa/activities/1234", data)
+    end
   end
 
   describe "containment of children" do