Explain auth logic some more

parent c0229e46
...@@ -3,9 +3,11 @@ module Gitlab ...@@ -3,9 +3,11 @@ module Gitlab
def find(login, password) def find(login, password)
user = User.find_by(email: login) || User.find_by(username: login) user = User.find_by(email: login) || User.find_by(username: login)
# If no user is found, or it's an LDAP server, try LDAP.
# LDAP users are only authenticated via LDAP
if user.nil? || user.ldap_user? if user.nil? || user.ldap_user?
# Second chance - try LDAP authentication # Second chance - try LDAP authentication
return nil unless ldap_conf.enabled return nil unless Gitlab::LDAP::Config.enabled?
Gitlab::LDAP::User.authenticate(login, password) Gitlab::LDAP::User.authenticate(login, password)
else else
......
...@@ -28,8 +28,7 @@ describe Gitlab::Auth do ...@@ -28,8 +28,7 @@ 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.enabled.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::User).not_to receive(:authenticate)
......
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