Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2017-02-06 15:48:46 +0300
committerPawel Chojnacki <pawel@chojnacki.ws>2017-03-06 17:41:24 +0300
commite5cf3f51fb568361a247d715facb6cd9bb15bb16 (patch)
treed12f9644c8b0dd0765fd0de90d69027848341083 /spec/lib/gitlab/request_context_spec.rb
parent27729aa3a4666c6b06006c76023f4bff60f8ba25 (diff)
Allow limiting logging in users from too many different IPs.
Diffstat (limited to 'spec/lib/gitlab/request_context_spec.rb')
-rw-r--r--spec/lib/gitlab/request_context_spec.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/lib/gitlab/request_context_spec.rb b/spec/lib/gitlab/request_context_spec.rb
new file mode 100644
index 00000000000..3565fab6ded
--- /dev/null
+++ b/spec/lib/gitlab/request_context_spec.rb
@@ -0,0 +1,40 @@
+require 'spec_helper'
+
+describe Gitlab::RequestContext, lib: true do
+ describe '#client_ip' do
+ subject { Gitlab::RequestContext.client_ip }
+ let(:app) { -> env {} }
+ let(:env) { Hash.new }
+
+ context 'when RequestStore::Middleware is used' do
+ around(:each) do |example|
+ RequestStore::Middleware.new(-> env { example.run }).call({})
+ end
+
+ context 'request' do
+ let(:ip) { '192.168.1.11' }
+
+ before do
+ allow_any_instance_of(Rack::Request).to receive(:ip).and_return(ip)
+ Gitlab::RequestContext.new(app).call(env)
+ end
+
+ it { is_expected.to eq(ip) }
+ end
+
+ context 'before RequestContext mw run' do
+ it { is_expected.to be_nil }
+ end
+ end
+
+ context 'RequestStore is not active' do
+ it { is_expected.to be_nil }
+
+ context 'when RequestContext mw is run' do
+ subject { -> { Gitlab::RequestContext.new(app).call(env) } }
+
+ it { is_expected.to raise_error(Gitlab::RequestStoreNotActive) }
+ end
+ end
+ end
+end