Skip to content

Commit cfd42d8

Browse files
committed
Implement just enough of rabbit_auth_backend_ldap_mgmt for test to
pass.
1 parent 303fb29 commit cfd42d8

File tree

3 files changed

+83
-3
lines changed

3 files changed

+83
-3
lines changed

deps/rabbitmq_auth_backend_ldap/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ define PROJECT_APP_EXTRA_KEYS
3535
endef
3636

3737
LOCAL_DEPS = eldap public_key
38-
DEPS = rabbit_common rabbit
38+
DEPS = rabbit_common rabbit rabbitmq_management
3939
TEST_DEPS = ct_helper rabbitmq_ct_helpers rabbitmq_ct_client_helpers amqp_client
4040
dep_ct_helper = git https://github.com/extend/ct_helper.git master
4141

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
%% This Source Code Form is subject to the terms of the Mozilla Public
2+
%% License, v. 2.0. If a copy of the MPL was not distributed with this
3+
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
%%
5+
%% Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
6+
%%
7+
8+
-module(rabbit_auth_backend_ldap_mgmt).
9+
10+
-behaviour(rabbit_mgmt_extension).
11+
12+
-export([dispatcher/0, web_ui/0]).
13+
14+
-export([init/2,
15+
content_types_accepted/2,
16+
allowed_methods/2,
17+
resource_exists/2,
18+
is_authorized/2,
19+
accept_content/2]).
20+
21+
22+
-include_lib("kernel/include/logger.hrl").
23+
-include_lib("rabbitmq_web_dispatch/include/rabbitmq_web_dispatch_records.hrl").
24+
25+
dispatcher() -> [{"/ldap/validate/bind/:name", ?MODULE, []}].
26+
27+
web_ui() -> [].
28+
29+
%%--------------------------------------------------------------------
30+
31+
init(Req, _Opts) ->
32+
{cowboy_rest, rabbit_mgmt_cors:set_headers(Req, ?MODULE), #context{}}.
33+
34+
content_types_accepted(ReqData, Context) ->
35+
{[{'*', accept_content}], ReqData, Context}.
36+
37+
allowed_methods(ReqData, Context) ->
38+
{[<<"HEAD">>, <<"PUT">>, <<"OPTIONS">>], ReqData, Context}.
39+
40+
resource_exists(ReqData, Context) ->
41+
{true, ReqData, Context}.
42+
43+
is_authorized(ReqData, Context) ->
44+
rabbit_mgmt_util:is_authorized(ReqData, Context).
45+
46+
accept_content(ReqData0, Context) ->
47+
F = fun (_Values, BodyMap, ReqData1) ->
48+
_Name = name(ReqData1),
49+
Port = rabbit_mgmt_util:parse_int(maps:get(port, BodyMap, 389)),
50+
_UseSsl = rabbit_mgmt_util:parse_bool(maps:get(use_ssl, BodyMap, false)),
51+
_UseStartTls = rabbit_mgmt_util:parse_bool(maps:get(use_starttls, BodyMap, false)),
52+
Servers = maps:get(servers, BodyMap, []),
53+
_Password = maps:get(password, BodyMap, <<"">>),
54+
Options = [
55+
{port, Port},
56+
{timeout, 5000},
57+
{ssl, false}
58+
],
59+
?LOG_DEBUG("eldap:open Servers: ~tp Options: ~tp", [Servers, Options]),
60+
case eldap:open(Servers, Options) of
61+
{ok, H} ->
62+
eldap:close(H),
63+
{true, ReqData1, Context};
64+
{error, E} ->
65+
Reason = unicode_format(E),
66+
rabbit_mgmt_util:bad_request(Reason, ReqData1, Context)
67+
end
68+
end,
69+
rabbit_mgmt_util:with_decode([], ReqData0, Context, F).
70+
71+
%%--------------------------------------------------------------------
72+
73+
name(ReqData) ->
74+
case rabbit_mgmt_util:id(name, ReqData) of
75+
[Value] -> Value;
76+
Value -> Value
77+
end.
78+
79+
unicode_format(Arg) ->
80+
rabbit_data_coercion:to_utf8_binary(io_lib:format("~tp", [Arg])).

deps/rabbitmq_auth_backend_ldap/test/system_SUITE.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,9 @@ validate_ldap_configuration_via_api(Config) ->
285285
LdapPort = ?config(ldap_port, Config),
286286
http_put(Config, io_lib:format("/ldap/validate/bind/~ts", [<<?ALICE_NAME>>]),
287287
#{
288-
'servers' => [<<"localhost">>],
288+
'servers' => ["localhost"],
289289
'port' => LdapPort
290-
}, ?OK).
290+
}, ?NO_CONTENT).
291291

292292
purge_connection(Config) ->
293293
{ok, _} = rabbit_ct_broker_helpers:rpc(Config, 0,

0 commit comments

Comments
 (0)