Skip to content

Commit ccb28d8

Browse files
committed
* Tests for edge-cases for password / user_dn
1 parent 0f48e4b commit ccb28d8

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

deps/rabbitmq_auth_backend_ldap/src/rabbit_auth_backend_ldap_mgmt.erl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,17 @@ accept_content(ReqData0, Context) ->
6565
ok ->
6666
{true, ReqData1, Context};
6767
{error, invalidCredentials} ->
68-
rabbit_mgmt_util:unprocessable_entity("Invalid LDAP credentials", ReqData1, Context);
68+
rabbit_mgmt_util:unprocessable_entity("invalid LDAP credentials: "
69+
"authentication failure",
70+
ReqData1, Context);
6971
{error, unwillingToPerform} ->
70-
rabbit_mgmt_util:unprocessable_entity("Invalid LDAP credentials", ReqData1, Context);
72+
rabbit_mgmt_util:unprocessable_entity("invalid LDAP credentials: "
73+
"authentication failure",
74+
ReqData1, Context);
75+
{error, invalidDNSyntax} ->
76+
rabbit_mgmt_util:unprocessable_entity("invalid LDAP credentials: "
77+
"DN syntax invalid / too long",
78+
ReqData1, Context);
7179
{error, E} ->
7280
Reason = unicode_format(E),
7381
rabbit_mgmt_util:unprocessable_entity(Reason, ReqData1, Context)

deps/rabbitmq_auth_backend_ldap/test/system_SUITE.erl

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,65 @@ validate_ldap_configuration_via_api(Config) ->
443443
'servers' => ["not..a..valid..hostname"],
444444
'port' => LdapPort
445445
}, ?BAD_REQUEST),
446+
447+
%% Edge case credentials tests
448+
%% Empty password - should be 422 (credential validation failure)
449+
{ok, {{_, 422, _}, _Headers1, EmptyPasswordBody}} =
450+
rabbit_mgmt_test_util:req(Config, 0, put, "/ldap/validate/simple-bind",
451+
[rabbit_mgmt_test_util:auth_header("guest", "guest")],
452+
rabbit_mgmt_test_util:format_for_upload(#{
453+
'user_dn' => AliceUserDN,
454+
'password' => "",
455+
'servers' => ["localhost"],
456+
'port' => LdapPort
457+
})),
458+
EmptyPasswordJson = rabbit_json:decode(EmptyPasswordBody),
459+
?assertEqual(<<"unprocessable_entity">>, maps:get(<<"error">>, EmptyPasswordJson)),
460+
?assertEqual(<<"anonymous_auth">>, maps:get(<<"reason">>, EmptyPasswordJson)),
461+
462+
%% Empty user DN - should be 422 (credential validation failure)
463+
{ok, {{_, 422, _}, _Headers2, EmptyUserDnBody}} =
464+
rabbit_mgmt_test_util:req(Config, 0, put, "/ldap/validate/simple-bind",
465+
[rabbit_mgmt_test_util:auth_header("guest", "guest")],
466+
rabbit_mgmt_test_util:format_for_upload(#{
467+
'user_dn' => "",
468+
'password' => Password,
469+
'servers' => ["localhost"],
470+
'port' => LdapPort
471+
})),
472+
EmptyUserDnJson = rabbit_json:decode(EmptyUserDnBody),
473+
?assertEqual(<<"unprocessable_entity">>, maps:get(<<"error">>, EmptyUserDnJson)),
474+
?assertEqual(<<"anonymous_auth">>, maps:get(<<"reason">>, EmptyUserDnJson)),
475+
476+
%% Very long user DN (test size limits)
477+
{ok, {{_, 422, _}, _Headers3, LongUserDnBody}} =
478+
rabbit_mgmt_test_util:req(Config, 0, put, "/ldap/validate/simple-bind",
479+
[rabbit_mgmt_test_util:auth_header("guest", "guest")],
480+
rabbit_mgmt_test_util:format_for_upload(#{
481+
'user_dn' => binary:copy(<<"x">>, 10000),
482+
'password' => Password,
483+
'servers' => ["localhost"],
484+
'port' => LdapPort
485+
})),
486+
LongUserDnJson = rabbit_json:decode(LongUserDnBody),
487+
?assertEqual(<<"unprocessable_entity">>, maps:get(<<"error">>, LongUserDnJson)),
488+
?assertEqual(<<"invalid LDAP credentials: DN syntax invalid / too long">>,
489+
maps:get(<<"reason">>, LongUserDnJson)),
490+
491+
%% Very long password (test size limits)
492+
{ok, {{_, 422, _}, _Headers4, LongPasswordBody}} =
493+
rabbit_mgmt_test_util:req(Config, 0, put, "/ldap/validate/simple-bind",
494+
[rabbit_mgmt_test_util:auth_header("guest", "guest")],
495+
rabbit_mgmt_test_util:format_for_upload(#{
496+
'user_dn' => AliceUserDN,
497+
'password' => binary:copy(<<"x">>, 10000),
498+
'servers' => ["localhost"],
499+
'port' => LdapPort
500+
})),
501+
LongPasswordJson = rabbit_json:decode(LongPasswordBody),
502+
?assertEqual(<<"unprocessable_entity">>, maps:get(<<"error">>, LongPasswordJson)),
503+
?assertEqual(<<"invalid LDAP credentials: authentication failure">>,
504+
maps:get(<<"reason">>, LongPasswordJson)),
446505
http_put(Config, "/ldap/validate/simple-bind",
447506
#{
448507
'user_dn' => AliceUserDN,

0 commit comments

Comments
 (0)