diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-16 12:07:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-16 12:07:51 +0300 |
commit | 914ea32e0efca21436220df2c10e1bfbe4ed3da9 (patch) | |
tree | e8eb3b97aea2006bd863c586b7ec41d51f654b3b /spec/services | |
parent | 3546e1bb0971347e9e9984de0799e3fb53743b33 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/ci/pipeline_trigger_service_spec.rb | 162 | ||||
-rw-r--r-- | spec/services/groups/transfer_service_spec.rb | 17 | ||||
-rw-r--r-- | spec/services/groups/update_service_spec.rb | 24 |
3 files changed, 163 insertions, 40 deletions
diff --git a/spec/services/ci/pipeline_trigger_service_spec.rb b/spec/services/ci/pipeline_trigger_service_spec.rb index 76251b5b557..24d42f402f4 100644 --- a/spec/services/ci/pipeline_trigger_service_spec.rb +++ b/spec/services/ci/pipeline_trigger_service_spec.rb @@ -11,76 +11,158 @@ describe Ci::PipelineTriggerService do describe '#execute' do let(:user) { create(:user) } - let(:trigger) { create(:ci_trigger, project: project, owner: user) } let(:result) { described_class.new(project, user, params).execute } before do project.add_developer(user) end - context 'when trigger belongs to a different project' do - let(:params) { { token: trigger.token, ref: 'master', variables: nil } } - let(:trigger) { create(:ci_trigger, project: create(:project), owner: user) } + context 'with a trigger token' do + let(:trigger) { create(:ci_trigger, project: project, owner: user) } - it 'does nothing' do - expect { result }.not_to change { Ci::Pipeline.count } - end - end - - context 'when params have an existsed trigger token' do - context 'when params have an existsed ref' do + context 'when trigger belongs to a different project' do let(:params) { { token: trigger.token, ref: 'master', variables: nil } } + let(:trigger) { create(:ci_trigger, project: create(:project), owner: user) } - it 'triggers a pipeline' do - expect { result }.to change { Ci::Pipeline.count }.by(1) - expect(result[:pipeline].ref).to eq('master') - expect(result[:pipeline].project).to eq(project) - expect(result[:pipeline].user).to eq(trigger.owner) - expect(result[:pipeline].trigger_requests.to_a) - .to eq(result[:pipeline].builds.map(&:trigger_request).uniq) - expect(result[:status]).to eq(:success) + it 'does nothing' do + expect { result }.not_to change { Ci::Pipeline.count } end + end - context 'when commit message has [ci skip]' do - before do - allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { '[ci skip]' } - end + context 'when params have an existsed trigger token' do + context 'when params have an existsed ref' do + let(:params) { { token: trigger.token, ref: 'master', variables: nil } } - it 'ignores [ci skip] and create as general' do + it 'triggers a pipeline' do expect { result }.to change { Ci::Pipeline.count }.by(1) + expect(result[:pipeline].ref).to eq('master') + expect(result[:pipeline].project).to eq(project) + expect(result[:pipeline].user).to eq(trigger.owner) + expect(result[:pipeline].trigger_requests.to_a) + .to eq(result[:pipeline].builds.map(&:trigger_request).uniq) expect(result[:status]).to eq(:success) end + + context 'when commit message has [ci skip]' do + before do + allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { '[ci skip]' } + end + + it 'ignores [ci skip] and create as general' do + expect { result }.to change { Ci::Pipeline.count }.by(1) + expect(result[:status]).to eq(:success) + end + end + + context 'when params have a variable' do + let(:params) { { token: trigger.token, ref: 'master', variables: variables } } + let(:variables) { { 'AAA' => 'AAA123' } } + + it 'has a variable' do + expect { result }.to change { Ci::PipelineVariable.count }.by(1) + .and change { Ci::TriggerRequest.count }.by(1) + expect(result[:pipeline].variables.map { |v| { v.key => v.value } }.first).to eq(variables) + expect(result[:pipeline].trigger_requests.last.variables).to be_nil + end + end end - context 'when params have a variable' do - let(:params) { { token: trigger.token, ref: 'master', variables: variables } } - let(:variables) { { 'AAA' => 'AAA123' } } + context 'when params have a non-existsed ref' do + let(:params) { { token: trigger.token, ref: 'invalid-ref', variables: nil } } - it 'has a variable' do - expect { result }.to change { Ci::PipelineVariable.count }.by(1) - .and change { Ci::TriggerRequest.count }.by(1) - expect(result[:pipeline].variables.map { |v| { v.key => v.value } }.first).to eq(variables) - expect(result[:pipeline].trigger_requests.last.variables).to be_nil + it 'does not trigger a pipeline' do + expect { result }.not_to change { Ci::Pipeline.count } + expect(result[:http_status]).to eq(400) end end end - context 'when params have a non-existsed ref' do - let(:params) { { token: trigger.token, ref: 'invalid-ref', variables: nil } } + context 'when params have a non-existsed trigger token' do + let(:params) { { token: 'invalid-token', ref: nil, variables: nil } } it 'does not trigger a pipeline' do expect { result }.not_to change { Ci::Pipeline.count } - expect(result[:http_status]).to eq(400) + expect(result).to be_nil end end end - context 'when params have a non-existsed trigger token' do - let(:params) { { token: 'invalid-token', ref: nil, variables: nil } } + context 'with a pipeline job token' do + let!(:pipeline) { create(:ci_empty_pipeline, project: project) } + let(:job) { create(:ci_build, :running, pipeline: pipeline, user: user) } + + context 'when job user does not have a permission to read a project' do + let(:params) { { token: job.token, ref: 'master', variables: nil } } + let(:job) { create(:ci_build, pipeline: pipeline, user: create(:user)) } + + it 'does nothing' do + expect { result }.not_to change { Ci::Pipeline.count } + end + end + + context 'when job is not running' do + let(:params) { { token: job.token, ref: 'master', variables: nil } } + let(:job) { create(:ci_build, :success, pipeline: pipeline, user: user) } + + it 'does nothing' do + expect { result }.not_to change { Ci::Pipeline.count } + expect(result[:message]).to eq('400 Job has to be running') + end + end - it 'does not trigger a pipeline' do - expect { result }.not_to change { Ci::Pipeline.count } - expect(result).to be_nil + context 'when params have an existsed job token' do + context 'when params have an existsed ref' do + let(:params) { { token: job.token, ref: 'master', variables: nil } } + + it 'triggers a pipeline' do + expect { result }.to change { Ci::Pipeline.count }.by(1) + expect(result[:pipeline].ref).to eq('master') + expect(result[:pipeline].project).to eq(project) + expect(result[:pipeline].user).to eq(job.user) + expect(result[:status]).to eq(:success) + end + + context 'when commit message has [ci skip]' do + before do + allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { '[ci skip]' } + end + + it 'ignores [ci skip] and create as general' do + expect { result }.to change { Ci::Pipeline.count }.by(1) + expect(result[:status]).to eq(:success) + end + end + + context 'when params have a variable' do + let(:params) { { token: job.token, ref: 'master', variables: variables } } + let(:variables) { { 'AAA' => 'AAA123' } } + + it 'has a variable' do + expect { result }.to change { Ci::PipelineVariable.count }.by(1) + .and change { Ci::Sources::Pipeline.count }.by(1) + expect(result[:pipeline].variables.map { |v| { v.key => v.value } }.first).to eq(variables) + expect(job.sourced_pipelines.last.pipeline_id).to eq(result[:pipeline].id) + end + end + end + + context 'when params have a non-existsed ref' do + let(:params) { { token: job.token, ref: 'invalid-ref', variables: nil } } + + it 'does not job a pipeline' do + expect { result }.not_to change { Ci::Pipeline.count } + expect(result[:http_status]).to eq(400) + end + end + end + + context 'when params have a non-existsed trigger token' do + let(:params) { { token: 'invalid-token', ref: nil, variables: nil } } + + it 'does not trigger a pipeline' do + expect { result }.not_to change { Ci::Pipeline.count } + expect(result).to be_nil + end end end end diff --git a/spec/services/groups/transfer_service_spec.rb b/spec/services/groups/transfer_service_spec.rb index 0cbb3122bb0..5ef1fb1932f 100644 --- a/spec/services/groups/transfer_service_spec.rb +++ b/spec/services/groups/transfer_service_spec.rb @@ -426,5 +426,22 @@ describe Groups::TransferService do end end end + + context 'when a project in group has container images' do + let(:group) { create(:group, :public, :nested) } + let!(:project) { create(:project, :repository, :public, namespace: group) } + + before do + stub_container_registry_tags(repository: /image/, tags: %w[rc1]) + create(:container_repository, project: project, name: :image) + create(:group_member, :owner, group: new_parent_group, user: user) + end + + it 'does not allow group to be transferred' do + transfer_service.execute(new_parent_group) + + expect(transfer_service.error).to match(/Docker images in their Container Registry/) + end + end end end diff --git a/spec/services/groups/update_service_spec.rb b/spec/services/groups/update_service_spec.rb index 12e9c2b2f3a..ca8eaf4c970 100644 --- a/spec/services/groups/update_service_spec.rb +++ b/spec/services/groups/update_service_spec.rb @@ -148,6 +148,30 @@ describe Groups::UpdateService do end end + context 'projects in group have container images' do + let(:service) { described_class.new(public_group, user, path: SecureRandom.hex) } + let(:project) { create(:project, :internal, group: public_group) } + + before do + stub_container_registry_tags(repository: /image/, tags: %w[rc1]) + create(:container_repository, project: project, name: :image) + end + + it 'does not allow path to be changed' do + result = described_class.new(public_group, user, path: 'new-path').execute + + expect(result).to eq false + expect(public_group.errors[:base].first).to match(/Docker images in their Container Registry/) + end + + it 'allows other settings to be changed' do + result = described_class.new(public_group, user, name: 'new-name').execute + + expect(result).to eq true + expect(public_group.reload.name).to eq('new-name') + end + end + context 'for a subgroup' do let(:subgroup) { create(:group, :private, parent: private_group) } |