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.

43 lines
1.1KB

  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.AdminSecretAuthenticationPlugTest do
  5. use Pleroma.Web.ConnCase, async: true
  6. import Pleroma.Factory
  7. alias Pleroma.Plugs.AdminSecretAuthenticationPlug
  8. test "does nothing if a user is assigned", %{conn: conn} do
  9. user = insert(:user)
  10. conn =
  11. conn
  12. |> assign(:user, user)
  13. ret_conn =
  14. conn
  15. |> AdminSecretAuthenticationPlug.call(%{})
  16. assert conn == ret_conn
  17. end
  18. test "with secret set and given in the 'admin_token' parameter, it assigns an admin user", %{
  19. conn: conn
  20. } do
  21. Pleroma.Config.put(:admin_token, "password123")
  22. conn =
  23. %{conn | params: %{"admin_token" => "wrong_password"}}
  24. |> AdminSecretAuthenticationPlug.call(%{})
  25. refute conn.assigns[:user]
  26. conn =
  27. %{conn | params: %{"admin_token" => "password123"}}
  28. |> AdminSecretAuthenticationPlug.call(%{})
  29. assert conn.assigns[:user].is_admin
  30. end
  31. end