2018-12-23 13:11:29 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-01 04:11:47 -07:00
|
|
|
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
|
2018-12-23 13:11:29 -07:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-06-23 09:16:47 -06:00
|
|
|
defmodule Pleroma.Web.Plugs.UserIsAdminPlugTest do
|
2018-11-17 12:04:54 -07:00
|
|
|
use Pleroma.Web.ConnCase, async: true
|
|
|
|
|
2020-06-23 23:59:35 -06:00
|
|
|
alias Pleroma.Web.Plugs.UserIsAdminPlug
|
2018-11-17 12:04:54 -07:00
|
|
|
import Pleroma.Factory
|
|
|
|
|
2020-07-19 12:35:57 -06:00
|
|
|
test "accepts a user that is an admin" do
|
|
|
|
user = insert(:user, is_admin: true)
|
2018-11-17 12:04:54 -07:00
|
|
|
|
2020-07-19 12:35:57 -06:00
|
|
|
conn = assign(build_conn(), :user, user)
|
2018-11-17 12:04:54 -07:00
|
|
|
|
2020-07-19 12:35:57 -06:00
|
|
|
ret_conn = UserIsAdminPlug.call(conn, %{})
|
2018-11-17 12:04:54 -07:00
|
|
|
|
2020-07-19 12:35:57 -06:00
|
|
|
assert conn == ret_conn
|
2018-11-17 12:04:54 -07:00
|
|
|
end
|
|
|
|
|
2020-07-19 12:35:57 -06:00
|
|
|
test "denies a user that isn't an admin" do
|
|
|
|
user = insert(:user)
|
2019-12-06 10:33:47 -07:00
|
|
|
|
2020-07-19 12:35:57 -06:00
|
|
|
conn =
|
|
|
|
build_conn()
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> UserIsAdminPlug.call(%{})
|
2019-12-06 10:33:47 -07:00
|
|
|
|
2020-07-19 12:35:57 -06:00
|
|
|
assert conn.status == 403
|
|
|
|
end
|
2019-12-06 10:33:47 -07:00
|
|
|
|
2020-07-19 12:35:57 -06:00
|
|
|
test "denies when a user isn't set" do
|
|
|
|
conn = UserIsAdminPlug.call(build_conn(), %{})
|
2018-11-17 12:04:54 -07:00
|
|
|
|
2020-07-19 12:35:57 -06:00
|
|
|
assert conn.status == 403
|
2018-11-17 12:04:54 -07:00
|
|
|
end
|
|
|
|
end
|