Commit fac725c9 authored by Stan Hu's avatar Stan Hu

Merge branch '53676-ip-address-of-gitlab-runner-is-wrong-in-the-runners-description' into 'master'

Get remote address for runner

Closes #53676

See merge request gitlab-org/gitlab-ce!24624
parents a59563a1 cb67423d
---
title: Get remote IP address of runner
merge_request: 24624
author:
type: changed
...@@ -26,7 +26,7 @@ module API ...@@ -26,7 +26,7 @@ module API
end end
def get_runner_ip def get_runner_ip
{ ip_address: request.ip } { ip_address: request.env["HTTP_X_FORWARDED_FOR"] || request.ip }
end end
def current_runner def current_runner
......
...@@ -211,7 +211,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do ...@@ -211,7 +211,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
it "sets the runner's ip_address" do it "sets the runner's ip_address" do
post api('/runners'), post api('/runners'),
params: { token: registration_token }, params: { token: registration_token },
headers: { 'REMOTE_ADDR' => '123.111.123.111' } headers: { 'X-Forwarded-For' => '123.111.123.111' }
expect(response).to have_gitlab_http_status 201 expect(response).to have_gitlab_http_status 201
expect(Ci::Runner.first.ip_address).to eq('123.111.123.111') expect(Ci::Runner.first.ip_address).to eq('123.111.123.111')
...@@ -520,7 +520,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do ...@@ -520,7 +520,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
it "sets the runner's ip_address" do it "sets the runner's ip_address" do
post api('/jobs/request'), post api('/jobs/request'),
params: { token: runner.token }, params: { token: runner.token },
headers: { 'User-Agent' => user_agent, 'REMOTE_ADDR' => '123.222.123.222' } headers: { 'User-Agent' => user_agent, 'X-Forwarded-For' => '123.222.123.222' }
expect(response).to have_gitlab_http_status 201 expect(response).to have_gitlab_http_status 201
expect(runner.reload.ip_address).to eq('123.222.123.222') expect(runner.reload.ip_address).to eq('123.222.123.222')
......
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