2020-05-06 14:12:36 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-03-31 14:11:38 +00:00
|
|
|
defmodule Pleroma.Web.ObjectValidators.Types.ObjectIDTest do
|
2020-06-16 14:50:33 +00:00
|
|
|
alias Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectID
|
2020-03-31 14:11:38 +00:00
|
|
|
use Pleroma.DataCase
|
|
|
|
|
|
|
|
@uris [
|
|
|
|
"http://lain.com/users/lain",
|
|
|
|
"http://lain.com",
|
|
|
|
"https://lain.com/object/1"
|
|
|
|
]
|
|
|
|
|
|
|
|
@non_uris [
|
|
|
|
"https://",
|
2020-03-31 15:47:34 +00:00
|
|
|
"rin",
|
|
|
|
1,
|
|
|
|
:x,
|
|
|
|
%{"1" => 2}
|
2020-03-31 14:11:38 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
test "it accepts http uris" do
|
|
|
|
Enum.each(@uris, fn uri ->
|
|
|
|
assert {:ok, uri} == ObjectID.cast(uri)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it accepts an object with a nested uri id" do
|
|
|
|
Enum.each(@uris, fn uri ->
|
|
|
|
assert {:ok, uri} == ObjectID.cast(%{"id" => uri})
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it rejects non-uri strings" do
|
|
|
|
Enum.each(@non_uris, fn non_uri ->
|
|
|
|
assert :error == ObjectID.cast(non_uri)
|
|
|
|
assert :error == ObjectID.cast(%{"id" => non_uri})
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|