Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions deps/rabbit/src/rabbit_amqp_filtex.erl
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,16 @@ validate0(Descriptor, KVList0) when
KVList = lists:map(fun({{utf8, Key}, {utf8, String}}) ->
{Key, parse_string_modifier_prefix(String)};
({{utf8, Key}, TaggedVal}) ->
{Key, unwrap(TaggedVal)}
{Key, unwrap(TaggedVal)};
(_) ->
invalid_filter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your modification violates the spec when sending the filter field from RabbitMQ to the consumer:

the sending endpoint sets the filter actually in place

In your change, the desired filter as sent from the client to RabbitMQ is echoed back from RabbitMQ to the client while RabbitMQ silently modifies the filter.
This function should return error if the filter is invalid such that the entire filter doesn't take effect.
For example, the Java client compares only the filter names that were desired (i.e. sent from consumer to RabbitMQ) with the filter names actually in place (i.e. sent from RabbitMQ to the consumer).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I've changed it so that the function will return an error

end, KVList0),
{ok, {application_properties, KVList}};
case lists:member(invalid_filter, KVList) of
false ->
{ok, {application_properties, KVList}};
true ->
error
end;
validate0(_, _) ->
error.

Expand Down
21 changes: 20 additions & 1 deletion deps/rabbit/test/amqp_filtex_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@

all() ->
[
{group, cluster_size_1}
{group, cluster_size_1},
{group, filter_validation}
].

groups() ->
Expand All @@ -44,6 +45,10 @@ groups() ->
multiple_sections,
filter_few_messages_from_many,
string_modifier
]},
{filter_validation, [shuffle],
[
invalid_application_property_filter
]}
].

Expand Down Expand Up @@ -579,6 +584,20 @@ string_modifier(Config) ->
ok = end_session_sync(Session),
ok = close_connection_sync(Connection).

invalid_application_property_filter(_Config) ->
%% the only expression is invalid
?assertEqual(error,
rabbit_amqp_filtex:validate(
{described,{symbol,?DESCRIPTOR_NAME_APPLICATION_PROPERTIES_FILTER},
{map,[{{symbol,<<"subject">>},{utf8,<<"var">>}}]}})),

%% one expressions is valid but another one is not
?assertEqual(error,
rabbit_amqp_filtex:validate(
{described,{symbol,?DESCRIPTOR_NAME_APPLICATION_PROPERTIES_FILTER},
{map,[{{utf8, <<"valid">>}, {symbol, <<"no match">>}},
{{symbol,<<"subject">>}, {utf8,<<"var">>}}]}})).

%% -------------------------------------------------------------------
%% Helpers
%% -------------------------------------------------------------------
Expand Down
Loading