mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-14 03:24:04 +00:00
Merge branch 'bugfix/containment-no-id' into 'develop'
object containment: handle all cases where ID is invalid (missing, nil, non-string) Closes #1387 See merge request pleroma/pleroma!1955
This commit is contained in:
commit
d8e99189d0
|
@ -64,15 +64,15 @@ defmodule Pleroma.Object.Containment do
|
||||||
def contain_origin(id, %{"attributedTo" => actor} = params),
|
def contain_origin(id, %{"attributedTo" => actor} = params),
|
||||||
do: contain_origin(id, Map.put(params, "actor", actor))
|
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) when is_binary(other_id) do
|
||||||
|
|
||||||
def contain_origin_from_id(id, %{"id" => other_id} = _params) do
|
|
||||||
id_uri = URI.parse(id)
|
id_uri = URI.parse(id)
|
||||||
other_uri = URI.parse(other_id)
|
other_uri = URI.parse(other_id)
|
||||||
|
|
||||||
compare_uris(id_uri, other_uri)
|
compare_uris(id_uri, other_uri)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def contain_origin_from_id(_id, _data), do: :error
|
||||||
|
|
||||||
def contain_child(%{"object" => %{"id" => id, "attributedTo" => _} = object}),
|
def contain_child(%{"object" => %{"id" => id, "attributedTo" => _} = object}),
|
||||||
do: contain_origin(id, object)
|
do: contain_origin(id, object)
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,20 @@ defmodule Pleroma.Object.ContainmentTest do
|
||||||
end) =~
|
end) =~
|
||||||
"[error] Could not decode user at fetch https://n1u.moe/users/rye"
|
"[error] Could not decode user at fetch https://n1u.moe/users/rye"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "containment of children" do
|
describe "containment of children" do
|
||||||
|
|
Loading…
Reference in a new issue