debian-mirror-gitlab/spec/lib/gitlab/ldap/authentication_spec.rb

59 lines
1.8 KiB
Ruby
Raw Normal View History

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