BigW Consortium Gitlab

Commit df313634 by Grzegorz Bizon Committed by Grzegorz Bizon

Do not allow to modify build if it has been erased

parent 21152d7d
......@@ -38,6 +38,8 @@ module Ci
authenticate_runner!
update_runner_last_contact
build = Ci::Build.where(runner_id: current_runner.id).running.find(params[:id])
forbidden!('Build has been erased!') if build.erased?
build.update_attributes(trace: params[:trace]) if params[:trace]
case params[:state].to_s
......@@ -99,6 +101,7 @@ module Ci
not_found! unless build
authenticate_build_token!(build)
forbidden!('Build is not running!') unless build.running?
forbidden!('Build has been erased!') if build.erased?
artifacts_upload_path = ArtifactUploader.artifacts_upload_path
artifacts = uploaded_file(:file, artifacts_upload_path)
......
......@@ -131,39 +131,41 @@ describe Ci::API::API do
end
describe "PUT /builds/:id" do
let(:commit) { FactoryGirl.create(:ci_commit, project: project)}
let(:build) { FactoryGirl.create(:ci_build, commit: commit, runner_id: runner.id) }
let(:commit) {create(:ci_commit, project: project)}
let(:build) { create(:ci_build_with_trace, commit: commit, runner_id: runner.id) }
it "should update a running build" do
before do
build.run!
put ci_api("/builds/#{build.id}"), token: runner.token
end
it "should update a running build" do
expect(response.status).to eq(200)
end
it 'Should not override trace information when no trace is given' do
build.run!
build.update!(trace: 'hello_world')
put ci_api("/builds/#{build.id}"), token: runner.token
expect(build.reload.trace).to eq 'hello_world'
it 'should not override trace information when no trace is given' do
expect(build.reload.trace).to eq 'BUILD TRACE'
end
context 'build has been erased' do
let(:build) { create(:ci_build, runner_id: runner.id, erased_at: Time.now) }
it 'should respond with forbidden' do
expect(response.status).to eq 403
end
end
end
describe 'DELETE /builds/:id/content' do
let(:build) { create(:ci_build_with_trace, :artifacts, :success) }
before { delete ci_api("/builds/#{build.id}/content"), token: build.token }
let!(:build) { create(:ci_build_with_trace, :artifacts, :success) }
it 'should respond with valid status' do
it 'should erase build content' do
expect(response.status).to eq 200
end
it 'should remove build artifacts' do
expect(build.trace).to be_empty
expect(build.artifacts_file.exists?).to be_falsy
expect(build.artifacts_metadata.exists?).to be_falsy
end
it 'should remove build trace' do
expect(build.trace).to be_empty
end
end
context "Artifacts" do
......@@ -209,9 +211,10 @@ describe Ci::API::API do
end
end
context 'token is invalid' do
it 'should respond with forbidden'do
post authorize_url, { token: 'invalid', filesize: 100 }
context 'authorization token is invalid' do
before { post authorize_url, { token: 'invalid', filesize: 100 } }
it 'should respond with forbidden' do
expect(response.status).to eq(403)
end
end
......@@ -224,6 +227,15 @@ describe Ci::API::API do
allow(ArtifactUploader).to receive(:artifacts_upload_path).and_return('/')
end
context 'build has been erased' do
let(:build) { create(:ci_build, erased_at: Time.now) }
before { upload_artifacts(file_upload, headers_with_token) }
it 'should respond with forbidden' do
expect(response.status).to eq 403
end
end
context "should post artifact to running build" do
it "uses regual file post" do
upload_artifacts(file_upload, headers_with_token, false)
......@@ -252,7 +264,9 @@ describe Ci::API::API do
let(:stored_artifacts_file) { build.reload.artifacts_file.file }
let(:stored_metadata_file) { build.reload.artifacts_metadata.file }
before { post(post_url, post_data, headers_with_token) }
before do
post(post_url, post_data, headers_with_token)
end
context 'post data accelerated by workhorse is correct' do
let(:post_data) do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment