1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Plugs.AdminSecretAuthenticationPlugTest do
6 use Pleroma.Web.ConnCase, async: true
9 alias Pleroma.Plugs.AdminSecretAuthenticationPlug
11 test "does nothing if a user is assigned", %{conn: conn} do
16 |> assign(:user, user)
20 |> AdminSecretAuthenticationPlug.call(%{})
22 assert conn == ret_conn
25 describe "when secret set it assigns an admin user" do
26 test "with `admin_token` query parameter", %{conn: conn} do
27 Pleroma.Config.put(:admin_token, "password123")
30 %{conn | params: %{"admin_token" => "wrong_password"}}
31 |> AdminSecretAuthenticationPlug.call(%{})
33 refute conn.assigns[:user]
36 %{conn | params: %{"admin_token" => "password123"}}
37 |> AdminSecretAuthenticationPlug.call(%{})
39 assert conn.assigns[:user].is_admin
42 test "with `x-admin-token` HTTP header", %{conn: conn} do
43 Pleroma.Config.put(:admin_token, "☕️")
47 |> put_req_header("x-admin-token", "🥛")
48 |> AdminSecretAuthenticationPlug.call(%{})
50 refute conn.assigns[:user]
54 |> put_req_header("x-admin-token", "☕️")
55 |> AdminSecretAuthenticationPlug.call(%{})
57 assert conn.assigns[:user].is_admin