Skip to content
Merged
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
5 changes: 4 additions & 1 deletion src/rabbit_queue_location_validator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@

validate_policy(KeyList) ->
case proplists:lookup(<<"queue-master-locator">> , KeyList) of
{_, Strategy} -> validate_strategy(Strategy);
{_, Strategy} -> case validate_strategy(Strategy) of
Copy link
Collaborator

Choose a reason for hiding this comment

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

I must be missing something, but I don't see how validate_strategy/1 can return anything other than {ok, _} or {error, "~p invalid queue-master-locator value", [Strategy]}

Copy link
Contributor

Choose a reason for hiding this comment

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

validate_policy/1 should return either ok or {error, term()}, but not {ok, term()}. https://github.com/rabbitmq/rabbitmq-server/blob/master/src/rabbit_policy.erl#L528

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see now, thanks.

{error, _} = Er -> Er;
_ -> ok
end;
_ -> {error, "queue-master-locator undefined"}
end.

Expand Down
14 changes: 14 additions & 0 deletions test/queue_master_location_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ groups() ->
{cluster_size_3, [], [
declare_args,
declare_policy,
declare_invalid_policy,
declare_policy_nodes,
declare_policy_all,
declare_policy_exactly,
Expand Down Expand Up @@ -129,6 +130,19 @@ declare_policy(Config) ->
declare(Config, QueueName, false, false, _Args=[], none),
verify_min_master(Config, Q).

declare_invalid_policy(Config) ->
%% Tests that queue masters location returns 'ok', otherwise the validation of
%% any other parameter might be skipped and invalid policy accepted.
setup_test_environment(Config),
unset_location_config(Config),
Policy = [{<<"queue-master-locator">>, <<"min-masters">>},
{<<"ha-mode">>, <<"exactly">>},
%% this field is expected to be an integer
{<<"ha-params">>, <<"2">>}],
{error_string, _} = rabbit_ct_broker_helpers:rpc(
Config, 0, rabbit_policy, set,
[<<"/">>, ?POLICY, <<".*">>, Policy, 0, <<"queues">>, <<"acting-user">>]).

declare_policy_nodes(Config) ->
setup_test_environment(Config),
unset_location_config(Config),
Expand Down