summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/auth_spec.rb
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2017-02-17 13:24:32 +0100
committerPawel Chojnacki <pawel@chojnacki.ws>2017-03-06 15:41:25 +0100
commitb1da4f7de3019059051e35c806bb03bdacb41fcf (patch)
treee8c222f99ddee8dda54035d6d62b86f74272a814 /spec/lib/gitlab/auth_spec.rb
parent8993801f0cefdc64b46b8fe30622cc78eaa03173 (diff)
downloadgitlab-ce-b1da4f7de3019059051e35c806bb03bdacb41fcf.tar.gz
Cleanup RSpec tests
Diffstat (limited to 'spec/lib/gitlab/auth_spec.rb')
-rw-r--r--spec/lib/gitlab/auth_spec.rb28
1 files changed, 9 insertions, 19 deletions
diff --git a/spec/lib/gitlab/auth_spec.rb b/spec/lib/gitlab/auth_spec.rb
index ee70ef34f4f..860189dcf3c 100644
--- a/spec/lib/gitlab/auth_spec.rb
+++ b/spec/lib/gitlab/auth_spec.rb
@@ -58,27 +58,11 @@ describe Gitlab::Auth, lib: true do
expect(gl_auth.find_for_git_client(user.username, 'password', project: nil, ip: 'ip')).to eq(Gitlab::Auth::Result.new(user, nil, :gitlab_or_ldap, full_authentication_abilities))
end
+ include_examples 'user login operation with unique ip limit' do
+ let(:user) { create(:user, password: 'password') }
- context 'unique ip limit is enabled and set to 1', :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(10)
- allow(Gitlab::Auth::UniqueIpsLimiter).to receive_message_chain(:config, :unique_ips_limit_per_user).and_return(1)
- end
-
- it 'allows user authenticating from the same ip' do
- user = create(:user, password: 'password')
- allow(Gitlab::RequestContext).to receive(:client_ip).and_return('ip')
- expect(gl_auth.find_for_git_client(user.username, 'password', project: nil, ip: 'ip')).to eq(Gitlab::Auth::Result.new(user, nil, :gitlab_or_ldap, full_authentication_abilities))
- expect(gl_auth.find_for_git_client(user.username, 'password', project: nil, ip: 'ip')).to eq(Gitlab::Auth::Result.new(user, nil, :gitlab_or_ldap, full_authentication_abilities))
- end
-
- it 'blocks user authenticating from two distinct ips' do
- user = create(:user, password: 'password')
- allow(Gitlab::RequestContext).to receive(:client_ip).and_return('ip')
+ def operation
expect(gl_auth.find_for_git_client(user.username, 'password', project: nil, ip: 'ip')).to eq(Gitlab::Auth::Result.new(user, nil, :gitlab_or_ldap, full_authentication_abilities))
- allow(Gitlab::RequestContext).to receive(:client_ip).and_return('ip2')
- expect { gl_auth.find_for_git_client(user.username, 'password', project: nil, ip: 'ip2') }.to raise_error(Gitlab::Auth::TooManyIps)
end
end
@@ -220,6 +204,12 @@ describe Gitlab::Auth, lib: true do
expect( gl_auth.find_with_user_password(username, password) ).not_to eql user
end
+ include_examples 'user login operation with unique ip limit' do
+ def operation
+ expect(gl_auth.find_with_user_password(username, password)).to eql user
+ end
+ end
+
context "with ldap enabled" do
before do
allow(Gitlab::LDAP::Config).to receive(:enabled?).and_return(true)