Commit ffe130d8 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'fix/oauth_user_ldap_person' into 'master'

Fix behavior of ldap_person method in Gitlab::OAuth::User

Code tweaks in 45e9150a caused the ldap_person method to not return expected results.
Improved tests to cover the ldap_person method, which was previously stubbed.

Restored the previous implementation of ldap_person, as I could not find a more concise to write it that still works with all the test cases.

See merge request !837
parents e12b6431 d96d9aae
......@@ -87,12 +87,13 @@ module Gitlab
def ldap_person
return @ldap_person if defined?(@ldap_person)
# looks for a corresponding person with same uid in any of the configured LDAP providers
@ldap_person = Gitlab::LDAP::Config.providers.find do |provider|
# Look for a corresponding person with same uid in any of the configured LDAP providers
Gitlab::LDAP::Config.providers.each do |provider|
adapter = Gitlab::LDAP::Adapter.new(provider)
Gitlab::LDAP::Person.find_by_uid(auth_hash.uid, adapter)
@ldap_person = Gitlab::LDAP::Person.find_by_uid(auth_hash.uid, adapter)
break if @ldap_person
end
@ldap_person
end
def ldap_config
......
......@@ -63,13 +63,22 @@ describe Gitlab::OAuth::User do
context "with auto_link_ldap_user enabled" do
before { Gitlab.config.omniauth.stub auto_link_ldap_user: true }
context "and no LDAP provider defined" do
before { allow(Gitlab::LDAP::Config).to receive(:providers).and_return([]) }
include_examples "to verify compliance with allow_single_sign_on"
end
context "and at least one LDAP provider is defined" do
before { allow(Gitlab::LDAP::Config).to receive(:providers).and_return(['ldapmain']) }
context "and a corresponding LDAP person" do
before do
ldap_user.stub(:uid) { uid }
ldap_user.stub(:username) { uid }
ldap_user.stub(:email) { ['johndoe@example.com','john2@example.com'] }
ldap_user.stub(:dn) { 'uid=user1,ou=People,dc=example' }
allow(oauth_user).to receive(:ldap_person).and_return(ldap_user)
allow(Gitlab::LDAP::Person).to receive(:find_by_uid).and_return(ldap_user)
end
context "and no account for the LDAP user" do
......@@ -108,11 +117,12 @@ describe Gitlab::OAuth::User do
end
context "and no corresponding LDAP person" do
before { allow(oauth_user).to receive(:ldap_person).and_return(nil) }
before { allow(Gitlab::LDAP::Person).to receive(:find_by_uid).and_return(nil) }
include_examples "to verify compliance with allow_single_sign_on"
end
end
end
end
......
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