Commit edf29b57 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'fix/regression-in-runners-registration-v1-api' into 'master'

Fix regression in runners registration v1 api

See merge request !9904
parents 2526d2dc 2e1b2233
...@@ -24,13 +24,13 @@ module Ci ...@@ -24,13 +24,13 @@ module Ci
optional :locked, type: Boolean, desc: 'Lock this runner for this specific project' optional :locked, type: Boolean, desc: 'Lock this runner for this specific project'
end end
post "register" do post "register" do
runner_params = declared(params, include_missing: false) runner_params = declared(params, include_missing: false).except(:token)
runner = runner =
if runner_registration_token_valid? if runner_registration_token_valid?
# Create shared runner. Requires admin access # Create shared runner. Requires admin access
Ci::Runner.create(runner_params.merge(is_shared: true)) Ci::Runner.create(runner_params.merge(is_shared: true))
elsif project = Project.find_by(runners_token: runner_params[:token]) elsif project = Project.find_by(runners_token: params[:token])
# Create a specific runner for project. # Create a specific runner for project.
project.runners.create(runner_params) project.runners.create(runner_params)
end end
......
...@@ -39,6 +39,7 @@ describe API::Runner do ...@@ -39,6 +39,7 @@ describe API::Runner do
expect(json_response['id']).to eq(runner.id) expect(json_response['id']).to eq(runner.id)
expect(json_response['token']).to eq(runner.token) expect(json_response['token']).to eq(runner.token)
expect(runner.run_untagged).to be true expect(runner.run_untagged).to be true
expect(runner.token).not_to eq(registration_token)
end end
context 'when project token is used' do context 'when project token is used' do
...@@ -49,6 +50,8 @@ describe API::Runner do ...@@ -49,6 +50,8 @@ describe API::Runner do
expect(response).to have_http_status 201 expect(response).to have_http_status 201
expect(project.runners.size).to eq(1) expect(project.runners.size).to eq(1)
expect(Ci::Runner.first.token).not_to eq(registration_token)
expect(Ci::Runner.first.token).not_to eq(project.runners_token)
end end
end end
end end
......
...@@ -18,6 +18,7 @@ describe Ci::API::Runners do ...@@ -18,6 +18,7 @@ describe Ci::API::Runners do
it 'creates runner with default values' do it 'creates runner with default values' do
expect(response).to have_http_status 201 expect(response).to have_http_status 201
expect(Ci::Runner.first.run_untagged).to be true expect(Ci::Runner.first.run_untagged).to be true
expect(Ci::Runner.first.token).not_to eq(registration_token)
end end
end end
...@@ -74,6 +75,8 @@ describe Ci::API::Runners do ...@@ -74,6 +75,8 @@ describe Ci::API::Runners do
it 'creates runner' do it 'creates runner' do
expect(response).to have_http_status 201 expect(response).to have_http_status 201
expect(project.runners.size).to eq(1) expect(project.runners.size).to eq(1)
expect(Ci::Runner.first.token).not_to eq(registration_token)
expect(Ci::Runner.first.token).not_to eq(project.runners_token)
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