logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

object_id_test.exs (996B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectIDTest do
  5. alias Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectID
  6. use Pleroma.DataCase, async: true
  7. @uris [
  8. "http://lain.com/users/lain",
  9. "http://lain.com",
  10. "https://lain.com/object/1"
  11. ]
  12. @non_uris [
  13. "https://",
  14. "rin",
  15. 1,
  16. :x,
  17. %{"1" => 2}
  18. ]
  19. test "it accepts http uris" do
  20. Enum.each(@uris, fn uri ->
  21. assert {:ok, uri} == ObjectID.cast(uri)
  22. end)
  23. end
  24. test "it accepts an object with a nested uri id" do
  25. Enum.each(@uris, fn uri ->
  26. assert {:ok, uri} == ObjectID.cast(%{"id" => uri})
  27. end)
  28. end
  29. test "it rejects non-uri strings" do
  30. Enum.each(@non_uris, fn non_uri ->
  31. assert :error == ObjectID.cast(non_uri)
  32. assert :error == ObjectID.cast(%{"id" => non_uri})
  33. end)
  34. end
  35. end