Merge branch 'more-efficient-ci' into 'develop'
[akkoma] / test / pleroma / web / plugs / ensure_staff_privileged_plug_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Plugs.EnsureStaffPrivilegedPlugTest do
6 use Pleroma.Web.ConnCase, async: true
7
8 alias Pleroma.Web.Plugs.EnsureStaffPrivilegedPlug
9 import Pleroma.Factory
10
11 test "accepts a user that is an admin" do
12 user = insert(:user, is_admin: true)
13
14 conn = assign(build_conn(), :user, user)
15
16 ret_conn = EnsureStaffPrivilegedPlug.call(conn, %{})
17
18 assert conn == ret_conn
19 end
20
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)
24
25 conn = assign(build_conn(), :user, user)
26
27 ret_conn = EnsureStaffPrivilegedPlug.call(conn, %{})
28
29 assert conn == ret_conn
30 end
31
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)
35
36 conn =
37 build_conn()
38 |> assign(:user, user)
39 |> EnsureStaffPrivilegedPlug.call(%{})
40
41 assert conn.status == 403
42 end
43
44 test "denies a user that isn't a staff member" do
45 user = insert(:user)
46
47 conn =
48 build_conn()
49 |> assign(:user, user)
50 |> EnsureStaffPrivilegedPlug.call(%{})
51
52 assert conn.status == 403
53 end
54
55 test "denies when a user isn't set" do
56 conn = EnsureStaffPrivilegedPlug.call(build_conn(), %{})
57
58 assert conn.status == 403
59 end
60 end