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

48 lines
1.2 KiB
Ruby
Raw Normal View History

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-09-08 11:11:39 +00:00
let(:username) { 'john' }
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
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'
expect( gl_auth.find(username, password) ).to_not 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'
expect( gl_auth.find(username, password) ).to_not eql user
end
context "with ldap enabled" do
before { Gitlab.config.ldap['enabled'] = true }
after { Gitlab.config.ldap['enabled'] = false }
it "tries to autheticate with db before ldap" do
expect(Gitlab::LDAP::User).not_to receive(:authenticate)
gl_auth.find(username, password)
end
it "uses ldap as fallback to for authentication" do
expect(Gitlab::LDAP::User).to receive(:authenticate)
gl_auth.find('ldap_user', 'password')
end
end
2012-09-12 06:23:16 +00:00
end
end