summaryrefslogtreecommitdiff
path: root/spec/controllers/metrics_controller_spec.rb
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2017-07-04 23:50:18 +0200
committerPawel Chojnacki <pawel@chojnacki.ws>2017-07-05 00:46:12 +0200
commit2f875c40374597ca98104cd40a357a9a928335ff (patch)
tree534fa9883193e9280ae9e17331335277bdc503e1 /spec/controllers/metrics_controller_spec.rb
parente5a6f268bd0703410781afaa62e8ecb3a1f7513d (diff)
downloadgitlab-ce-2f875c40374597ca98104cd40a357a9a928335ff.tar.gz
Finish refactring processed configuraiton, and add test validating ip range matching
Diffstat (limited to 'spec/controllers/metrics_controller_spec.rb')
-rw-r--r--spec/controllers/metrics_controller_spec.rb28
1 files changed, 21 insertions, 7 deletions
diff --git a/spec/controllers/metrics_controller_spec.rb b/spec/controllers/metrics_controller_spec.rb
index 5bcdc6bd872..692bc9a87b4 100644
--- a/spec/controllers/metrics_controller_spec.rb
+++ b/spec/controllers/metrics_controller_spec.rb
@@ -6,21 +6,19 @@ describe MetricsController do
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' }
+ let(:whitelisted_ip_range) { '10.0.0.0/24' }
+ let(:ip_in_whitelisted_range) { '10.0.0.1' }
+ let(:not_whitelisted_ip) { '10.0.1.1' }
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)])
+ allow(Settings.monitoring).to receive(:ip_whitelist).and_return([whitelisted_ip, whitelisted_ip_range])
end
describe '#index' do
- context 'accessed from whitelisted ip' do
- before do
- allow(Gitlab::RequestContext).to receive(:client_ip).and_return(whitelisted_ip)
- end
-
+ shared_examples_for 'endpoint providing metrics' do
it 'returns DB ping metrics' do
get :index
@@ -61,6 +59,22 @@ describe MetricsController do
end
end
+ context 'accessed from whitelisted ip' do
+ before do
+ allow(Gitlab::RequestContext).to receive(:client_ip).and_return(whitelisted_ip)
+ end
+
+ it_behaves_like 'endpoint providing metrics'
+ end
+
+ context 'accessed from ip in whitelisted range' do
+ before do
+ allow(Gitlab::RequestContext).to receive(:client_ip).and_return(ip_in_whitelisted_range)
+ end
+
+ it_behaves_like 'endpoint providing metrics'
+ end
+
context 'accessed from not whitelisted ip' do
before do
allow(Gitlab::RequestContext).to receive(:client_ip).and_return(not_whitelisted_ip)