1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Plugs.EnsureStaffPrivilegedPlugTest do
6 use Pleroma.Web.ConnCase, async: true
8 alias Pleroma.Web.Plugs.EnsureStaffPrivilegedPlug
11 test "accepts a user that is an admin" do
12 user = insert(:user, is_admin: true)
14 conn = assign(build_conn(), :user, user)
16 ret_conn = EnsureStaffPrivilegedPlug.call(conn, %{})
18 assert conn == ret_conn
21 test "accepts a user that is a moderator when :privileged_staff is enabled" do
22 clear_config([:instance, :privileged_staff], true)
23 user = insert(:user, is_moderator: true)
25 conn = assign(build_conn(), :user, user)
27 ret_conn = EnsureStaffPrivilegedPlug.call(conn, %{})
29 assert conn == ret_conn
32 test "denies a user that is a moderator when :privileged_staff is disabled" do
33 clear_config([:instance, :privileged_staff], false)
34 user = insert(:user, is_moderator: true)
38 |> assign(:user, user)
39 |> EnsureStaffPrivilegedPlug.call(%{})
41 assert conn.status == 403
44 test "denies a user that isn't a staff member" do
49 |> assign(:user, user)
50 |> EnsureStaffPrivilegedPlug.call(%{})
52 assert conn.status == 403
55 test "denies when a user isn't set" do
56 conn = EnsureStaffPrivilegedPlug.call(build_conn(), %{})
58 assert conn.status == 403