Skip to content

Commit b099e3c

Browse files
michaelklishinmergify[bot]
authored andcommitted
HTTP API: make sure virtual host limits are returned as a JSON object
when no limits are set. This is the classic empty proplist JSON serialization problem in a relatively new place. (cherry picked from commit 1795306)
1 parent 50e4e92 commit b099e3c

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

deps/rabbitmq_management/src/rabbit_mgmt_wm_limits.erl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,21 @@ limits(ReqData, Context) ->
4545
none ->
4646
User = Context#context.user,
4747
VisibleVhosts = rabbit_mgmt_util:list_visible_vhosts_names(User),
48-
[ [{vhost, VHost}, {value, Value}]
49-
|| {VHost, Value} <- rabbit_vhost_limit:list(),
50-
lists:member(VHost, VisibleVhosts) ];
48+
[
49+
#{
50+
vhost => VHost,
51+
value => rabbit_data_coercion:to_map(Value)
52+
} || {VHost, Value} <- rabbit_vhost_limit:list(), lists:member(VHost, VisibleVhosts)
53+
];
5154
VHost when is_binary(VHost) ->
5255
case rabbit_vhost_limit:list(VHost) of
5356
[] -> [];
54-
Value -> [[{vhost, VHost}, {value, Value}]]
57+
Value -> [
58+
#{
59+
vhost => VHost,
60+
value => rabbit_data_coercion:to_map(Value)
61+
}
62+
]
5563
end
5664
end.
5765
%%--------------------------------------------------------------------

deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3411,13 +3411,14 @@ vhost_limits_list_test(Config) ->
34113411
lists:map(
34123412
fun(#{vhost := VHost, value := Val}) ->
34133413
Param = [ {atom_to_binary(K, utf8),V} || {K,V} <- maps:to_list(Val) ],
3414+
ct:pal("Setting limits of virtual host '~ts' to ~tp", [VHost, Param]),
34143415
ok = rabbit_ct_broker_helpers:set_parameter(Config, 0, VHost, <<"vhost-limits">>, <<"limits">>, Param)
34153416
end,
34163417
Expected),
34173418

3418-
Expected = http_get(Config, "/vhost-limits", ?OK),
3419-
Limits1 = http_get(Config, "/vhost-limits/limit_test_vhost_1", ?OK),
3420-
Limits2 = http_get(Config, "/vhost-limits/limit_test_vhost_2", ?OK),
3419+
?assertEqual(lists:usort(Expected), lists:usort(http_get(Config, "/vhost-limits", ?OK))),
3420+
?assertEqual(Limits1, http_get(Config, "/vhost-limits/limit_test_vhost_1", ?OK)),
3421+
?assertEqual(Limits2, http_get(Config, "/vhost-limits/limit_test_vhost_2", ?OK)),
34213422

34223423
NoVhostUser = <<"no_vhost_user">>,
34233424
rabbit_ct_broker_helpers:add_user(Config, NoVhostUser),

0 commit comments

Comments
 (0)