diff options
author | Rémy Coutable <remy@rymai.me> | 2017-09-29 13:14:08 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-09-29 18:57:22 +0200 |
commit | 3040b994df0de7b6a6c4159a887fe7c8733bbb4d (patch) | |
tree | 44a2083d313206bad2090fdb5fc4f3e4c87b574e /spec/requests | |
parent | c49d19a5dc058a670bdac1e23579fbb44c60bec4 (diff) | |
download | gitlab-ce-3040b994df0de7b6a6c4159a887fe7c8733bbb4d.tar.gz |
Ensure no exception is raised when Raven tries to get the current user in API context38571-fix-exception-in-raven-report
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/helpers_spec.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/requests/api/helpers_spec.rb b/spec/requests/api/helpers_spec.rb index 98c49d3364c..060c8902471 100644 --- a/spec/requests/api/helpers_spec.rb +++ b/spec/requests/api/helpers_spec.rb @@ -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("\nRuntimeError (Runtime Error!):") + end + end end describe '.authenticate_non_get!' do |