BigW Consortium Gitlab

Change response for /ci/api/v1/builds/register.json from 404 to 204

parent 404f438f
...@@ -269,6 +269,10 @@ module API ...@@ -269,6 +269,10 @@ module API
render_api_error!('304 Not Modified', 304) render_api_error!('304 Not Modified', 304)
end end
def no_content!
render_api_error!('204 No Content', 204)
end
def render_validation_error!(model) def render_validation_error!(model)
if model.errors.any? if model.errors.any?
render_api_error!(model.errors.messages || '400 Bad Request', 400) render_api_error!(model.errors.messages || '400 Bad Request', 400)
......
...@@ -27,7 +27,7 @@ module Ci ...@@ -27,7 +27,7 @@ module Ci
else else
Gitlab::Metrics.add_event(:build_not_found) Gitlab::Metrics.add_event(:build_not_found)
not_found! build_not_found!
end end
end end
......
...@@ -32,6 +32,14 @@ module Ci ...@@ -32,6 +32,14 @@ module Ci
end end
end end
def build_not_found!
if headers['User-Agent'].match(/gitlab-ci-multi-runner \d+\.\d+\.\d+(~beta\.\d+\.g[0-9a-f]+)? /)
no_content!
else
not_found!
end
end
def current_runner def current_runner
@runner ||= Runner.find_by_token(params[:token].to_s) @runner ||= Runner.find_by_token(params[:token].to_s)
end end
......
...@@ -15,6 +15,25 @@ describe Ci::API::API do ...@@ -15,6 +15,25 @@ describe Ci::API::API do
describe "POST /builds/register" do describe "POST /builds/register" do
let!(:build) { create(:ci_build, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) } let!(:build) { create(:ci_build, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) }
let(:user_agent) { 'gitlab-ci-multi-runner 1.5.2 (1-5-stable; go1.6.3; linux/amd64)' }
shared_examples 'no builds available' do
context 'when runner sends version in User-Agent' do
context 'for stable version' do
it { expect(response).to have_http_status(204) }
end
context 'for beta version' do
let(:user_agent) { 'gitlab-ci-multi-runner 1.6.0~beta.167.g2b2bacc (1-5-stable; go1.6.3; linux/amd64)' }
it { expect(response).to have_http_status(204) }
end
end
context "when runner doesn't send version in User-Agent" do
let(:user_agent) { 'Go-http-client/1.1' }
it { expect(response).to have_http_status(404) }
end
end
it "starts a build" do it "starts a build" do
register_builds info: { platform: :darwin } register_builds info: { platform: :darwin }
...@@ -33,36 +52,30 @@ describe Ci::API::API do ...@@ -33,36 +52,30 @@ describe Ci::API::API do
context 'when builds are finished' do context 'when builds are finished' do
before do before do
build.success build.success
end
it "returns 404 error if no builds for specific runner" do
register_builds register_builds
expect(response).to have_http_status(404)
end end
it_behaves_like 'no builds available'
end end
context 'for other project with builds' do context 'for other project with builds' do
before do before do
build.success build.success
create(:ci_build, :pending) create(:ci_build, :pending)
end
it "returns 404 error if no builds for shared runner" do
register_builds register_builds
expect(response).to have_http_status(404)
end end
it_behaves_like 'no builds available'
end end
context 'for shared runner' do context 'for shared runner' do
let(:shared_runner) { create(:ci_runner, token: "SharedRunner") } let(:shared_runner) { create(:ci_runner, token: "SharedRunner") }
it "should return 404 error if no builds for shared runner" do before do
register_builds shared_runner.token register_builds shared_runner.token
expect(response).to have_http_status(404)
end end
it_behaves_like 'no builds available'
end end
context 'for triggered build' do context 'for triggered build' do
...@@ -136,18 +149,17 @@ describe Ci::API::API do ...@@ -136,18 +149,17 @@ describe Ci::API::API do
end end
context 'when runner is not allowed to pick untagged builds' do context 'when runner is not allowed to pick untagged builds' do
before { runner.update_column(:run_untagged, false) } before do
runner.update_column(:run_untagged, false)
it 'does not pick build' do
register_builds register_builds
expect(response).to have_http_status 404
end end
it_behaves_like 'no builds available'
end end
end end
def register_builds(token = runner.token, **params) def register_builds(token = runner.token, **params)
post ci_api("/builds/register"), params.merge(token: token) post ci_api("/builds/register"), params.merge(token: token), {'User-Agent' => user_agent}
end end
end end
......
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