Strip status data from Flag (when federating or closing/resolving report)
[akkoma] / test / plugs / admin_secret_authentication_plug_test.exs
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
5 defmodule Pleroma.Plugs.AdminSecretAuthenticationPlugTest do
6 use Pleroma.Web.ConnCase, async: true
7 import Pleroma.Factory
8
9 alias Pleroma.Plugs.AdminSecretAuthenticationPlug
10
11 test "does nothing if a user is assigned", %{conn: conn} do
12 user = insert(:user)
13
14 conn =
15 conn
16 |> assign(:user, user)
17
18 ret_conn =
19 conn
20 |> AdminSecretAuthenticationPlug.call(%{})
21
22 assert conn == ret_conn
23 end
24
25 test "with secret set and given in the 'admin_token' parameter, it assigns an admin user", %{
26 conn: conn
27 } do
28 Pleroma.Config.put(:admin_token, "password123")
29
30 conn =
31 %{conn | params: %{"admin_token" => "wrong_password"}}
32 |> AdminSecretAuthenticationPlug.call(%{})
33
34 refute conn.assigns[:user]
35
36 conn =
37 %{conn | params: %{"admin_token" => "password123"}}
38 |> AdminSecretAuthenticationPlug.call(%{})
39
40 assert conn.assigns[:user].info.is_admin
41 end
42 end