2017-04-07 10:27:15 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe HealthController do
|
|
|
|
include StubENV
|
|
|
|
|
|
|
|
let(:json_response) { JSON.parse(response.body) }
|
2017-07-03 15:09:34 +00:00
|
|
|
let(:whitelisted_ip) { '127.0.0.1' }
|
|
|
|
let(:not_whitelisted_ip) { '127.0.0.2' }
|
2017-04-07 10:27:15 +00:00
|
|
|
|
|
|
|
before do
|
2017-07-03 15:09:34 +00:00
|
|
|
allow(Settings.monitoring).to receive(:ip_whitelist).and_return([IPAddr.new(whitelisted_ip)])
|
2017-04-07 10:27:15 +00:00
|
|
|
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#readiness' do
|
2017-07-03 15:09:34 +00:00
|
|
|
context 'accessed from whitelisted ip' do
|
2017-04-07 10:27:15 +00:00
|
|
|
before do
|
2017-07-03 15:09:34 +00:00
|
|
|
allow(Gitlab::RequestContext).to receive(:client_ip).and_return(whitelisted_ip)
|
2017-04-07 10:27:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns proper response' do
|
|
|
|
get :readiness
|
|
|
|
expect(json_response['db_check']['status']).to eq('ok')
|
|
|
|
expect(json_response['redis_check']['status']).to eq('ok')
|
|
|
|
expect(json_response['fs_shards_check']['status']).to eq('ok')
|
|
|
|
expect(json_response['fs_shards_check']['labels']['shard']).to eq('default')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-03 15:09:34 +00:00
|
|
|
context 'accessed from not whitelisted ip' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::RequestContext).to receive(:client_ip).and_return(not_whitelisted_ip)
|
|
|
|
end
|
|
|
|
|
2017-04-07 10:27:15 +00:00
|
|
|
it 'returns proper response' do
|
|
|
|
get :readiness
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#liveness' do
|
2017-07-03 15:09:34 +00:00
|
|
|
context 'accessed from whitelisted ip' do
|
2017-04-07 10:27:15 +00:00
|
|
|
before do
|
2017-07-03 15:09:34 +00:00
|
|
|
allow(Gitlab::RequestContext).to receive(:client_ip).and_return(whitelisted_ip)
|
2017-04-07 10:27:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns proper response' do
|
|
|
|
get :liveness
|
|
|
|
expect(json_response['db_check']['status']).to eq('ok')
|
|
|
|
expect(json_response['redis_check']['status']).to eq('ok')
|
|
|
|
expect(json_response['fs_shards_check']['status']).to eq('ok')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-03 15:09:34 +00:00
|
|
|
context 'accessed from not whitelisted ip' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::RequestContext).to receive(:client_ip).and_return(not_whitelisted_ip)
|
|
|
|
end
|
|
|
|
|
2017-04-07 10:27:15 +00:00
|
|
|
it 'returns proper response' do
|
|
|
|
get :liveness
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|