summaryrefslogtreecommitdiff
path: root/spec/support/unique_ip_check_shared_examples.rb
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2017-02-17 12:52:27 +0100
committerPawel Chojnacki <pawel@chojnacki.ws>2017-03-06 15:41:25 +0100
commit8993801f0cefdc64b46b8fe30622cc78eaa03173 (patch)
treef9a9a38c91e99f03ea87978119a03538d1e91175 /spec/support/unique_ip_check_shared_examples.rb
parent66dc71599cb698d380e14be7230ae3495c78d266 (diff)
downloadgitlab-ce-8993801f0cefdc64b46b8fe30622cc78eaa03173.tar.gz
Test various login scenarios if the limit gets enforced
Diffstat (limited to 'spec/support/unique_ip_check_shared_examples.rb')
-rw-r--r--spec/support/unique_ip_check_shared_examples.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/support/unique_ip_check_shared_examples.rb b/spec/support/unique_ip_check_shared_examples.rb
new file mode 100644
index 00000000000..ab693b91d4a
--- /dev/null
+++ b/spec/support/unique_ip_check_shared_examples.rb
@@ -0,0 +1,27 @@
+shared_context 'limit login to only one ip', :redis do
+ before do
+ allow(Gitlab::Auth::UniqueIpsLimiter).to receive_message_chain(:config, :unique_ips_limit_enabled).and_return(true)
+ allow(Gitlab::Auth::UniqueIpsLimiter).to receive_message_chain(:config, :unique_ips_limit_time_window).and_return(1000)
+ allow(Gitlab::Auth::UniqueIpsLimiter).to receive_message_chain(:config, :unique_ips_limit_per_user).and_return(1)
+ end
+
+ def change_ip(ip)
+ allow(Gitlab::RequestContext).to receive(:client_ip).and_return(ip)
+ end
+end
+
+shared_examples 'user login operation with unique ip limit' do
+ include_context 'limit login to only one ip' do
+ it 'allows user authenticating from the same ip' do
+ expect { operation }.not_to raise_error
+ expect { operation }.not_to raise_error
+ end
+
+ it 'blocks user authenticating from two distinct ips' do
+ expect { operation }.not_to raise_error
+
+ change_ip('ip2')
+ expect { operation }.to raise_error(Gitlab::Auth::TooManyIps)
+ end
+ end
+end