diff options
author | GitLab Release Tools Bot <robert+release-tools@gitlab.com> | 2019-09-26 13:53:16 +0000 |
---|---|---|
committer | GitLab Release Tools Bot <robert+release-tools@gitlab.com> | 2019-09-26 13:53:16 +0000 |
commit | 7224fd1cc5bda5aa5b0e822f7e5eba66b8d87012 (patch) | |
tree | fb63588b2784b52389db6e2e977308cf6a16ccda /spec | |
parent | e5ba7aaebae30ff4a2aaf831be4315f9fffe9eff (diff) | |
parent | 90466e7009e5c1791de07590055db35921ac30c5 (diff) | |
download | gitlab-ce-7224fd1cc5bda5aa5b0e822f7e5eba66b8d87012.tar.gz |
Merge branch 'security-fp-stop-jobs-when-blocking-user-12-3' into '12-3-stable'
Cancel all running CI jobs when user is blocked
See merge request gitlab/gitlabhq!3436
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/user_spec.rb | 18 | ||||
-rw-r--r-- | spec/services/ci/cancel_user_pipelines_service_spec.rb | 23 |
2 files changed, 40 insertions, 1 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 228d1ce9964..a701b858783 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1097,11 +1097,27 @@ describe User do describe 'blocking user' do let(:user) { create(:user, name: 'John Smith') } - it "blocks user" do + it 'blocks user' do user.block expect(user.blocked?).to be_truthy end + + context 'when user has running CI pipelines' do + let(:service) { double } + + before do + pipeline = create(:ci_pipeline, :running, user: user) + create(:ci_build, :running, pipeline: pipeline) + end + + it 'cancels all running pipelines and related jobs' do + expect(Ci::CancelUserPipelinesService).to receive(:new).and_return(service) + expect(service).to receive(:execute).with(user) + + user.block + end + end end describe '.filter_items' do diff --git a/spec/services/ci/cancel_user_pipelines_service_spec.rb b/spec/services/ci/cancel_user_pipelines_service_spec.rb new file mode 100644 index 00000000000..251f21feaef --- /dev/null +++ b/spec/services/ci/cancel_user_pipelines_service_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Ci::CancelUserPipelinesService do + describe '#execute' do + let(:user) { create(:user) } + + subject { described_class.new.execute(user) } + + context 'when user has running CI pipelines' do + let(:pipeline) { create(:ci_pipeline, :running, user: user) } + let!(:build) { create(:ci_build, :running, pipeline: pipeline) } + + it 'cancels all running pipelines and related jobs' do + subject + + expect(pipeline.reload).to be_canceled + expect(build.reload).to be_canceled + end + end + end +end |