2012-09-12 06:23:16 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Auth do
|
|
|
|
let(:gl_auth) { Gitlab::Auth.new }
|
|
|
|
|
2013-09-03 21:53:13 +00:00
|
|
|
describe :find do
|
2014-09-08 11:11:39 +00:00
|
|
|
let!(:user) do
|
|
|
|
create(:user,
|
|
|
|
username: username,
|
|
|
|
password: password,
|
|
|
|
password_confirmation: password)
|
2012-09-12 06:23:16 +00:00
|
|
|
end
|
2014-10-22 15:29:26 +00:00
|
|
|
let(:username) { 'John' } # username isn't lowercase, test this
|
2014-09-08 11:11:39 +00:00
|
|
|
let(:password) { 'my-secret' }
|
2012-09-12 06:23:16 +00:00
|
|
|
|
2013-09-03 21:53:13 +00:00
|
|
|
it "should find user by valid login/password" do
|
2014-09-08 11:11:39 +00:00
|
|
|
expect( gl_auth.find(username, password) ).to eql user
|
2012-09-12 06:23:16 +00:00
|
|
|
end
|
|
|
|
|
2014-10-22 15:29:26 +00:00
|
|
|
it 'should find user by valid email/password with case-insensitive email' do
|
|
|
|
expect(gl_auth.find(user.email.upcase, password)).to eql user
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should find user by valid username/password with case-insensitive username' do
|
|
|
|
expect(gl_auth.find(username.upcase, password)).to eql user
|
|
|
|
end
|
|
|
|
|
2013-09-03 21:53:13 +00:00
|
|
|
it "should not find user with invalid password" do
|
2014-09-08 11:11:39 +00:00
|
|
|
password = 'wrong'
|
2015-06-18 01:30:58 +00:00
|
|
|
expect( gl_auth.find(username, password) ).not_to eql user
|
2012-09-12 06:23:16 +00:00
|
|
|
end
|
|
|
|
|
2014-09-08 11:11:39 +00:00
|
|
|
it "should not find user with invalid login" do
|
|
|
|
user = 'wrong'
|
2015-06-18 01:30:58 +00:00
|
|
|
expect( gl_auth.find(username, password) ).not_to eql user
|
2013-03-11 06:44:45 +00:00
|
|
|
end
|
2014-09-08 11:26:25 +00:00
|
|
|
|
|
|
|
context "with ldap enabled" do
|
2015-05-21 21:49:06 +00:00
|
|
|
before do
|
|
|
|
allow(Gitlab::LDAP::Config).to receive(:enabled?).and_return(true)
|
|
|
|
end
|
2014-09-08 11:26:25 +00:00
|
|
|
|
|
|
|
it "tries to autheticate with db before ldap" do
|
2014-10-13 15:33:44 +00:00
|
|
|
expect(Gitlab::LDAP::Authentication).not_to receive(:login)
|
2014-09-08 11:26:25 +00:00
|
|
|
|
|
|
|
gl_auth.find(username, password)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "uses ldap as fallback to for authentication" do
|
2014-10-13 15:33:44 +00:00
|
|
|
expect(Gitlab::LDAP::Authentication).to receive(:login)
|
2014-09-08 11:26:25 +00:00
|
|
|
|
|
|
|
gl_auth.find('ldap_user', 'password')
|
|
|
|
end
|
|
|
|
end
|
2012-09-12 06:23:16 +00:00
|
|
|
end
|
|
|
|
end
|