Skip to content

Commit 909f0d8

Browse files
committed
Add test case
and remove inner case statement since we only want rabbit_amqqueue:declare/6 to be protected.
1 parent f970753 commit 909f0d8

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

deps/rabbit/src/rabbit_amqp_management.erl

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ handle_http_req(HttpMethod = <<"PUT">>,
126126
ok = prohibit_reserved_amq(QName),
127127
PermCache1 = check_resource_access(QName, configure, User, PermCache0),
128128
rabbit_core_metrics:queue_declared(QName),
129+
129130
{Q1, NumMsgs, NumConsumers, StatusCode, PermCache} =
130131
case rabbit_amqqueue:with(
131132
QName,
@@ -146,36 +147,34 @@ handle_http_req(HttpMethod = <<"PUT">>,
146147
Result;
147148
{error, not_found} ->
148149
PermCache2 = check_dead_letter_exchange(QName, QArgs, User, PermCache1),
149-
try case rabbit_amqqueue:declare(
150-
QName, Durable, AutoDelete, QArgs, Owner, Username) of
151-
{new, Q} ->
150+
try rabbit_amqqueue:declare(
151+
QName, Durable, AutoDelete, QArgs, Owner, Username) of
152+
{new, Q} ->
152153
rabbit_core_metrics:queue_created(QName),
153154
{Q, 0, 0, <<"201">>, PermCache2};
154-
{owner_died, Q} ->
155+
{owner_died, Q} ->
155156
%% Presumably our own days are numbered since the
156157
%% connection has died. Pretend the queue exists though,
157158
%% just so nothing fails.
158159
{Q, 0, 0, <<"201">>, PermCache2};
159-
{absent, Q, Reason} ->
160+
{absent, Q, Reason} ->
160161
absent(Q, Reason);
161-
{existing, _Q} ->
162+
{existing, _Q} ->
162163
%% Must have been created in the meantime. Loop around again.
163164
handle_http_req(HttpMethod, PathSegments, Query, ReqPayload,
164-
Vhost, User, ConnPid, {PermCache2, TopicPermCache});
165-
{error, queue_limit_exceeded, Reason, ReasonArgs} ->
165+
Vhost, User, ConnPid, {PermCache2, TopicPermCache});
166+
{error, queue_limit_exceeded, Reason, ReasonArgs} ->
166167
throw(<<"403">>,
167-
Reason,
168-
ReasonArgs);
169-
{protocol_error, _ErrorType, Reason, ReasonArgs} ->
168+
Reason,
169+
ReasonArgs);
170+
{protocol_error, _ErrorType, Reason, ReasonArgs} ->
170171
throw(<<"400">>, Reason, ReasonArgs)
171-
end
172172
catch exit:#amqp_error{name = precondition_failed,
173-
explanation = Expl} ->
174-
throw(<<"409">>, Expl, []);
175-
exit:#amqp_error{explanation = Expl} ->
176-
throw(<<"400">>, Expl, [])
173+
explanation = Expl} ->
174+
throw(<<"409">>, Expl, []);
175+
exit:#amqp_error{explanation = Expl} ->
176+
throw(<<"400">>, Expl, [])
177177
end;
178-
179178
{error, {absent, Q, Reason}} ->
180179
absent(Q, Reason)
181180
end,

deps/rabbitmq_amqp_client/test/management_SUITE.erl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ groups() ->
5959
declare_queue_inequivalent_fields,
6060
declare_queue_inequivalent_exclusive,
6161
declare_queue_invalid_field,
62+
declare_queue_invalid_arg,
6263
declare_default_exchange,
6364
declare_exchange_amq_prefix,
6465
declare_exchange_line_feed,
@@ -528,6 +529,20 @@ declare_queue_invalid_field(Config) ->
528529
amqp10_msg:body(Resp)),
529530
ok = cleanup(Init).
530531

532+
declare_queue_invalid_arg(Config) ->
533+
Init = {_, LinkPair} = init(Config),
534+
QName = <<"👌"/utf8>>,
535+
QProps = #{arguments => #{<<"x-queue-type">> => {utf8, <<"stream">>},
536+
<<"x-dead-letter-exchange">> => {utf8, <<"dlx is invalid for stream">>}}},
537+
{error, Resp} = rabbitmq_amqp_client:declare_queue(LinkPair, QName, QProps),
538+
?assertMatch(#{subject := <<"409">>}, amqp10_msg:properties(Resp)),
539+
?assertEqual(
540+
#'v1_0.amqp_value'{
541+
content = {utf8, <<"invalid arg 'x-dead-letter-exchange' for queue '", QName/binary,
542+
"' in vhost '/' of queue type rabbit_stream_queue">>}},
543+
amqp10_msg:body(Resp)),
544+
ok = cleanup(Init).
545+
531546
declare_default_exchange(Config) ->
532547
Init = {_, LinkPair} = init(Config),
533548
{error, Resp} = rabbitmq_amqp_client:declare_exchange(LinkPair, ?DEFAULT_EXCHANGE, #{}),

0 commit comments

Comments
 (0)