diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-07-03 18:09:34 +0300 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-07-05 01:46:11 +0300 |
commit | 18521584bd6cfc8de9511722696e87aef59795c5 (patch) | |
tree | fa5b83fca15ff3d6f7a70fd9b87bc31ad575a08a /spec/controllers/health_controller_spec.rb | |
parent | 5af1fcd6f329858d757bab0d67cb50af6c820160 (diff) |
Remove the need to use health check token
in favor of whitelist that will be used to
control the access to monitoring resources
Diffstat (limited to 'spec/controllers/health_controller_spec.rb')
-rw-r--r-- | spec/controllers/health_controller_spec.rb | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/spec/controllers/health_controller_spec.rb b/spec/controllers/health_controller_spec.rb index e7c19b47a6a..3e4370652d0 100644 --- a/spec/controllers/health_controller_spec.rb +++ b/spec/controllers/health_controller_spec.rb @@ -3,17 +3,19 @@ require 'spec_helper' describe HealthController do include StubENV - let(:token) { current_application_settings.health_check_access_token } let(:json_response) { JSON.parse(response.body) } + let(:whitelisted_ip) { '127.0.0.1' } + let(:not_whitelisted_ip) { '127.0.0.2' } before do + allow(Settings.monitoring).to receive(:ip_whitelist).and_return([IPAddr.new(whitelisted_ip)]) stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false') end describe '#readiness' do - context 'authorization token provided' do + context 'accessed from whitelisted ip' do before do - request.headers['TOKEN'] = token + allow(Gitlab::RequestContext).to receive(:client_ip).and_return(whitelisted_ip) end it 'returns proper response' do @@ -25,7 +27,11 @@ describe HealthController do end end - context 'without authorization token' do + context 'accessed from not whitelisted ip' do + before do + allow(Gitlab::RequestContext).to receive(:client_ip).and_return(not_whitelisted_ip) + end + it 'returns proper response' do get :readiness expect(response.status).to eq(404) @@ -34,9 +40,9 @@ describe HealthController do end describe '#liveness' do - context 'authorization token provided' do + context 'accessed from whitelisted ip' do before do - request.headers['TOKEN'] = token + allow(Gitlab::RequestContext).to receive(:client_ip).and_return(whitelisted_ip) end it 'returns proper response' do @@ -47,7 +53,11 @@ describe HealthController do end end - context 'without authorization token' do + context 'accessed from not whitelisted ip' do + before do + allow(Gitlab::RequestContext).to receive(:client_ip).and_return(not_whitelisted_ip) + end + it 'returns proper response' do get :liveness expect(response.status).to eq(404) |