summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAriadne Conill <ariadne@dereferenced.org>2019-11-08 14:51:28 -0600
committerrinpatch <rinpatch@sdf.org>2019-11-09 01:41:34 +0300
commit6e65da782e6c448c6fa1901303bfe3dc5bdd7e13 (patch)
treed876720416e16c735c1c15005701afdd15de1bbe
parent4c5055bac9ba1763d17bb1b63aa378999b90ed1c (diff)
object containment: handle all cases where ID is invalid (missing, nil, non-string)
-rw-r--r--lib/pleroma/object/containment.ex6
-rw-r--r--test/object/containment_test.exs14
2 files changed, 17 insertions, 3 deletions
diff --git a/lib/pleroma/object/containment.ex b/lib/pleroma/object/containment.ex
index f077a9f32..5f9d75231 100644
--- a/lib/pleroma/object/containment.ex
+++ b/lib/pleroma/object/containment.ex
@@ -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)
diff --git a/test/object/containment_test.exs b/test/object/containment_test.exs
index 61cd1b412..a909f6db2 100644
--- a/test/object/containment_test.exs
+++ b/test/object/containment_test.exs
@@ -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