Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
e5fa9e4c
Commit
e5fa9e4c
authored
May 12, 2020
by
Diego Louzán
Committed by
Imre Farkas
May 12, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix admin mode access on GraphiQL controller
parent
f7df08df
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
1 deletion
+61
-1
app/controllers/graphql_controller.rb
app/controllers/graphql_controller.rb
+6
-1
changelogs/unreleased/fix-admin-mode-graphiql-explorer.yml
changelogs/unreleased/fix-admin-mode-graphiql-explorer.yml
+5
-0
spec/controllers/graphql_controller_spec.rb
spec/controllers/graphql_controller_spec.rb
+50
-0
No files found.
app/controllers/graphql_controller.rb
View file @
e5fa9e4c
...
...
@@ -3,7 +3,12 @@
class
GraphqlController
<
ApplicationController
# Unauthenticated users have access to the API for public data
skip_before_action
:authenticate_user!
skip_around_action
:set_session_storage
# If a user is using their session to access GraphQL, we need to have session
# storage, since the admin-mode check is session wide.
# We can't enable this for anonymous users because that would cause users using
# enforced SSO from using an auth token to access the API.
skip_around_action
:set_session_storage
,
unless: :current_user
# Allow missing CSRF tokens, this would mean that if a CSRF is invalid or missing,
# the user won't be authenticated but can proceed as an anonymous user.
...
...
changelogs/unreleased/fix-admin-mode-graphiql-explorer.yml
0 → 100644
View file @
e5fa9e4c
---
title
:
Fix admin mode access on GraphiQL controller
merge_request
:
29845
author
:
Diego Louzán
type
:
fixed
spec/controllers/graphql_controller_spec.rb
View file @
e5fa9e4c
...
...
@@ -3,6 +3,8 @@
require
'spec_helper'
describe
GraphqlController
do
include
GraphqlHelpers
before
do
stub_feature_flags
(
graphql:
true
)
end
...
...
@@ -64,4 +66,52 @@ describe GraphqlController do
end
end
end
describe
'Admin Mode'
do
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:graphql_query
)
{
graphql_query_for
(
'project'
,
{
'fullPath'
=>
project
.
full_path
},
%w(id name)
)
}
before
do
sign_in
(
admin
)
end
context
'when admin mode enabled'
do
before
do
Gitlab
::
Session
.
with_session
(
controller
.
session
)
do
controller
.
current_user_mode
.
request_admin_mode!
controller
.
current_user_mode
.
enable_admin_mode!
(
password:
admin
.
password
)
end
end
it
'can query project data'
do
post
:execute
,
params:
{
query:
graphql_query
}
expect
(
controller
.
current_user_mode
.
admin_mode?
).
to
be
(
true
)
expect
(
json_response
[
'data'
][
'project'
][
'name'
]).
to
eq
(
project
.
name
)
end
end
context
'when admin mode disabled'
do
it
'cannot query project data'
do
post
:execute
,
params:
{
query:
graphql_query
}
expect
(
controller
.
current_user_mode
.
admin_mode?
).
to
be
(
false
)
expect
(
json_response
[
'data'
][
'project'
]).
to
be_nil
end
context
'when admin is member of the project'
do
before
do
project
.
add_developer
(
admin
)
end
it
'can query project data'
do
post
:execute
,
params:
{
query:
graphql_query
}
expect
(
controller
.
current_user_mode
.
admin_mode?
).
to
be
(
false
)
expect
(
json_response
[
'data'
][
'project'
][
'name'
]).
to
eq
(
project
.
name
)
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment