diff options
| author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-02-17 14:44:57 +0100 |
|---|---|---|
| committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-03-06 15:41:25 +0100 |
| commit | 9cc0ff8f468c54e23172492d97f6d9b428d3ad2e (patch) | |
| tree | 5de31ec4dea0df354cc246b809dff5ef376316d5 /spec/support | |
| parent | 80fbced2e0b8d291173e1002f150bc5551e87359 (diff) | |
| download | gitlab-ce-9cc0ff8f468c54e23172492d97f6d9b428d3ad2e.tar.gz | |
Cleanup common code in Unique Ips tests
Diffstat (limited to 'spec/support')
| -rw-r--r-- | spec/support/unique_ip_check_shared_examples.rb | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/spec/support/unique_ip_check_shared_examples.rb b/spec/support/unique_ip_check_shared_examples.rb index c868a1c7a7c..024fb132778 100644 --- a/spec/support/unique_ip_check_shared_examples.rb +++ b/spec/support/unique_ip_check_shared_examples.rb @@ -1,12 +1,16 @@ -shared_context 'limit login to only one ip' do +shared_context 'enable unique ips sign in limit' do + include StubENV before(:each) do Gitlab::Redis.with(&:flushall) end 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(10000) - allow(Gitlab::Auth::UniqueIpsLimiter).to receive_message_chain(:config, :unique_ips_limit_per_user).and_return(1) + stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false') + + current_application_settings.update!( + unique_ips_limit_enabled: true, + unique_ips_limit_time_window: 10000 + ) end def change_ip(ip) @@ -15,7 +19,9 @@ shared_context 'limit login to only one ip' do end shared_examples 'user login operation with unique ip limit' do - include_context 'limit login to only one ip' do + include_context 'enable unique ips sign in limit' do + before { current_application_settings.update!(unique_ips_limit_per_user: 1) } + it 'allows user authenticating from the same ip' do change_ip('ip') expect { operation }.not_to raise_error @@ -31,3 +37,28 @@ shared_examples 'user login operation with unique ip limit' do end end end + +shared_examples 'user login request with unique ip limit' do + include_context 'enable unique ips sign in limit' do + before { current_application_settings.update!(unique_ips_limit_per_user: 1) } + + it 'allows user authenticating from the same ip' do + change_ip('ip') + request + expect(response).to have_http_status(200) + + request + expect(response).to have_http_status(200) + end + + it 'blocks user authenticating from two distinct ips' do + change_ip('ip') + request + expect(response).to have_http_status(200) + + change_ip('ip2') + request + expect(response).to have_http_status(403) + end + end +end |
