[#1427] Extra check that admin OAuth scope is used by admin. Adjusted tests.
This commit is contained in:
parent
40e1817f70
commit
1770602747
4 changed files with 67 additions and 27 deletions
|
|
@ -13,7 +13,7 @@ defmodule Pleroma.Plugs.UserIsAdminPlugTest do
|
|||
Pleroma.Config.put([:auth, :enforce_oauth_admin_scope_usage], false)
|
||||
end
|
||||
|
||||
test "accepts a user that is admin" do
|
||||
test "accepts a user that is an admin" do
|
||||
user = insert(:user, is_admin: true)
|
||||
|
||||
conn = assign(build_conn(), :user, user)
|
||||
|
|
@ -23,7 +23,7 @@ defmodule Pleroma.Plugs.UserIsAdminPlugTest do
|
|||
assert conn == ret_conn
|
||||
end
|
||||
|
||||
test "denies a user that isn't admin" do
|
||||
test "denies a user that isn't an admin" do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
|
|
@ -54,23 +54,43 @@ defmodule Pleroma.Plugs.UserIsAdminPlugTest do
|
|||
{:ok, %{users: [admin_user, non_admin_user, blank_user]}}
|
||||
end
|
||||
|
||||
# Note: in real-life scenarios only users with is_admin flag can possess admin-scoped tokens;
|
||||
# however, the following test stresses out that is_admin flag is not checked if we got token
|
||||
test "if token has any of admin scopes, accepts users regardless of is_admin flag",
|
||||
%{users: users} do
|
||||
for user <- users do
|
||||
token = insert(:oauth_token, user: user, scopes: ["admin:something"])
|
||||
test "if token has any of admin scopes, accepts a user that is an admin", %{conn: conn} do
|
||||
user = insert(:user, is_admin: true)
|
||||
token = insert(:oauth_token, user: user, scopes: ["admin:something"])
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> assign(:token, token)
|
||||
|> UserIsAdminPlug.call(%{})
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> assign(:token, token)
|
||||
|
||||
ret_conn = UserIsAdminPlug.call(conn, %{})
|
||||
ret_conn = UserIsAdminPlug.call(conn, %{})
|
||||
|
||||
assert conn == ret_conn
|
||||
end
|
||||
assert conn == ret_conn
|
||||
end
|
||||
|
||||
test "if token has any of admin scopes, denies a user that isn't an admin", %{conn: conn} do
|
||||
user = insert(:user, is_admin: false)
|
||||
token = insert(:oauth_token, user: user, scopes: ["admin:something"])
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> assign(:token, token)
|
||||
|> UserIsAdminPlug.call(%{})
|
||||
|
||||
assert conn.status == 403
|
||||
end
|
||||
|
||||
test "if token has any of admin scopes, denies when a user isn't set", %{conn: conn} do
|
||||
token = insert(:oauth_token, scopes: ["admin:something"])
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, nil)
|
||||
|> assign(:token, token)
|
||||
|> UserIsAdminPlug.call(%{})
|
||||
|
||||
assert conn.status == 403
|
||||
end
|
||||
|
||||
test "if token lacks admin scopes, denies users regardless of is_admin flag",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue