Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pleroma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ivan Tashkinov
pleroma
Commits
3920244b
Commit
3920244b
authored
5 years ago
by
Ivan Tashkinov
Browse files
Options
Downloads
Patches
Plain Diff
[
#1427
] Fixed `:admin` option handling in OAuthScopesPlug, added tests.
parent
1ae976ac
Branches
1427-oauth-admin-scopes
No related tags found
No related merge requests found
Pipeline
#20948
passed
5 years ago
Stage: build
Stage: test
Stage: benchmark
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/pleroma/config.ex
+8
-3
8 additions, 3 deletions
lib/pleroma/config.ex
lib/pleroma/plugs/oauth_scopes_plug.ex
+10
-7
10 additions, 7 deletions
lib/pleroma/plugs/oauth_scopes_plug.ex
test/plugs/oauth_scopes_plug_test.exs
+38
-0
38 additions, 0 deletions
test/plugs/oauth_scopes_plug_test.exs
with
56 additions
and
10 deletions
lib/pleroma/config.ex
+
8
−
3
View file @
3920244b
...
...
@@ -68,8 +68,13 @@ defmodule Pleroma.Config do
def
enforce_oauth_admin_scope_usage?
,
do
:
!!get
([
:auth
,
:enforce_oauth_admin_scope_usage
])
def
oauth_admin_scopes
(
scope
)
do
[
"admin:
#{
scope
}
"
]
++
if
enforce_oauth_admin_scope_usage?
(),
do
:
[],
else
:
[
scope
]
def
oauth_admin_scopes
(
scopes
)
when
is_list
(
scopes
)
do
Enum
.
flat_map
(
scopes
,
fn
scope
->
[
"admin:
#{
scope
}
"
]
++
if
enforce_oauth_admin_scope_usage?
(),
do
:
[],
else
:
[
scope
]
end
)
end
end
This diff is collapsed.
Click to expand it.
lib/pleroma/plugs/oauth_scopes_plug.ex
+
10
−
7
View file @
3920244b
...
...
@@ -17,13 +17,7 @@ defmodule Pleroma.Plugs.OAuthScopesPlug do
op
=
options
[
:op
]
||
:|
token
=
assigns
[
:token
]
scopes
=
if
options
[
:admin
]
do
Config
.
oauth_admin_scopes
(
scopes
)
else
scopes
end
scopes
=
transform_scopes
(
scopes
,
options
)
matched_scopes
=
token
&&
filter_descendants
(
scopes
,
token
.
scopes
)
cond
do
...
...
@@ -69,6 +63,15 @@ defmodule Pleroma.Plugs.OAuthScopesPlug do
)
end
@doc
"Transforms scopes by applying supported options (e.g. :admin)"
def
transform_scopes
(
scopes
,
options
)
do
if
options
[
:admin
]
do
Config
.
oauth_admin_scopes
(
scopes
)
else
scopes
end
end
defp
maybe_perform_instance_privacy_check
(%
Plug
.
Conn
{}
=
conn
,
options
)
do
if
options
[
:skip_instance_privacy_check
]
do
conn
...
...
This diff is collapsed.
Click to expand it.
test/plugs/oauth_scopes_plug_test.exs
+
38
−
0
View file @
3920244b
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment