logo

pleroma

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

user_is_admin_plug_test.exs (863B)


  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.UserIsAdminPlugTest do
  5. use Pleroma.Web.ConnCase, async: true
  6. alias Pleroma.Plugs.UserIsAdminPlug
  7. import Pleroma.Factory
  8. test "accepts a user that is an admin" do
  9. user = insert(:user, is_admin: true)
  10. conn = assign(build_conn(), :user, user)
  11. ret_conn = UserIsAdminPlug.call(conn, %{})
  12. assert conn == ret_conn
  13. end
  14. test "denies a user that isn't an admin" do
  15. user = insert(:user)
  16. conn =
  17. build_conn()
  18. |> assign(:user, user)
  19. |> UserIsAdminPlug.call(%{})
  20. assert conn.status == 403
  21. end
  22. test "denies when a user isn't set" do
  23. conn = UserIsAdminPlug.call(build_conn(), %{})
  24. assert conn.status == 403
  25. end
  26. end