summaryrefslogtreecommitdiff
path: root/spec/controllers/metrics_controller_spec.rb
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2017-07-03 17:09:34 +0200
committerPawel Chojnacki <pawel@chojnacki.ws>2017-07-05 00:46:11 +0200
commit18521584bd6cfc8de9511722696e87aef59795c5 (patch)
treefa5b83fca15ff3d6f7a70fd9b87bc31ad575a08a /spec/controllers/metrics_controller_spec.rb
parent5af1fcd6f329858d757bab0d67cb50af6c820160 (diff)
downloadgitlab-ce-18521584bd6cfc8de9511722696e87aef59795c5.tar.gz
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/metrics_controller_spec.rb')
-rw-r--r--spec/controllers/metrics_controller_spec.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/spec/controllers/metrics_controller_spec.rb b/spec/controllers/metrics_controller_spec.rb
index 044c9f179ed..5bcdc6bd872 100644
--- a/spec/controllers/metrics_controller_spec.rb
+++ b/spec/controllers/metrics_controller_spec.rb
@@ -3,20 +3,22 @@ require 'spec_helper'
describe MetricsController do
include StubENV
- let(:token) { current_application_settings.health_check_access_token }
let(:json_response) { JSON.parse(response.body) }
let(:metrics_multiproc_dir) { Dir.mktmpdir }
+ let(:whitelisted_ip) { '127.0.0.1' }
+ let(:not_whitelisted_ip) { '127.0.0.2' }
before do
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
stub_env('prometheus_multiproc_dir', metrics_multiproc_dir)
allow(Gitlab::Metrics).to receive(:prometheus_metrics_enabled?).and_return(true)
+ allow(Settings.monitoring).to receive(:ip_whitelist).and_return([IPAddr.new(whitelisted_ip)])
end
describe '#index' 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 DB ping metrics' do
@@ -59,7 +61,11 @@ describe MetricsController 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 :index