Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.2KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2018 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. test "it halts if not public and no user is assigned", %{conn: conn} do
  10. set_public_to(false)
  11. conn =
  12. conn
  13. |> EnsurePublicOrAuthenticatedPlug.call(%{})
  14. assert conn.status == 403
  15. assert conn.halted == true
  16. end
  17. test "it continues if public", %{conn: conn} do
  18. set_public_to(true)
  19. ret_conn =
  20. conn
  21. |> EnsurePublicOrAuthenticatedPlug.call(%{})
  22. assert ret_conn == conn
  23. end
  24. test "it continues if a user is assigned, even if not public", %{conn: conn} do
  25. set_public_to(false)
  26. conn =
  27. conn
  28. |> assign(:user, %User{})
  29. ret_conn =
  30. conn
  31. |> EnsurePublicOrAuthenticatedPlug.call(%{})
  32. assert ret_conn == conn
  33. end
  34. defp set_public_to(value) do
  35. orig = Config.get!([:instance, :public])
  36. Config.put([:instance, :public], value)
  37. on_exit(fn ->
  38. Config.put([:instance, :public], orig)
  39. end)
  40. end
  41. end