diff options
author | Egor Kislitsyn <egor@kislitsyn.com> | 2019-12-13 01:51:52 +0700 |
---|---|---|
committer | Egor Kislitsyn <egor@kislitsyn.com> | 2019-12-13 01:51:52 +0700 |
commit | 7528322f83d5bee92a030e2e626436dab327df9b (patch) | |
tree | d3a69eec557a563ce89246c886e9c31687c8debf /test/plugs/oauth_scopes_plug_test.exs | |
parent | c6f2735ffa1db7871bcb56c00b6d19e4de346d18 (diff) | |
parent | 2f31cef71f377cf660f818e7e204436f2070bd78 (diff) | |
download | pleroma-7528322f83d5bee92a030e2e626436dab327df9b.tar.gz pleroma-7528322f83d5bee92a030e2e626436dab327df9b.zip |
Merge branch 'develop' into feature/custom-runtime-modules
Diffstat (limited to 'test/plugs/oauth_scopes_plug_test.exs')
-rw-r--r-- | test/plugs/oauth_scopes_plug_test.exs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/plugs/oauth_scopes_plug_test.exs b/test/plugs/oauth_scopes_plug_test.exs index be6d1340b..89f32f43a 100644 --- a/test/plugs/oauth_scopes_plug_test.exs +++ b/test/plugs/oauth_scopes_plug_test.exs @@ -224,4 +224,42 @@ defmodule Pleroma.Plugs.OAuthScopesPlugTest do assert f.(["admin:read"], ["write", "admin"]) == ["admin:read"] end end + + describe "transform_scopes/2" do + clear_config([:auth, :enforce_oauth_admin_scope_usage]) + + setup do + {:ok, %{f: &OAuthScopesPlug.transform_scopes/2}} + end + + test "with :admin option, prefixes all requested scopes with `admin:` " <> + "and [optionally] keeps only prefixed scopes, " <> + "depending on `[:auth, :enforce_oauth_admin_scope_usage]` setting", + %{f: f} do + Pleroma.Config.put([:auth, :enforce_oauth_admin_scope_usage], false) + + assert f.(["read"], %{admin: true}) == ["admin:read", "read"] + + assert f.(["read", "write"], %{admin: true}) == [ + "admin:read", + "read", + "admin:write", + "write" + ] + + Pleroma.Config.put([:auth, :enforce_oauth_admin_scope_usage], true) + + assert f.(["read:accounts"], %{admin: true}) == ["admin:read:accounts"] + + assert f.(["read", "write:reports"], %{admin: true}) == [ + "admin:read", + "admin:write:reports" + ] + end + + test "with no supported options, returns unmodified scopes", %{f: f} do + assert f.(["read"], %{}) == ["read"] + assert f.(["read", "write"], %{}) == ["read", "write"] + end + end end |