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