logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

ensure_public_or_authenticated_plug_test.exs (1174B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Plugs.EnsurePublicOrAuthenticatedPlugTest do
  5. use Pleroma.Web.ConnCase, async: true
  6. alias Pleroma.Config
  7. alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug
  8. alias Pleroma.User
  9. setup do: clear_config([:instance, :public])
  10. test "it halts if not public and no user is assigned", %{conn: conn} do
  11. Config.put([:instance, :public], false)
  12. conn =
  13. conn
  14. |> EnsurePublicOrAuthenticatedPlug.call(%{})
  15. assert conn.status == 403
  16. assert conn.halted == true
  17. end
  18. test "it continues if public", %{conn: conn} do
  19. Config.put([:instance, :public], true)
  20. ret_conn =
  21. conn
  22. |> EnsurePublicOrAuthenticatedPlug.call(%{})
  23. refute ret_conn.halted
  24. end
  25. test "it continues if a user is assigned, even if not public", %{conn: conn} do
  26. Config.put([:instance, :public], false)
  27. conn =
  28. conn
  29. |> assign(:user, %User{})
  30. ret_conn =
  31. conn
  32. |> EnsurePublicOrAuthenticatedPlug.call(%{})
  33. refute ret_conn.halted
  34. end
  35. end