Skip to content

Commit

Permalink
Return 404 in AMQP management queue purge for non-existing queue
Browse files Browse the repository at this point in the history
  • Loading branch information
acogoluegnes committed Jan 24, 2025
1 parent 4627e7a commit 7bfe2fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion deps/rabbit/src/rabbit_amqp_management.erl
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ handle_http_req(<<"DELETE">>,
[rabbit_misc:rs(QName)])
end
end)
catch exit:#amqp_error{explanation = Explanation} ->
catch exit:#amqp_error{name = not_found, explanation = Explanation} ->
throw(<<"404">>, Explanation, []);
exit:#amqp_error{explanation = Explanation} ->
throw(<<"400">>, Explanation, [])
end;

Expand Down
13 changes: 13 additions & 0 deletions deps/rabbitmq_amqp_client/test/management_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ groups() ->
unbind_bad_binding_path_segment,
exclusive_queue,
purge_stream,
purge_non_existing_queue_should_return_not_found,
pipeline,
multiple_link_pairs,
link_attach_order,
Expand Down Expand Up @@ -773,6 +774,18 @@ purge_stream(Config) ->
{ok, #{}} = rabbitmq_amqp_client:delete_queue(LinkPair, QName),
ok = cleanup(Init).

purge_non_existing_queue_should_return_not_found(Config) ->
Init = {_, LinkPair} = init(Config),
QName = atom_to_binary(?FUNCTION_NAME),

{error, Resp} = rabbitmq_amqp_client:purge_queue(LinkPair, QName),
?assertMatch(#{subject := <<"404">>}, amqp10_msg:properties(Resp)),
#'v1_0.amqp_value'{content = {utf8, Reason}} = amqp10_msg:body(Resp),
?assertEqual(<<"no queue '", QName/binary, "' in vhost '/'">>,
Reason),

ok = cleanup(Init).

queue_topology(Config) ->
NodeNames = rabbit_ct_broker_helpers:get_node_configs(Config, nodename),
Nodes = [N0, N1, N2] = lists:map(fun erlang:atom_to_binary/1, NodeNames),
Expand Down

0 comments on commit 7bfe2fd

Please sign in to comment.