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