Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit 0c0c5a1

Browse files
committed
ldap: fail to login if neither the username nor the password are present
It's not needed to reach the LDAP server when neither of these values are present, since this should fail anyways. This fixes a common pitfall on LDAP servers that have not been configured to handle this special case. Signed-off-by: Miquel Sabaté Solà <[email protected]>
1 parent 0b5c502 commit 0c0c5a1

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/portus/ldap.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def load_configuration
9090

9191
fill_user_params!
9292
return nil if params[:user].nil?
93+
return nil if params[:user][:username].blank? || params[:user][:password].blank?
9394

9495
adapter.new(adapter_options)
9596
end

spec/lib/portus/ldap_spec.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ def load_configuration_test
143143
lm = PortusMock.new(account: "portus", password: "1234")
144144
expect(lm.load_configuration_test).to be nil
145145

146+
# Empty password always returns an empty configuration
147+
lm = LdapMock.new(username: "name", password: "")
148+
expect(lm.load_configuration_test).to be nil
149+
150+
# Empty name always returns an empty configuration
151+
lm = LdapMock.new(username: "", password: "1234")
152+
expect(lm.load_configuration_test).to be nil
153+
154+
# Now we are good to go
146155
lm = LdapMock.new(username: "name", password: "1234")
147156
cfg = lm.load_configuration_test
148157

@@ -302,10 +311,9 @@ def load_configuration_test
302311

303312
it "raises an exception if the user could not created" do
304313
APP_CONFIG["ldap"] = { "enabled" => true, "base" => "" }
305-
lm = LdapMock.new(username: "", password: "1234")
314+
lm = LdapMock.new(username: "name", password: "1234")
306315
lm.authenticate!
307-
expect(lm.last_symbol).to eq "Password is too short (minimum is 8 characters),"\
308-
"Username Only alphanumeric characters are allowed. Minimum 4 characters, maximum 30."
316+
expect(lm.last_symbol).to eq "Password is too short (minimum is 8 characters)"
309317
end
310318

311319
it "returns a success if it was successful" do

0 commit comments

Comments
 (0)