Commit 6d000c9f authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '60057-fix-gitlab-schema-keyerror' into 'master'

Fix a KeyError in GitlabSchema

Closes #60057

See merge request gitlab-org/gitlab-ce!27011
parents 3958b4d3 beeeede2
......@@ -31,7 +31,7 @@ class GitlabSchema < GraphQL::Schema
end
def self.max_query_complexity(ctx)
current_user = ctx&.fetch(:current_user)
current_user = ctx&.fetch(:current_user, nil)
if current_user&.admin
ADMIN_COMPLEXITY
......
......@@ -34,12 +34,22 @@ describe GitlabSchema do
end
context 'for different types of users' do
it 'returns DEFAULT_MAX_COMPLEXITY for no user' do
expect(GraphQL::Schema).to receive(:execute).with('query', hash_including(max_complexity: GitlabSchema::DEFAULT_MAX_COMPLEXITY))
it 'returns DEFAULT_MAX_COMPLEXITY for no context' do
expect(GraphQL::Schema)
.to receive(:execute)
.with('query', hash_including(max_complexity: GitlabSchema::DEFAULT_MAX_COMPLEXITY))
described_class.execute('query')
end
it 'returns DEFAULT_MAX_COMPLEXITY for no user' do
expect(GraphQL::Schema)
.to receive(:execute)
.with('query', hash_including(max_complexity: GitlabSchema::DEFAULT_MAX_COMPLEXITY))
described_class.execute('query', context: {})
end
it 'returns AUTHENTICATED_COMPLEXITY for a logged in user' do
user = build :user
......
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