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>2022-07-20 18:40:28 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-07-20 18:40:28 +0300
commitb595cb0c1dec83de5bdee18284abe86614bed33b (patch)
tree8c3d4540f193c5ff98019352f554e921b3a41a72 /spec/requests/api/graphql/ci
parent2f9104a328fc8a4bddeaa4627b595166d24671d0 (diff)
Add latest changes from gitlab-org/gitlab@15-2-stable-eev15.2.0-rc42
Diffstat (limited to 'spec/requests/api/graphql/ci')
-rw-r--r--spec/requests/api/graphql/ci/group_variables_spec.rb67
-rw-r--r--spec/requests/api/graphql/ci/instance_variables_spec.rb60
-rw-r--r--spec/requests/api/graphql/ci/job_spec.rb4
-rw-r--r--spec/requests/api/graphql/ci/jobs_spec.rb6
-rw-r--r--spec/requests/api/graphql/ci/manual_variables_spec.rb95
-rw-r--r--spec/requests/api/graphql/ci/pipelines_spec.rb4
-rw-r--r--spec/requests/api/graphql/ci/project_variables_spec.rb67
-rw-r--r--spec/requests/api/graphql/ci/runner_spec.rb2
-rw-r--r--spec/requests/api/graphql/ci/stages_spec.rb2
9 files changed, 298 insertions, 9 deletions
diff --git a/spec/requests/api/graphql/ci/group_variables_spec.rb b/spec/requests/api/graphql/ci/group_variables_spec.rb
new file mode 100644
index 00000000000..5ea6646ec2c
--- /dev/null
+++ b/spec/requests/api/graphql/ci/group_variables_spec.rb
@@ -0,0 +1,67 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'Query.group(fullPath).ciVariables' do
+ include GraphqlHelpers
+
+ let_it_be(:group) { create(:group) }
+ let_it_be(:user) { create(:user) }
+
+ let(:query) do
+ %(
+ query {
+ group(fullPath: "#{group.full_path}") {
+ ciVariables {
+ nodes {
+ id
+ key
+ value
+ variableType
+ protected
+ masked
+ raw
+ environmentScope
+ }
+ }
+ }
+ }
+ )
+ end
+
+ context 'when the user can administer the group' do
+ before do
+ group.add_owner(user)
+ end
+
+ it "returns the group's CI variables" do
+ variable = create(:ci_group_variable, group: group, key: 'TEST_VAR', value: 'test',
+ masked: false, protected: true, raw: true, environment_scope: 'staging')
+
+ post_graphql(query, current_user: user)
+
+ expect(graphql_data.dig('group', 'ciVariables', 'nodes')).to contain_exactly({
+ 'id' => variable.to_global_id.to_s,
+ 'key' => 'TEST_VAR',
+ 'value' => 'test',
+ 'variableType' => 'ENV_VAR',
+ 'masked' => false,
+ 'protected' => true,
+ 'raw' => true,
+ 'environmentScope' => 'staging'
+ })
+ end
+ end
+
+ context 'when the user cannot administer the group' do
+ it 'returns nothing' do
+ create(:ci_group_variable, group: group, value: 'verysecret', masked: true)
+
+ group.add_developer(user)
+
+ post_graphql(query, current_user: user)
+
+ expect(graphql_data.dig('group', 'ciVariables')).to be_nil
+ end
+ end
+end
diff --git a/spec/requests/api/graphql/ci/instance_variables_spec.rb b/spec/requests/api/graphql/ci/instance_variables_spec.rb
new file mode 100644
index 00000000000..7acf73a4e7a
--- /dev/null
+++ b/spec/requests/api/graphql/ci/instance_variables_spec.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'Query.ciVariables' do
+ include GraphqlHelpers
+
+ let(:query) do
+ %(
+ query {
+ ciVariables {
+ nodes {
+ id
+ key
+ value
+ variableType
+ protected
+ masked
+ raw
+ environmentScope
+ }
+ }
+ }
+ )
+ end
+
+ context 'when the user is an admin' do
+ let_it_be(:user) { create(:admin) }
+
+ it "returns the instance's CI variables" do
+ variable = create(:ci_instance_variable, key: 'TEST_VAR', value: 'test',
+ masked: false, protected: true, raw: true)
+
+ post_graphql(query, current_user: user)
+
+ expect(graphql_data.dig('ciVariables', 'nodes')).to contain_exactly({
+ 'id' => variable.to_global_id.to_s,
+ 'key' => 'TEST_VAR',
+ 'value' => 'test',
+ 'variableType' => 'ENV_VAR',
+ 'masked' => false,
+ 'protected' => true,
+ 'raw' => true,
+ 'environmentScope' => nil
+ })
+ end
+ end
+
+ context 'when the user is not an admin' do
+ let_it_be(:user) { create(:user) }
+
+ it 'returns nothing' do
+ create(:ci_instance_variable, value: 'verysecret', masked: true)
+
+ post_graphql(query, current_user: user)
+
+ expect(graphql_data.dig('ciVariables')).to be_nil
+ end
+ end
+end
diff --git a/spec/requests/api/graphql/ci/job_spec.rb b/spec/requests/api/graphql/ci/job_spec.rb
index 2fb90dcd92b..3721155c71b 100644
--- a/spec/requests/api/graphql/ci/job_spec.rb
+++ b/spec/requests/api/graphql/ci/job_spec.rb
@@ -13,8 +13,8 @@ RSpec.describe 'Query.project(fullPath).pipelines.job(id)' do
let_it_be(:project) { create(:project, :repository, :public) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
- let_it_be(:prepare_stage) { create(:ci_stage_entity, pipeline: pipeline, project: project, name: 'prepare') }
- let_it_be(:test_stage) { create(:ci_stage_entity, pipeline: pipeline, project: project, name: 'test') }
+ let_it_be(:prepare_stage) { create(:ci_stage, pipeline: pipeline, project: project, name: 'prepare') }
+ let_it_be(:test_stage) { create(:ci_stage, pipeline: pipeline, project: project, name: 'test') }
let_it_be(:job_1) { create(:ci_build, pipeline: pipeline, stage: 'prepare', name: 'Job 1') }
let_it_be(:job_2) { create(:ci_build, pipeline: pipeline, stage: 'test', name: 'Job 2') }
diff --git a/spec/requests/api/graphql/ci/jobs_spec.rb b/spec/requests/api/graphql/ci/jobs_spec.rb
index d1737fc22ae..8c4ab13fc35 100644
--- a/spec/requests/api/graphql/ci/jobs_spec.rb
+++ b/spec/requests/api/graphql/ci/jobs_spec.rb
@@ -14,7 +14,7 @@ RSpec.describe 'Query.project.pipeline' do
describe '.stages.groups.jobs' do
let(:pipeline) do
pipeline = create(:ci_pipeline, project: project, user: user)
- stage = create(:ci_stage_entity, project: project, pipeline: pipeline, name: 'first', position: 1)
+ stage = create(:ci_stage, project: project, pipeline: pipeline, name: 'first', position: 1)
create(:ci_build, stage_id: stage.id, pipeline: pipeline, name: 'my test job', scheduling_type: :stage)
pipeline
@@ -84,8 +84,8 @@ RSpec.describe 'Query.project.pipeline' do
context 'when there is more than one stage and job needs' do
before do
- build_stage = create(:ci_stage_entity, position: 2, name: 'build', project: project, pipeline: pipeline)
- test_stage = create(:ci_stage_entity, position: 3, name: 'test', project: project, pipeline: pipeline)
+ build_stage = create(:ci_stage, position: 2, name: 'build', project: project, pipeline: pipeline)
+ test_stage = create(:ci_stage, position: 3, name: 'test', project: project, pipeline: pipeline)
create(:ci_build, pipeline: pipeline, name: 'docker 1 2', scheduling_type: :stage, stage: build_stage, stage_idx: build_stage.position)
create(:ci_build, pipeline: pipeline, name: 'docker 2 2', stage: build_stage, stage_idx: build_stage.position, scheduling_type: :dag)
diff --git a/spec/requests/api/graphql/ci/manual_variables_spec.rb b/spec/requests/api/graphql/ci/manual_variables_spec.rb
new file mode 100644
index 00000000000..b7aa76511a3
--- /dev/null
+++ b/spec/requests/api/graphql/ci/manual_variables_spec.rb
@@ -0,0 +1,95 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'Query.project(fullPath).pipelines.jobs.manualVariables' do
+ include GraphqlHelpers
+
+ let_it_be(:project) { create(:project) }
+ let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
+ let_it_be(:user) { create(:user) }
+
+ let(:query) do
+ %(
+ query {
+ project(fullPath: "#{project.full_path}") {
+ pipelines {
+ nodes {
+ jobs {
+ nodes {
+ manualVariables {
+ nodes {
+ key
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ )
+ end
+
+ before do
+ project.add_maintainer(user)
+ end
+
+ it 'returns the manual variables for the jobs' do
+ job = create(:ci_build, :manual, pipeline: pipeline)
+ create(:ci_job_variable, key: 'MANUAL_TEST_VAR', job: job)
+
+ post_graphql(query, current_user: user)
+
+ variables_data = graphql_data.dig('project', 'pipelines', 'nodes').first
+ .dig('jobs', 'nodes').flat_map { |job| job.dig('manualVariables', 'nodes') }
+ expect(variables_data.map { |var| var['key'] }).to match_array(['MANUAL_TEST_VAR'])
+ end
+
+ it 'does not fetch job variables for jobs that are not manual' do
+ job = create(:ci_build, pipeline: pipeline)
+ create(:ci_job_variable, key: 'THIS_VAR_WOULD_SHOULD_NEVER_EXIST', job: job)
+
+ post_graphql(query, current_user: user)
+
+ variables_data = graphql_data.dig('project', 'pipelines', 'nodes').first
+ .dig('jobs', 'nodes').flat_map { |job| job.dig('manualVariables', 'nodes') }
+ expect(variables_data).to be_empty
+ end
+
+ it 'does not fetch job variables for bridges' do
+ create(:ci_bridge, :manual, pipeline: pipeline)
+
+ post_graphql(query, current_user: user)
+
+ variables_data = graphql_data.dig('project', 'pipelines', 'nodes').first
+ .dig('jobs', 'nodes').flat_map { |job| job.dig('manualVariables', 'nodes') }
+ expect(variables_data).to be_empty
+ end
+
+ it 'does not produce N+1 queries', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/367991' do
+ second_user = create(:user)
+ project.add_maintainer(second_user)
+ job = create(:ci_build, :manual, pipeline: pipeline)
+ create(:ci_job_variable, key: 'MANUAL_TEST_VAR_1', job: job)
+
+ control_count = ActiveRecord::QueryRecorder.new do
+ post_graphql(query, current_user: user)
+ end
+
+ variables_data = graphql_data.dig('project', 'pipelines', 'nodes').first
+ .dig('jobs', 'nodes').flat_map { |job| job.dig('manualVariables', 'nodes') }
+ expect(variables_data.map { |var| var['key'] }).to match_array(['MANUAL_TEST_VAR_1'])
+
+ job = create(:ci_build, :manual, pipeline: pipeline)
+ create(:ci_job_variable, key: 'MANUAL_TEST_VAR_2', job: job)
+
+ expect do
+ post_graphql(query, current_user: second_user)
+ end.not_to exceed_query_limit(control_count)
+
+ variables_data = graphql_data.dig('project', 'pipelines', 'nodes').first
+ .dig('jobs', 'nodes').flat_map { |job| job.dig('manualVariables', 'nodes') }
+ expect(variables_data.map { |var| var['key'] }).to match_array(%w(MANUAL_TEST_VAR_1 MANUAL_TEST_VAR_2))
+ end
+end
diff --git a/spec/requests/api/graphql/ci/pipelines_spec.rb b/spec/requests/api/graphql/ci/pipelines_spec.rb
index 741af676b6d..a968e5508cb 100644
--- a/spec/requests/api/graphql/ci/pipelines_spec.rb
+++ b/spec/requests/api/graphql/ci/pipelines_spec.rb
@@ -86,8 +86,8 @@ RSpec.describe 'Query.project(fullPath).pipelines' do
describe '.stages' do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:pipeline) { create(:ci_empty_pipeline, project: project) }
- let_it_be(:stage) { create(:ci_stage_entity, pipeline: pipeline, project: project) }
- let_it_be(:other_stage) { create(:ci_stage_entity, pipeline: pipeline, project: project, name: 'other') }
+ let_it_be(:stage) { create(:ci_stage, pipeline: pipeline, project: project) }
+ let_it_be(:other_stage) { create(:ci_stage, pipeline: pipeline, project: project, name: 'other') }
let(:first_n) { var('Int') }
let(:query_path) do
diff --git a/spec/requests/api/graphql/ci/project_variables_spec.rb b/spec/requests/api/graphql/ci/project_variables_spec.rb
new file mode 100644
index 00000000000..e61f146b24c
--- /dev/null
+++ b/spec/requests/api/graphql/ci/project_variables_spec.rb
@@ -0,0 +1,67 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'Query.project(fullPath).ciVariables' do
+ include GraphqlHelpers
+
+ let_it_be(:project) { create(:project) }
+ let_it_be(:user) { create(:user) }
+
+ let(:query) do
+ %(
+ query {
+ project(fullPath: "#{project.full_path}") {
+ ciVariables {
+ nodes {
+ id
+ key
+ value
+ variableType
+ protected
+ masked
+ raw
+ environmentScope
+ }
+ }
+ }
+ }
+ )
+ end
+
+ context 'when the user can administer builds' do
+ before do
+ project.add_maintainer(user)
+ end
+
+ it "returns the project's CI variables" do
+ variable = create(:ci_variable, project: project, key: 'TEST_VAR', value: 'test',
+ masked: false, protected: true, raw: true, environment_scope: 'production')
+
+ post_graphql(query, current_user: user)
+
+ expect(graphql_data.dig('project', 'ciVariables', 'nodes')).to contain_exactly({
+ 'id' => variable.to_global_id.to_s,
+ 'key' => 'TEST_VAR',
+ 'value' => 'test',
+ 'variableType' => 'ENV_VAR',
+ 'masked' => false,
+ 'protected' => true,
+ 'raw' => true,
+ 'environmentScope' => 'production'
+ })
+ end
+ end
+
+ context 'when the user cannot administer builds' do
+ it 'returns nothing' do
+ create(:ci_variable, project: project, value: 'verysecret', masked: true)
+
+ project.add_developer(user)
+
+ post_graphql(query, current_user: user)
+
+ expect(graphql_data.dig('project', 'ciVariables')).to be_nil
+ end
+ end
+end
diff --git a/spec/requests/api/graphql/ci/runner_spec.rb b/spec/requests/api/graphql/ci/runner_spec.rb
index 446d1fb1bdb..e17a83d8e47 100644
--- a/spec/requests/api/graphql/ci/runner_spec.rb
+++ b/spec/requests/api/graphql/ci/runner_spec.rb
@@ -424,7 +424,7 @@ RSpec.describe 'Query.runner(id)' do
let(:user) { create(:user) }
before do
- group.add_user(user, Gitlab::Access::OWNER)
+ group.add_member(user, Gitlab::Access::OWNER)
end
it_behaves_like 'retrieval with no admin url' do
diff --git a/spec/requests/api/graphql/ci/stages_spec.rb b/spec/requests/api/graphql/ci/stages_spec.rb
index 50d2cf75097..1edd6e58486 100644
--- a/spec/requests/api/graphql/ci/stages_spec.rb
+++ b/spec/requests/api/graphql/ci/stages_spec.rb
@@ -36,7 +36,7 @@ RSpec.describe 'Query.project.pipeline.stages' do
end
before_all do
- create(:ci_stage_entity, pipeline: pipeline, name: 'deploy')
+ create(:ci_stage, pipeline: pipeline, name: 'deploy')
create_list(:ci_build, 2, pipeline: pipeline, stage: 'deploy')
end