Merge tests to support Multiple LDAP groups

parent 01b79123
...@@ -24,6 +24,11 @@ FactoryGirl.define do ...@@ -24,6 +24,11 @@ FactoryGirl.define do
admin true admin true
end end
trait :ldap do
provider 'ldapmain'
extern_uid 'my-ldap-id'
end
factory :admin, traits: [:admin] factory :admin, traits: [:admin]
end end
......
...@@ -28,17 +28,16 @@ describe Gitlab::Auth do ...@@ -28,17 +28,16 @@ describe Gitlab::Auth do
end end
context "with ldap enabled" do context "with ldap enabled" do
before { Gitlab.config.ldap['enabled'] = true } before { Gitlab::LDAP::Config.stub(enabled?: true) }
after { Gitlab.config.ldap['enabled'] = false }
it "tries to autheticate with db before ldap" do it "tries to autheticate with db before ldap" do
expect(Gitlab::LDAP::User).not_to receive(:authenticate) expect(Gitlab::LDAP::Authentication).not_to receive(:login)
gl_auth.find(username, password) gl_auth.find(username, password)
end end
it "uses ldap as fallback to for authentication" do it "uses ldap as fallback to for authentication" do
expect(Gitlab::LDAP::User).to receive(:authenticate) expect(Gitlab::LDAP::Authentication).to receive(:login)
gl_auth.find('ldap_user', 'password') gl_auth.find('ldap_user', 'password')
end end
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::LDAP::Adapter do describe Gitlab::LDAP::Adapter do
let(:adapter) { Gitlab::LDAP::Adapter.new } let(:adapter) { Gitlab::LDAP::Adapter.new 'ldapmain' }
describe :dn_matches_filter? do describe :dn_matches_filter? do
let(:ldap) { double(:ldap) } let(:ldap) { double(:ldap) }
......
...@@ -10,12 +10,12 @@ describe Gitlab::LDAP::User do ...@@ -10,12 +10,12 @@ describe Gitlab::LDAP::User do
} }
end end
let(:auth_hash) do let(:auth_hash) do
double(uid: 'my-uid', provider: 'ldap', info: double(info)) double(uid: 'my-uid', provider: 'ldapmain', info: double(info))
end end
describe :find_or_create do describe :find_or_create do
it "finds the user if already existing" do it "finds the user if already existing" do
existing_user = create(:user, extern_uid: 'my-uid', provider: 'ldap') existing_user = create(:user, extern_uid: 'my-uid', provider: 'ldapmain')
expect{ gl_user.save }.to_not change{ User.count } expect{ gl_user.save }.to_not change{ User.count }
end end
...@@ -26,27 +26,11 @@ describe Gitlab::LDAP::User do ...@@ -26,27 +26,11 @@ describe Gitlab::LDAP::User do
existing_user.reload existing_user.reload
expect(existing_user.extern_uid).to eql 'my-uid' expect(existing_user.extern_uid).to eql 'my-uid'
expect(existing_user.provider).to eql 'ldap' expect(existing_user.provider).to eql 'ldapmain'
end end
it "creates a new user if not found" do it "creates a new user if not found" do
expect{ gl_user.save }.to change{ User.count }.by(1) expect{ gl_user.save }.to change{ User.count }.by(1)
end end
end end
describe "authenticate" do
let(:login) { 'john' }
let(:password) { 'my-secret' }
before {
Gitlab.config.ldap['enabled'] = true
Gitlab.config.ldap['user_filter'] = 'employeeType=developer'
}
after { Gitlab.config.ldap['enabled'] = false }
it "send an authentication request to ldap" do
expect( Gitlab::LDAP::User.adapter ).to receive(:bind_as)
Gitlab::LDAP::User.authenticate(login, password)
end
end
end end
...@@ -346,6 +346,25 @@ describe User do ...@@ -346,6 +346,25 @@ describe User do
end end
end end
describe :ldap_user? do
let(:user) { build(:user, :ldap) }
it "is true if provider name starts with ldap" do
user.provider = 'ldapmain'
expect( user.ldap_user? ).to be_true
end
it "is false for other providers" do
user.provider = 'other-provider'
expect( user.ldap_user? ).to be_false
end
it "is false if no extern_uid is provided" do
user.extern_uid = nil
expect( user.ldap_user? ).to be_false
end
end
describe '#full_website_url' do describe '#full_website_url' do
let(:user) { create(:user) } let(:user) { create(:user) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment