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
3040b994
Commit
3040b994
authored
Sep 29, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure no exception is raised when Raven tries to get the current user in API context
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
c49d19a5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
3 deletions
+32
-3
changelogs/unreleased/38571-fix-exception-in-raven-report.yml
...gelogs/unreleased/38571-fix-exception-in-raven-report.yml
+6
-0
lib/api/helpers.rb
lib/api/helpers.rb
+5
-3
spec/requests/api/helpers_spec.rb
spec/requests/api/helpers_spec.rb
+21
-0
No files found.
changelogs/unreleased/38571-fix-exception-in-raven-report.yml
0 → 100644
View file @
3040b994
---
title
:
Ensure no exception is raised when Raven tries to get the current user in API
context
merge_request
:
14580
author
:
type
:
fixed
lib/api/helpers.rb
View file @
3040b994
...
...
@@ -464,10 +464,12 @@ module API
header
(
*
Gitlab
::
Workhorse
.
send_artifacts_entry
(
build
,
entry
))
end
# The Grape Error Middleware only has access to env but no params. We workaround this by
# defining a method that returns the right value.
# The Grape Error Middleware only has access to `env` but not `params` nor
# `request`. We workaround this by defining methods that returns the right
# values.
def
define_params_for_grape_middleware
self
.
define_singleton_method
(
:params
)
{
Rack
::
Request
.
new
(
env
).
params
.
symbolize_keys
}
self
.
define_singleton_method
(
:request
)
{
Rack
::
Request
.
new
(
env
)
}
self
.
define_singleton_method
(
:params
)
{
request
.
params
.
symbolize_keys
}
end
# We could get a Grape or a standard Ruby exception. We should only report anything that
...
...
spec/requests/api/helpers_spec.rb
View file @
3040b994
...
...
@@ -480,6 +480,27 @@ describe API::Helpers do
handle_api_exception
(
exception
)
end
context
'with a personal access token given'
do
let
(
:token
)
{
create
(
:personal_access_token
,
scopes:
[
'api'
],
user:
user
)
}
# Regression test for https://gitlab.com/gitlab-org/gitlab-ce/issues/38571
it
'does not raise an additional exception because of missing `request`'
do
# We need to stub at a lower level than #sentry_enabled? otherwise
# Sentry is not enabled when the request below is made, and the test
# would pass even without the fix
expect
(
Gitlab
::
Sentry
).
to
receive
(
:enabled?
).
twice
.
and_return
(
true
)
expect
(
ProjectsFinder
).
to
receive
(
:new
).
and_raise
(
'Runtime Error!'
)
get
api
(
'/projects'
,
personal_access_token:
token
)
# The 500 status is expected as we're testing a case where an exception
# is raised, but Grape shouldn't raise an additional exception
expect
(
response
).
to
have_gitlab_http_status
(
500
)
expect
(
json_response
[
'message'
]).
not_to
include
(
"undefined local variable or method `request'"
)
expect
(
json_response
[
'message'
]).
to
start_with
(
"
\n
RuntimeError (Runtime Error!):"
)
end
end
end
describe
'.authenticate_non_get!'
do
...
...
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