diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-02-20 17:09:05 +0300 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-03-06 17:41:25 +0300 |
commit | 0ef8a643489ad1a3da4431155326f0a6e206d870 (patch) | |
tree | beb7bceb362f627e4864075e76d05e81f9b743da /spec | |
parent | 9cc0ff8f468c54e23172492d97f6d9b428d3ad2e (diff) |
Remove unecessary calls to limit_user!, UniqueIps Middleware, and address MR review
- cleanup formating in haml
- clarify time window is in seconds
- cleanup straneous chunks in db/schema
- rename count_uniqe_ips to update_and_return_ips_count
- other
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/sessions_controller_spec.rb | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/auth/unique_ips_limiter_spec.rb | 35 | ||||
-rw-r--r-- | spec/lib/gitlab/auth_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/request_context_spec.rb | 10 |
4 files changed, 19 insertions, 29 deletions
diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index 56ed11737ad..fe11bdf4a78 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -33,6 +33,7 @@ describe SessionsController do include_examples 'user login operation with unique ip limit' do def operation post(:create, user: { login: user.username, password: user.password }) + expect(subject.current_user).to eq user end end diff --git a/spec/lib/gitlab/auth/unique_ips_limiter_spec.rb b/spec/lib/gitlab/auth/unique_ips_limiter_spec.rb index 2b21a76c59d..3214786d172 100644 --- a/spec/lib/gitlab/auth/unique_ips_limiter_spec.rb +++ b/spec/lib/gitlab/auth/unique_ips_limiter_spec.rb @@ -7,36 +7,35 @@ describe Gitlab::Auth::UniqueIpsLimiter, :redis, lib: true do describe '#count_unique_ips' do context 'non unique IPs' do it 'properly counts them' do - expect(Gitlab::Auth::UniqueIpsLimiter.count_unique_ips(user.id, 'ip1')).to eq(1) - expect(Gitlab::Auth::UniqueIpsLimiter.count_unique_ips(user.id, 'ip1')).to eq(1) + expect(described_class.update_and_return_ips_count(user.id, 'ip1')).to eq(1) + expect(described_class.update_and_return_ips_count(user.id, 'ip1')).to eq(1) end end context 'unique IPs' do it 'properly counts them' do - expect(Gitlab::Auth::UniqueIpsLimiter.count_unique_ips(user.id, 'ip2')).to eq(1) - expect(Gitlab::Auth::UniqueIpsLimiter.count_unique_ips(user.id, 'ip3')).to eq(2) + expect(described_class.update_and_return_ips_count(user.id, 'ip2')).to eq(1) + expect(described_class.update_and_return_ips_count(user.id, 'ip3')).to eq(2) end end it 'resets count after specified time window' do - cur_time = Time.now - allow(Time).to receive(:now).and_return(cur_time) - - expect(Gitlab::Auth::UniqueIpsLimiter.count_unique_ips(user.id, 'ip2')).to eq(1) - expect(Gitlab::Auth::UniqueIpsLimiter.count_unique_ips(user.id, 'ip3')).to eq(2) - - allow(Time).to receive(:now).and_return(cur_time + Gitlab::Auth::UniqueIpsLimiter.config.unique_ips_limit_time_window) - - expect(Gitlab::Auth::UniqueIpsLimiter.count_unique_ips(user.id, 'ip4')).to eq(1) - expect(Gitlab::Auth::UniqueIpsLimiter.count_unique_ips(user.id, 'ip5')).to eq(2) + Timecop.freeze do + expect(described_class.update_and_return_ips_count(user.id, 'ip2')).to eq(1) + expect(described_class.update_and_return_ips_count(user.id, 'ip3')).to eq(2) + + Timecop.travel(Time.now.utc + described_class.config.unique_ips_limit_time_window) do + expect(described_class.update_and_return_ips_count(user.id, 'ip4')).to eq(1) + expect(described_class.update_and_return_ips_count(user.id, 'ip5')).to eq(2) + end + end end end describe '#limit_user!' do include_examples 'user login operation with unique ip limit' do def operation - Gitlab::Auth::UniqueIpsLimiter.limit_user! { user } + described_class.limit_user! { user } end end @@ -45,13 +44,13 @@ describe Gitlab::Auth::UniqueIpsLimiter, :redis, lib: true do it 'blocks user trying to login from third ip' do change_ip('ip1') - expect(Gitlab::Auth::UniqueIpsLimiter.limit_user! { user }).to eq(user) + expect(described_class.limit_user! { user }).to eq(user) change_ip('ip2') - expect(Gitlab::Auth::UniqueIpsLimiter.limit_user! { user }).to eq(user) + expect(described_class.limit_user! { user }).to eq(user) change_ip('ip3') - expect { Gitlab::Auth::UniqueIpsLimiter.limit_user! { user } }.to raise_error(Gitlab::Auth::TooManyIps) + expect { described_class.limit_user! { user } }.to raise_error(Gitlab::Auth::TooManyIps) end end end diff --git a/spec/lib/gitlab/auth_spec.rb b/spec/lib/gitlab/auth_spec.rb index 860189dcf3c..daf8f5c1d6c 100644 --- a/spec/lib/gitlab/auth_spec.rb +++ b/spec/lib/gitlab/auth_spec.rb @@ -206,7 +206,7 @@ describe Gitlab::Auth, lib: true do include_examples 'user login operation with unique ip limit' do def operation - expect(gl_auth.find_with_user_password(username, password)).to eql user + expect(gl_auth.find_with_user_password(username, password)).to eq(user) end end diff --git a/spec/lib/gitlab/request_context_spec.rb b/spec/lib/gitlab/request_context_spec.rb index 69c5549c39c..b2828f7e5e0 100644 --- a/spec/lib/gitlab/request_context_spec.rb +++ b/spec/lib/gitlab/request_context_spec.rb @@ -26,15 +26,5 @@ describe Gitlab::RequestContext, lib: true 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 |