Commit 35a02dc3 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'ignore-writing-trace-if-it-already-archived' into 'master'

Disallow updating job status if the job is not running

Closes #46383

See merge request gitlab-org/gitlab-ce!19101
parents 265b1faf 890f7f49
---
title: Disallow updating job status if the job is not running
merge_request: 19101
author:
type: fixed
......@@ -123,6 +123,7 @@ module API
end
put '/:id' do
job = authenticate_job!
forbidden!('Job is not running') unless job.running?
job.trace.set(params[:trace]) if params[:trace]
......@@ -131,9 +132,9 @@ module API
case params[:state].to_s
when 'success'
job.success
job.success!
when 'failed'
job.drop(params[:failure_reason] || :unknown_failure)
job.drop!(params[:failure_reason] || :unknown_failure)
end
end
......
......@@ -830,6 +830,21 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
end
end
context 'when job has already been finished' do
before do
job.trace.set('Job failed')
job.drop!(:script_failure)
end
it 'does not update job status and job trace' do
update_job(state: 'success', trace: 'BUILD TRACE UPDATED')
expect(response).to have_gitlab_http_status(403)
expect(job.trace.raw).to eq 'Job failed'
expect(job).to be_failed
end
end
def update_job(token = job.token, **params)
new_params = params.merge(token: token)
put api("/jobs/#{job.id}"), new_params
......
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