Commit fef4dff1 authored by Sean McGivern's avatar Sean McGivern

Merge branch '29623-fix-nil-resolver-crash' into 'master'

Check nil before checking connection

See merge request gitlab-org/gitlab!30209
parents d498d0e1 47c3a6d2
...@@ -70,7 +70,10 @@ module Gitlab ...@@ -70,7 +70,10 @@ module Gitlab
end end
def filter_allowed(current_user, resolved_type, authorizing_object) def filter_allowed(current_user, resolved_type, authorizing_object)
if authorizing_object if resolved_type.nil?
# We're not rendering anything, for example when a record was not found
# no need to do anything
elsif authorizing_object
# Authorizing fields representing scalars, or a simple field with an object # Authorizing fields representing scalars, or a simple field with an object
resolved_type if allowed_access?(current_user, authorizing_object) resolved_type if allowed_access?(current_user, authorizing_object)
elsif @field.connection? elsif @field.connection?
...@@ -83,9 +86,6 @@ module Gitlab ...@@ -83,9 +86,6 @@ module Gitlab
resolved_type.select do |single_object_type| resolved_type.select do |single_object_type|
allowed_access?(current_user, single_object_type.object) allowed_access?(current_user, single_object_type.object)
end end
elsif resolved_type.nil?
# We're not rendering anything, for example when a record was not found
# no need to do anything
else else
raise "Can't authorize #{@field}" raise "Can't authorize #{@field}"
end end
......
...@@ -84,6 +84,16 @@ describe Gitlab::Graphql::Authorize::AuthorizeFieldService do ...@@ -84,6 +84,16 @@ describe Gitlab::Graphql::Authorize::AuthorizeFieldService do
end end
end end
context 'when the field is a connection' do
context 'when it resolves to nil' do
let(:field) { type_with_field(Types::QueryType.connection_type, :read_field, nil).fields['testField'].to_graphql }
it 'does not fail when authorizing' do
expect(resolved).to be_nil
end
end
end
context 'when the field is a specific type' do context 'when the field is a specific type' do
let(:custom_type) { type(:read_type) } let(:custom_type) { type(:read_type) }
let(:object_in_field) { double('presented in field') } let(:object_in_field) { double('presented in field') }
......
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