Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-04-27 11:57:43 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-04-27 11:57:43 +0300
commitbc299f54e841488b4ab37777761db1dfc7f3b60e (patch)
treebf58693acb03633a63138874072e3d3af3ee9f76 /spec/support/shared_examples
parent2fad41087674984a064cf6a312ac34c16bb2a1aa (diff)
Add latest changes from gitlab-org/security/gitlab@13-11-stable-ee
Diffstat (limited to 'spec/support/shared_examples')
-rw-r--r--spec/support/shared_examples/requests/graphql_shared_examples.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/support/shared_examples/requests/graphql_shared_examples.rb b/spec/support/shared_examples/requests/graphql_shared_examples.rb
index a66bc7112fe..d133c5ea641 100644
--- a/spec/support/shared_examples/requests/graphql_shared_examples.rb
+++ b/spec/support/shared_examples/requests/graphql_shared_examples.rb
@@ -10,6 +10,52 @@ RSpec.shared_examples 'a working graphql query' do
end
end
+RSpec.shared_examples 'a working GraphQL mutation' do
+ include GraphqlHelpers
+
+ before do
+ post_graphql_mutation(mutation, current_user: current_user, token: token)
+ end
+
+ shared_examples 'allows access to the mutation' do
+ let(:scopes) { ['api'] }
+
+ it_behaves_like 'a working graphql query' do
+ it 'returns data' do
+ expect(graphql_data.compact).not_to be_empty
+ end
+ end
+ end
+
+ shared_examples 'prevents access to the mutation' do
+ let(:scopes) { ['read_api'] }
+
+ it 'does not resolve the mutation' do
+ expect(graphql_data.compact).to be_empty
+ expect(graphql_errors).to be_present
+ end
+ end
+
+ context 'with a personal access token' do
+ let(:token) do
+ pat = create(:personal_access_token, user: current_user, scopes: scopes)
+ { personal_access_token: pat }
+ end
+
+ it_behaves_like 'prevents access to the mutation'
+ it_behaves_like 'allows access to the mutation'
+ end
+
+ context 'with an OAuth token' do
+ let(:token) do
+ { oauth_access_token: create(:oauth_access_token, resource_owner: current_user, scopes: scopes.join(' ')) }
+ end
+
+ it_behaves_like 'prevents access to the mutation'
+ it_behaves_like 'allows access to the mutation'
+ end
+end
+
RSpec.shared_examples 'a mutation on an unauthorized resource' do
it_behaves_like 'a mutation that returns top-level errors',
errors: [::Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR]