2014-10-14 03:31:38 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::LDAP::Authentication do
|
|
|
|
let(:klass) { Gitlab::LDAP::Authentication }
|
2014-12-04 06:43:08 -05:00
|
|
|
let(:user) { create(:omniauth_user, extern_uid: dn) }
|
2014-10-14 03:31:38 -04:00
|
|
|
let(:dn) { 'uid=john,ou=people,dc=example,dc=com' }
|
|
|
|
let(:login) { 'john' }
|
|
|
|
let(:password) { 'password' }
|
|
|
|
|
|
|
|
describe :login do
|
|
|
|
let(:adapter) { double :adapter }
|
|
|
|
before do
|
|
|
|
Gitlab::LDAP::Config.stub(enabled?: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "finds the user if authentication is successful" do
|
|
|
|
user
|
|
|
|
# try only to fake the LDAP call
|
|
|
|
klass.any_instance.stub(adapter: double(:adapter,
|
|
|
|
bind_as: double(:ldap_user, dn: dn)
|
|
|
|
))
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(klass.login(login, password)).to be_truthy
|
2014-10-14 03:31:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "is false if the user does not exist" do
|
|
|
|
# try only to fake the LDAP call
|
|
|
|
klass.any_instance.stub(adapter: double(:adapter,
|
|
|
|
bind_as: double(:ldap_user, dn: dn)
|
|
|
|
))
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(klass.login(login, password)).to be_falsey
|
2014-10-14 03:31:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "is false if authentication fails" do
|
|
|
|
user
|
|
|
|
# try only to fake the LDAP call
|
|
|
|
klass.any_instance.stub(adapter: double(:adapter, bind_as: nil))
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(klass.login(login, password)).to be_falsey
|
2014-10-14 03:31:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if ldap is disabled" do
|
|
|
|
Gitlab::LDAP::Config.stub(enabled?: false)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(klass.login(login, password)).to be_falsey
|
2014-10-14 03:31:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if no login is supplied" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(klass.login('', password)).to be_falsey
|
2014-10-14 03:31:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if no password is supplied" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(klass.login(login, '')).to be_falsey
|
2014-10-14 03:31:38 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|