gitlab-org--gitlab-foss/spec/lib/gitlab/auth_spec.rb

57 lines
1.6 KiB
Ruby
Raw Normal View History

2012-09-12 02:23:16 -04:00
require 'spec_helper'
2015-12-09 05:55:36 -05:00
describe Gitlab::Auth, lib: true do
2012-09-12 02:23:16 -04:00
let(:gl_auth) { Gitlab::Auth.new }
2013-09-03 17:53:13 -04:00
describe :find do
2014-09-08 07:11:39 -04:00
let!(:user) do
create(:user,
username: username,
password: password,
password_confirmation: password)
2012-09-12 02:23:16 -04:00
end
let(:username) { 'John' } # username isn't lowercase, test this
2014-09-08 07:11:39 -04:00
let(:password) { 'my-secret' }
2012-09-12 02:23:16 -04:00
2013-09-03 17:53:13 -04:00
it "should find user by valid login/password" do
2014-09-08 07:11:39 -04:00
expect( gl_auth.find(username, password) ).to eql user
2012-09-12 02:23:16 -04:00
end
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 17:53:13 -04:00
it "should not find user with invalid password" do
2014-09-08 07:11:39 -04:00
password = 'wrong'
expect( gl_auth.find(username, password) ).not_to eql user
2012-09-12 02:23:16 -04:00
end
2014-09-08 07:11:39 -04:00
it "should not find user with invalid login" do
user = 'wrong'
expect( gl_auth.find(username, password) ).not_to eql user
end
context "with ldap enabled" do
2015-05-21 17:49:06 -04:00
before do
allow(Gitlab::LDAP::Config).to receive(:enabled?).and_return(true)
end
it "tries to autheticate with db before ldap" do
expect(Gitlab::LDAP::Authentication).not_to receive(:login)
gl_auth.find(username, password)
end
it "uses ldap as fallback to for authentication" do
expect(Gitlab::LDAP::Authentication).to receive(:login)
gl_auth.find('ldap_user', 'password')
end
end
2012-09-12 02:23:16 -04:00
end
end