Skip to content

Commit 0445e9c

Browse files
ansdmergify[bot]
authored andcommitted
Fix crash for operator policy HTTP API
This commit fixes the following crash for a GET or a PUT on HTTP API path `/api/operator-policies/vhost/name` if the supplied `vhost` doesn't exists: ``` crasher: initial call: cowboy_stream_h:request_process/3 pid: <0.688.0> registered_name: [] exception error: no function clause matching rabbit_db_rtparams:get({not_found,<<"operator_policy">>, <<"my_policy">>}) (rabbit_db_rtparams.erl:145) in function rabbit_runtime_parameters:lookup0/2 (rabbit_runtime_parameters.erl:363) in call from rabbit_runtime_parameters:lookup/3 (rabbit_runtime_parameters.erl:336) in call from rabbit_policy:lookup_op/2 (rabbit_policy.erl:326) in call from rabbit_mgmt_wm_operator_policy:resource_exists/2 (rabbit_mgmt_wm_operator_policy.erl:38) in call from cowboy_rest:call/3 (src/cowboy_rest.erl:1577) in call from cowboy_rest:expect/6 (src/cowboy_rest.erl:1560) in call from cowboy_rest:upgrade/4 (src/cowboy_rest.erl:281) ``` Also, instead of returning a 500 response code, RabbitMQ will now return a 404 response code. (cherry picked from commit bc0885c)
1 parent b2ebe35 commit 0445e9c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

deps/rabbitmq_management/src/rabbit_mgmt_wm_operator_policy.erl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ is_authorized(ReqData, Context) ->
8282
%%--------------------------------------------------------------------
8383

8484
policy(ReqData) ->
85-
rabbit_policy:lookup_op(
86-
rabbit_mgmt_util:vhost(ReqData), name(ReqData)).
85+
case rabbit_mgmt_util:vhost(ReqData) of
86+
not_found ->
87+
not_found;
88+
Vhost ->
89+
rabbit_policy:lookup_op(Vhost, name(ReqData))
90+
end.
8791

8892
name(ReqData) -> rabbit_mgmt_util:id(name, ReqData).

deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3459,8 +3459,15 @@ operator_policy_test(Config) ->
34593459
"/operator-policies/%2F/policy_even",
34603460
PolicyEven,
34613461
{group, '2xx'}),
3462+
http_put(Config,
3463+
"/operator-policies/absent_vhost/policy_even",
3464+
PolicyEven,
3465+
404),
3466+
34623467
assert_item(PolicyPos, http_get(Config, "/operator-policies/%2F/policy_pos", ?OK)),
34633468
assert_item(PolicyEven, http_get(Config, "/operator-policies/%2F/policy_even", ?OK)),
3469+
http_get(Config, "/operator-policies/absent_vhost/policy_even", 404),
3470+
34643471
List = [PolicyPos, PolicyEven],
34653472
assert_list(List, http_get(Config, "/operator-policies", ?OK)),
34663473
assert_list(List, http_get(Config, "/operator-policies/%2F", ?OK)),

0 commit comments

Comments
 (0)