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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
ffcf50c8
Commit
ffcf50c8
authored
Aug 07, 2018
by
Peter Leitzen
Committed by
Tim Zallmann
Aug 07, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't set gon variables in JSON requests
parent
7a3d74af
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
2 deletions
+62
-2
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+6
-2
changelogs/unreleased/pl-json-gon.yml
changelogs/unreleased/pl-json-gon.yml
+5
-0
spec/controllers/application_controller_spec.rb
spec/controllers/application_controller_spec.rb
+51
-0
No files found.
app/controllers/application_controller.rb
View file @
ffcf50c8
...
...
@@ -20,13 +20,13 @@ class ApplicationController < ActionController::Base
before_action
:ldap_security_check
before_action
:sentry_context
before_action
:default_headers
before_action
:add_gon_variables
,
unless:
:peek_request?
before_action
:add_gon_variables
,
unless:
[
:peek_request?
,
:json_request?
]
before_action
:configure_permitted_parameters
,
if: :devise_controller?
before_action
:require_email
,
unless: :devise_controller?
around_action
:set_locale
after_action
:set_page_title_header
,
if:
->
{
request
.
format
==
:json
}
after_action
:set_page_title_header
,
if:
:json_request?
protect_from_forgery
with: :exception
,
prepend:
true
...
...
@@ -424,6 +424,10 @@ class ApplicationController < ActionController::Base
request
.
path
.
start_with?
(
'/-/peek'
)
end
def
json_request?
request
.
format
.
json?
end
def
should_enforce_terms?
return
false
unless
Gitlab
::
CurrentSettings
.
current_application_settings
.
enforce_terms
...
...
changelogs/unreleased/pl-json-gon.yml
0 → 100644
View file @
ffcf50c8
---
title
:
Don't set gon variables in JSON requests
merge_request
:
21016
author
:
Peter Leitzen
type
:
performance
spec/controllers/application_controller_spec.rb
View file @
ffcf50c8
...
...
@@ -56,6 +56,57 @@ describe ApplicationController do
end
end
describe
'#add_gon_variables'
do
before
do
Gon
.
clear
sign_in
user
end
let
(
:json_response
)
{
JSON
.
parse
(
response
.
body
)
}
controller
(
described_class
)
do
def
index
render
json:
Gon
.
all_variables
end
end
shared_examples
'setting gon variables'
do
it
'sets gon variables'
do
get
:index
,
format:
format
expect
(
json_response
.
size
).
not_to
be_zero
end
end
shared_examples
'not setting gon variables'
do
it
'does not set gon variables'
do
get
:index
,
format:
format
expect
(
json_response
.
size
).
to
be_zero
end
end
context
'with html format'
do
let
(
:format
)
{
:html
}
it_behaves_like
'setting gon variables'
context
'for peek requests'
do
before
do
request
.
path
=
'/-/peek'
end
it_behaves_like
'not setting gon variables'
end
end
context
'with json format'
do
let
(
:format
)
{
:json
}
it_behaves_like
'not setting gon variables'
end
end
describe
"#authenticate_user_from_personal_access_token!"
do
before
do
stub_authentication_activity_metrics
(
debug:
false
)
...
...
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