diff options
author | Sean McGivern <sean@gitlab.com> | 2019-05-08 11:46:56 +0300 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-05-08 11:46:56 +0300 |
commit | 9f888c7440a99f0c9bd59ac066fae88e7c863e41 (patch) | |
tree | 83f534032d8098414de3a3957f3a591e4e412e52 /spec/requests | |
parent | 69cfdfaed3e5a63bc8af39ca4b42c932db1b7f75 (diff) | |
parent | f80f68d520b98ae60300ecf0758ff241218e9cd0 (diff) |
Merge branch '58404-set-default-max-depth-for-GraphQL' into 'master'
58404 - setup max depth for graphql
Closes #58404
See merge request gitlab-org/gitlab-ce!25737
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/graphql/gitlab_schema_spec.rb | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/spec/requests/api/graphql/gitlab_schema_spec.rb b/spec/requests/api/graphql/gitlab_schema_spec.rb index b63b4fb34df..dd518274f82 100644 --- a/spec/requests/api/graphql/gitlab_schema_spec.rb +++ b/spec/requests/api/graphql/gitlab_schema_spec.rb @@ -3,15 +3,43 @@ require 'spec_helper' describe 'GitlabSchema configurations' do include GraphqlHelpers - it 'shows an error if complexity is too high' do - project = create(:project, :repository) - query = graphql_query_for('project', { 'fullPath' => project.full_path }, %w(id name description)) + let(:project) { create(:project, :repository) } + let(:query) { graphql_query_for('project', { 'fullPath' => project.full_path }, %w(id name description)) } + let(:current_user) { create(:user) } - allow(GitlabSchema).to receive(:max_query_complexity).and_return 1 + describe '#max_complexity' do + context 'when complexity is too high' do + it 'shows an error' do + allow(GitlabSchema).to receive(:max_query_complexity).and_return 1 - post_graphql(query, current_user: nil) + post_graphql(query, current_user: nil) - expect(graphql_errors.first['message']).to include('which exceeds max complexity of 1') + expect(graphql_errors.first['message']).to include('which exceeds max complexity of 1') + end + end + end + + describe '#max_depth' do + context 'when query depth is too high' do + it 'shows error' do + errors = [{ "message" => "Query has depth of 2, which exceeds max depth of 1" }] + allow(GitlabSchema).to receive(:max_query_depth).and_return 1 + + post_graphql(query) + + expect(graphql_errors).to eq(errors) + end + end + + context 'when query depth is within range' do + it 'has no error' do + allow(GitlabSchema).to receive(:max_query_depth).and_return 5 + + post_graphql(query) + + expect(graphql_errors).to be_nil + end + end end context 'when IntrospectionQuery' do |