Commit 24f3ef5c authored by Sean Arnold's avatar Sean Arnold

Add authorisation for SentryErrorStackTraceType

- Stylistic changes
parent d3267254
......@@ -8,7 +8,6 @@ module Resolvers
description: 'ID of the Sentry issue'
def resolve(**args)
current_user = context[:current_user]
issue_id = GlobalID.parse(args[:id]).model_id
# Get data from Sentry
......
......@@ -2,11 +2,12 @@
module Types
module ErrorTracking
# rubocop: disable Graphql/AuthorizeTypes
class SentryErrorStackTraceType < ::Types::BaseObject
graphql_name 'SentryErrorStackTrace'
description 'An object containing a stack trace entry for a Sentry error.'
authorize :read_sentry_issue
field :issue_id, GraphQL::STRING_TYPE,
null: false,
description: 'ID of the Sentry error'
......@@ -17,6 +18,5 @@ module Types
null: false,
description: 'Stack trace entries for the Sentry error'
end
# rubocop: enable Graphql/AuthorizeTypes
end
end
......@@ -12,7 +12,7 @@ describe GitlabSchema.types['SentryErrorCollection'] do
errors
detailed_error
external_url
errorStackTrace
error_stack_trace
]
is_expected.to have_graphql_fields(*expected_fields)
......
......@@ -5,6 +5,8 @@ require 'spec_helper'
describe GitlabSchema.types['SentryErrorStackTrace'] do
it { expect(described_class.graphql_name).to eq('SentryErrorStackTrace') }
it { expect(described_class).to require_graphql_authorizations(:read_sentry_issue) }
it 'exposes the expected fields' do
expected_fields = %i[
issue_id
......
......@@ -40,8 +40,8 @@ describe 'sentry errors requests' do
post_graphql(query, current_user: current_user)
end
it "is expected to return an empty error" do
expect(error_data).to eq nil
it 'is expected to return an empty error' do
expect(error_data).to be_nil
end
end
......@@ -49,7 +49,7 @@ describe 'sentry errors requests' do
before do
allow_any_instance_of(ErrorTracking::ProjectErrorTrackingSetting)
.to receive(:issue_details)
.and_return({ issue: sentry_detailed_error })
.and_return(issue: sentry_detailed_error)
post_graphql(query, current_user: current_user)
end
......@@ -72,8 +72,8 @@ describe 'sentry errors requests' do
context 'user does not have permission' do
let(:current_user) { create(:user) }
it "is expected to return an empty error" do
expect(error_data).to eq nil
it 'is expected to return an empty error' do
expect(error_data).to be_nil
end
end
end
......@@ -82,13 +82,13 @@ describe 'sentry errors requests' do
before do
expect_any_instance_of(ErrorTracking::ProjectErrorTrackingSetting)
.to receive(:issue_details)
.and_return({ error: 'error message' })
.and_return(error: 'error message')
post_graphql(query, current_user: current_user)
end
it 'is expected to handle the error and return nil' do
expect(error_data).to eq nil
expect(error_data).to be_nil
end
end
end
......@@ -132,8 +132,8 @@ describe 'sentry errors requests' do
post_graphql(query, current_user: current_user)
end
it "is expected to return nil" do
expect(error_data).to eq nil
it 'is expected to return nil' do
expect(error_data).to be_nil
end
end
......@@ -141,7 +141,7 @@ describe 'sentry errors requests' do
before do
expect_any_instance_of(ErrorTracking::ProjectErrorTrackingSetting)
.to receive(:list_sentry_issues)
.and_return({ issues: [sentry_error], pagination: pagination })
.and_return(issues: [sentry_error], pagination: pagination)
post_graphql(query, current_user: current_user)
end
......@@ -174,17 +174,17 @@ describe 'sentry errors requests' do
end
end
context "sentry api itself errors out" do
context 'sentry api itself errors out' do
before do
expect_any_instance_of(ErrorTracking::ProjectErrorTrackingSetting)
.to receive(:list_sentry_issues)
.and_return({ error: 'error message' })
.and_return(error: 'error message')
post_graphql(query, current_user: current_user)
end
it 'is expected to handle the error and return nil' do
expect(error_data).to eq nil
expect(error_data).to be_nil
end
end
end
......@@ -214,8 +214,8 @@ describe 'sentry errors requests' do
post_graphql(query, current_user: current_user)
end
it "is expected to return an empty error" do
expect(stack_trace_data).to eq nil
it 'is expected to return an empty error' do
expect(stack_trace_data).to be_nil
end
end
......@@ -223,7 +223,7 @@ describe 'sentry errors requests' do
before do
allow_any_instance_of(ErrorTracking::ProjectErrorTrackingSetting)
.to receive(:issue_latest_event)
.and_return({ latest_event: sentry_stack_trace })
.and_return(latest_event: sentry_stack_trace)
post_graphql(query, current_user: current_user)
end
......@@ -233,8 +233,8 @@ describe 'sentry errors requests' do
context 'user does not have permission' do
let(:current_user) { create(:user) }
it "is expected to return an empty error" do
expect(stack_trace_data).to eq nil
it 'is expected to return an empty error' do
expect(stack_trace_data).to be_nil
end
end
end
......@@ -243,13 +243,13 @@ describe 'sentry errors requests' do
before do
expect_any_instance_of(ErrorTracking::ProjectErrorTrackingSetting)
.to receive(:issue_latest_event)
.and_return({ error: 'error message' })
.and_return(error: 'error message')
post_graphql(query, current_user: current_user)
end
it 'is expected to handle the error and return nil' do
expect(stack_trace_data).to eq nil
expect(stack_trace_data).to be_nil
end
end
end
......
......@@ -3,11 +3,11 @@
RSpec.shared_examples 'setting sentry error data' do
it 'sets the sentry error data correctly' do
aggregate_failures 'testing the sentry error is correct' do
expect(error['id']).to eql sentry_error.to_global_id.to_s
expect(error['sentryId']).to eql sentry_error.id.to_s
expect(error['status']).to eql sentry_error.status.upcase
expect(error['firstSeen']).to eql sentry_error.first_seen
expect(error['lastSeen']).to eql sentry_error.last_seen
expect(error['id']).to eq sentry_error.to_global_id.to_s
expect(error['sentryId']).to eq sentry_error.id.to_s
expect(error['status']).to eq sentry_error.status.upcase
expect(error['firstSeen']).to eq sentry_error.first_seen
expect(error['lastSeen']).to eq sentry_error.last_seen
end
end
end
......@@ -15,10 +15,10 @@ end
RSpec.shared_examples 'setting stack trace error' do
it 'sets the stack trace data correctly' do
aggregate_failures 'testing the stack trace is correct' do
expect(stack_trace_data['dateReceived']).to eql(sentry_stack_trace.date_received)
expect(stack_trace_data['issueId']).to eql(sentry_stack_trace.issue_id)
expect(stack_trace_data['dateReceived']).to eq(sentry_stack_trace.date_received)
expect(stack_trace_data['issueId']).to eq(sentry_stack_trace.issue_id)
expect(stack_trace_data['stackTraceEntries']).to be_an_instance_of(Array)
expect(stack_trace_data['stackTraceEntries'].size).to eql(sentry_stack_trace.stack_trace_entries.size)
expect(stack_trace_data['stackTraceEntries'].size).to eq(sentry_stack_trace.stack_trace_entries.size)
end
end
......@@ -27,10 +27,10 @@ RSpec.shared_examples 'setting stack trace error' do
stack_trace_entry = stack_trace_data['stackTraceEntries'].first
model_entry = sentry_stack_trace.stack_trace_entries.first
expect(stack_trace_entry['function']).to eql model_entry['function']
expect(stack_trace_entry['col']).to eql model_entry['colNo']
expect(stack_trace_entry['line']).to eql model_entry['lineNo'].to_s
expect(stack_trace_entry['fileName']).to eql model_entry['filename']
expect(stack_trace_entry['function']).to eq model_entry['function']
expect(stack_trace_entry['col']).to eq model_entry['colNo']
expect(stack_trace_entry['line']).to eq model_entry['lineNo'].to_s
expect(stack_trace_entry['fileName']).to eq model_entry['filename']
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment