diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-02-22 14:13:06 +0100 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-03-06 15:41:25 +0100 |
commit | 98bd48c66bd45241d857528791f4e2dd21bfc17a (patch) | |
tree | 3b39f840bb1d3515bad73ceae91d7d6128dc301d /spec | |
parent | 2ff139ddee49dca7109b9f547e54c6e472c7195b (diff) | |
download | gitlab-ce-98bd48c66bd45241d857528791f4e2dd21bfc17a.tar.gz |
Cleanup test phases by introducing request_from_ip and operation_from_ip helers
Diffstat (limited to 'spec')
-rw-r--r-- | spec/support/unique_ip_check_shared_examples.rb | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/spec/support/unique_ip_check_shared_examples.rb b/spec/support/unique_ip_check_shared_examples.rb index 772e6722fc1..7cf5a65eeed 100644 --- a/spec/support/unique_ip_check_shared_examples.rb +++ b/spec/support/unique_ip_check_shared_examples.rb @@ -16,6 +16,17 @@ shared_context 'unique ips sign in limit' do def change_ip(ip) allow(Gitlab::RequestContext).to receive(:client_ip).and_return(ip) end + + def request_from_ip(ip) + change_ip(ip) + request + response + end + + def operation_from_ip(ip) + change_ip(ip) + operation + end end shared_examples 'user login operation with unique ip limit' do @@ -23,17 +34,13 @@ shared_examples 'user login operation with unique ip 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 - expect { operation }.not_to raise_error + expect { operation_from_ip('ip') }.not_to raise_error + expect { operation_from_ip('ip') }.not_to raise_error end it 'blocks user authenticating from two distinct ips' do - change_ip('ip') - expect { operation }.not_to raise_error - - change_ip('ip2') - expect { operation }.to raise_error(Gitlab::Auth::TooManyIps) + expect { operation_from_ip('ip') }.not_to raise_error + expect { operation_from_ip('ip2') }.to raise_error(Gitlab::Auth::TooManyIps) end end end @@ -43,22 +50,13 @@ shared_examples 'user login request with unique ip limit' do |success_status = 2 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(success_status) - - request - expect(response).to have_http_status(success_status) + expect(request_from_ip('ip')).to have_http_status(success_status) + expect(request_from_ip('ip')).to have_http_status(success_status) end it 'blocks user authenticating from two distinct ips' do - change_ip('ip') - request - expect(response).to have_http_status(success_status) - - change_ip('ip2') - request - expect(response).to have_http_status(403) + expect(request_from_ip('ip')).to have_http_status(success_status) + expect(request_from_ip('ip2')).to have_http_status(403) end end end |