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-06 11:36:16 +00:00
|
|
|
let(:token) { current_application_settings.health_check_access_token }
|
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-04 22:12:21 +00:00
|
|
|
allow(Settings.monitoring).to receive(:ip_whitelist).and_return([whitelisted_ip])
|
2017-04-07 10:27:15 +00:00
|
|
|
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#readiness' do
|
2017-07-06 11:36:16 +00:00
|
|
|
shared_context 'endpoint responding with readiness data' do
|
|
|
|
subject { get :readiness }
|
2017-04-07 10:27:15 +00:00
|
|
|
|
2017-07-06 11:36:16 +00:00
|
|
|
it 'responds with readiness checks data' do
|
|
|
|
subject
|
2017-07-04 22:12:21 +00:00
|
|
|
|
2017-04-07 10:27:15 +00:00
|
|
|
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-06 11:36:16 +00:00
|
|
|
context 'accessed from whitelisted ip' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::RequestContext).to receive(:client_ip).and_return(whitelisted_ip)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'endpoint responding with readiness data'
|
|
|
|
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-07-06 11:36:16 +00:00
|
|
|
it 'responds with resource not found' do
|
2017-04-07 10:27:15 +00:00
|
|
|
get :readiness
|
2017-07-04 22:12:21 +00:00
|
|
|
|
2017-04-07 10:27:15 +00:00
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
2017-07-06 11:36:16 +00:00
|
|
|
|
|
|
|
context 'accessed with valid token' do
|
|
|
|
context 'token passed in request header' do
|
|
|
|
before do
|
|
|
|
request.headers['TOKEN'] = token
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'endpoint responding with readiness data'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'token passed as URL param' do
|
|
|
|
it_behaves_like 'endpoint responding with readiness data' do
|
|
|
|
subject { get :readiness, token: token }
|
|
|
|
end
|
|
|
|
end
|
2017-04-07 10:27:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#liveness' do
|
2017-07-06 11:36:16 +00:00
|
|
|
shared_context 'endpoint responding with liveness data' do
|
|
|
|
subject { get :liveness }
|
2017-04-07 10:27:15 +00:00
|
|
|
|
2017-07-06 11:36:16 +00:00
|
|
|
it 'responds with liveness checks data' do
|
|
|
|
subject
|
2017-07-04 22:12:21 +00:00
|
|
|
|
2017-04-07 10:27:15 +00:00
|
|
|
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-06 11:36:16 +00:00
|
|
|
context 'accessed from whitelisted ip' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::RequestContext).to receive(:client_ip).and_return(whitelisted_ip)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'endpoint responding with liveness data'
|
|
|
|
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-07-06 11:36:16 +00:00
|
|
|
it 'responds with resource not found' do
|
2017-04-07 10:27:15 +00:00
|
|
|
get :liveness
|
2017-07-04 22:12:21 +00:00
|
|
|
|
2017-04-07 10:27:15 +00:00
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
2017-07-06 11:36:16 +00:00
|
|
|
|
|
|
|
context 'accessed with valid token' do
|
|
|
|
context 'token passed in request header' do
|
|
|
|
before do
|
|
|
|
request.headers['TOKEN'] = token
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'endpoint responding with liveness data'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'token passed as URL param' do
|
|
|
|
it_behaves_like 'endpoint responding with liveness data' do
|
|
|
|
subject { get :liveness, token: token }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-04-07 10:27:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|