gitlab-org--gitlab-foss/spec/lib/gitlab/ldap/authentication_spec.rb

59 lines
1.8 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe Gitlab::LDAP::Authentication do
2015-05-21 17:49:06 -04:00
let(:user) { create(:omniauth_user, extern_uid: dn) }
let(:dn) { 'uid=john,ou=people,dc=example,dc=com' }
let(:login) { 'john' }
let(:password) { 'password' }
2015-05-21 17:49:06 -04:00
describe 'login' do
before do
2015-05-21 17:49:06 -04:00
allow(Gitlab::LDAP::Config).to receive(:enabled?).and_return(true)
end
it "finds the user if authentication is successful" do
2015-05-21 17:49:06 -04:00
expect(user).not_to be_nil
# try only to fake the LDAP call
2015-05-21 17:49:06 -04:00
adapter = double('adapter', dn: dn).as_null_object
2017-06-21 09:48:12 -04:00
allow_any_instance_of(described_class)
.to receive(:adapter).and_return(adapter)
2015-05-21 17:49:06 -04:00
expect(described_class.login(login, password)).to be_truthy
end
it "is false if the user does not exist" do
# try only to fake the LDAP call
2015-05-21 17:49:06 -04:00
adapter = double('adapter', dn: dn).as_null_object
2017-06-21 09:48:12 -04:00
allow_any_instance_of(described_class)
.to receive(:adapter).and_return(adapter)
2015-05-21 17:49:06 -04:00
expect(described_class.login(login, password)).to be_falsey
end
it "is false if authentication fails" do
2015-05-21 17:49:06 -04:00
expect(user).not_to be_nil
# try only to fake the LDAP call
2015-05-21 17:49:06 -04:00
adapter = double('adapter', bind_as: nil).as_null_object
2017-06-21 09:48:12 -04:00
allow_any_instance_of(described_class)
.to receive(:adapter).and_return(adapter)
2015-05-21 17:49:06 -04:00
expect(described_class.login(login, password)).to be_falsey
end
it "fails if ldap is disabled" do
2015-05-21 17:49:06 -04:00
allow(Gitlab::LDAP::Config).to receive(:enabled?).and_return(false)
expect(described_class.login(login, password)).to be_falsey
end
it "fails if no login is supplied" do
2015-05-21 17:49:06 -04:00
expect(described_class.login('', password)).to be_falsey
end
it "fails if no password is supplied" do
2015-05-21 17:49:06 -04:00
expect(described_class.login(login, '')).to be_falsey
end
end
2015-05-21 17:49:06 -04:00
end