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