Skip to content

Commit 4d1f03f

Browse files
committed
Add more informative information when connection fails
1 parent 20d9f3c commit 4d1f03f

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

deps/rabbitmq_auth_backend_ldap/src/rabbit_auth_backend_ldap_mgmt.erl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ accept_content(ReqData0, Context) ->
7979
eldap:close(LDAP),
8080
Result;
8181
{error, E} ->
82-
Reason = unicode_format(E),
82+
Reason = unicode_format("LDAP connection failed: ~tp "
83+
"(servers: ~tp, user_dn: ~tp, password: ~s)",
84+
[E, Servers, UserDN, format_password_for_logging(Password)]),
8385
rabbit_mgmt_util:bad_request(Reason, ReqData1, Context)
8486
end
8587
catch throw:{bad_request, ErrMsg} ->
@@ -93,6 +95,14 @@ accept_content(ReqData0, Context) ->
9395
unicode_format(Arg) ->
9496
rabbit_data_coercion:to_utf8_binary(io_lib:format("~tp", [Arg])).
9597

98+
unicode_format(Format, Args) ->
99+
rabbit_data_coercion:to_utf8_binary(io_lib:format(Format, Args)).
100+
101+
format_password_for_logging(<<>>) ->
102+
"[empty]";
103+
format_password_for_logging(Password) ->
104+
io_lib:format("[~p bytes]", [byte_size(Password)]).
105+
96106
maybe_starttls(_LDAP, false, _BodyMap) ->
97107
ok;
98108
maybe_starttls(LDAP, true, BodyMap) ->

deps/rabbitmq_auth_backend_ldap/test/system_SUITE.erl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,40 @@ validate_ldap_configuration_via_api(Config) ->
352352
%% Should NOT contain GET or HEAD
353353
?assertEqual(0, string:str(string:to_upper(AllowHeader), "GET")),
354354
?assertEqual(0, string:str(string:to_upper(AllowHeader), "HEAD")),
355+
356+
%% Missing required fields tests
357+
%% Empty servers array - connection failure (400)
358+
http_put(Config, "/ldap/validate/simple-bind",
359+
#{
360+
'user_dn' => AliceUserDN,
361+
'password' => Password,
362+
'servers' => [],
363+
'port' => LdapPort
364+
}, ?BAD_REQUEST),
365+
366+
%% Missing servers field entirely - defaults to [], same as above (400)
367+
http_put(Config, "/ldap/validate/simple-bind",
368+
#{
369+
'user_dn' => AliceUserDN,
370+
'password' => Password,
371+
'port' => LdapPort
372+
}, ?BAD_REQUEST),
373+
374+
%% Missing user_dn field entirely - empty DN fails credential validation (422)
375+
http_put(Config, "/ldap/validate/simple-bind",
376+
#{
377+
'password' => Password,
378+
'servers' => ["localhost"],
379+
'port' => LdapPort
380+
}, ?UNPROCESSABLE_ENTITY),
381+
382+
%% Missing password field entirely - empty password fails credential validation (422)
383+
http_put(Config, "/ldap/validate/simple-bind",
384+
#{
385+
'user_dn' => AliceUserDN,
386+
'servers' => ["localhost"],
387+
'port' => LdapPort
388+
}, ?UNPROCESSABLE_ENTITY),
355389
http_put(Config, "/ldap/validate/simple-bind",
356390
#{
357391
'user_dn' => AliceUserDN,

0 commit comments

Comments
 (0)