Skip to content

Commit f1d51e1

Browse files
Merge pull request #12032 from rabbitmq/sasl-mechanisms-order
Maintain order of configured SASL mechanisms
2 parents c12d5a1 + b6fbc02 commit f1d51e1

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

deps/rabbit/priv/schema/rabbit.schema

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,11 @@ end}.
455455
{datatype, atom}]}.
456456

457457
{translation, "rabbit.auth_mechanisms",
458-
fun(Conf) ->
459-
Settings = cuttlefish_variable:filter_by_prefix("auth_mechanisms", Conf),
460-
[ V || {_, V} <- Settings ]
461-
end}.
458+
fun(Conf) ->
459+
Settings = cuttlefish_variable:filter_by_prefix("auth_mechanisms", Conf),
460+
Sorted = lists:keysort(1, Settings),
461+
[V || {_, V} <- Sorted]
462+
end}.
462463

463464

464465
%% Select an authentication backend to use. RabbitMQ provides an

deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,20 @@ default_permissions.write = .*",
239239
[{rabbit,
240240
[{anonymous_login_user, none}]}],
241241
[]},
242+
243+
{auth_mechanisms_ordered,
244+
"auth_mechanisms.1 = PLAIN
245+
auth_mechanisms.2 = AMQPLAIN
246+
auth_mechanisms.3 = ANONYMOUS",
247+
[],
248+
[{rabbit,
249+
%% We expect the mechanisms in the order as declared.
250+
[{auth_mechanisms, ['PLAIN', 'AMQPLAIN', 'ANONYMOUS']}]
251+
}],
252+
[],
253+
nosort
254+
},
255+
242256
{cluster_formation,
243257
"cluster_formation.peer_discovery_backend = rabbit_peer_discovery_classic_config
244258
cluster_formation.classic_config.nodes.peer1 = rabbit@hostname1

deps/rabbitmq_ct_helpers/src/rabbit_ct_config_schema.erl

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ run_snippets(Config) ->
2525
{ok, [Snippets]} = file:consult(?config(conf_snippets, Config)),
2626
ct:pal("Loaded config schema snippets: ~tp", [Snippets]),
2727
lists:map(
28-
fun({N, S, C, P}) -> ok = test_snippet(Config, {snippet_id(N), S, []}, C, P);
29-
({N, S, A, C, P}) -> ok = test_snippet(Config, {snippet_id(N), S, A}, C, P)
30-
end,
31-
Snippets),
28+
fun({N, S, C, P}) ->
29+
ok = test_snippet(Config, {snippet_id(N), S, []}, C, P, true);
30+
({N, S, A, C, P}) ->
31+
ok = test_snippet(Config, {snippet_id(N), S, A}, C, P, true);
32+
({N, S, A, C, P, nosort}) ->
33+
ok = test_snippet(Config, {snippet_id(N), S, A}, C, P, false)
34+
end,
35+
Snippets),
3236
ok.
3337

3438
snippet_id(N) when is_integer(N) ->
@@ -40,7 +44,7 @@ snippet_id(A) when is_atom(A) ->
4044
snippet_id(L) when is_list(L) ->
4145
L.
4246

43-
test_snippet(Config, Snippet = {SnipID, _, _}, Expected, _Plugins) ->
47+
test_snippet(Config, Snippet = {SnipID, _, _}, Expected, _Plugins, Sort) ->
4448
{ConfFile, AdvancedFile} = write_snippet(Config, Snippet),
4549
%% We ignore the rabbit -> log portion of the config on v3.9+, where the lager
4650
%% dependency has been dropped
@@ -50,8 +54,12 @@ test_snippet(Config, Snippet = {SnipID, _, _}, Expected, _Plugins) ->
5054
_ ->
5155
generate_config(ConfFile, AdvancedFile)
5256
end,
53-
Gen = deepsort(Generated),
54-
Exp = deepsort(Expected),
57+
{Exp, Gen} = case Sort of
58+
true ->
59+
{deepsort(Expected), deepsort(Generated)};
60+
false ->
61+
{Expected, Generated}
62+
end,
5563
case Exp of
5664
Gen -> ok;
5765
_ ->

0 commit comments

Comments
 (0)