Skip to content

Commit 792598e

Browse files
Merge pull request #1999 from rabbitmq/queue-master-location-validation
Policy validation must return 'ok' or an error (cherry picked from commit 3cfcacb)
1 parent e459bda commit 792598e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/rabbit_queue_location_validator.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232

3333
validate_policy(KeyList) ->
3434
case proplists:lookup(<<"queue-master-locator">> , KeyList) of
35-
{_, Strategy} -> validate_strategy(Strategy);
35+
{_, Strategy} -> case validate_strategy(Strategy) of
36+
{error, _} = Er -> Er;
37+
_ -> ok
38+
end;
3639
_ -> {error, "queue-master-locator undefined"}
3740
end.
3841

test/queue_master_location_SUITE.erl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ groups() ->
5151
{cluster_size_3, [], [
5252
declare_args,
5353
declare_policy,
54+
declare_invalid_policy,
5455
declare_policy_nodes,
5556
declare_policy_all,
5657
declare_policy_exactly,
@@ -129,6 +130,19 @@ declare_policy(Config) ->
129130
declare(Config, QueueName, false, false, _Args=[], none),
130131
verify_min_master(Config, Q).
131132

133+
declare_invalid_policy(Config) ->
134+
%% Tests that queue masters location returns 'ok', otherwise the validation of
135+
%% any other parameter might be skipped and invalid policy accepted.
136+
setup_test_environment(Config),
137+
unset_location_config(Config),
138+
Policy = [{<<"queue-master-locator">>, <<"min-masters">>},
139+
{<<"ha-mode">>, <<"exactly">>},
140+
%% this field is expected to be an integer
141+
{<<"ha-params">>, <<"2">>}],
142+
{error_string, _} = rabbit_ct_broker_helpers:rpc(
143+
Config, 0, rabbit_policy, set,
144+
[<<"/">>, ?POLICY, <<".*">>, Policy, 0, <<"queues">>, <<"acting-user">>]).
145+
132146
declare_policy_nodes(Config) ->
133147
setup_test_environment(Config),
134148
unset_location_config(Config),

0 commit comments

Comments
 (0)