Skip to content

Commit 3e81cfa

Browse files
MarcialRosalesmichaelklishin
authored andcommitted
Handle wrong scope_aliases configuration
1 parent 48670a0 commit 3e81cfa

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

deps/rabbitmq_auth_backend_oauth2/src/rabbit_oauth2_schema.erl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ extract_scope_aliases_as_list_of_alias_scope_props(Settings) ->
5252
List0 = [{Index, {list_to_atom(Attr), V}}
5353
|| {[?AUTH_OAUTH2, ?SCOPE_ALIASES, Index, Attr], V} <- Settings ],
5454
List1 = maps:to_list(maps:groups_from_list(KeyFun, ValueFun, List0)),
55-
maps:from_list([
56-
extract_scope_alias_mapping(Proplist) || {_, Proplist} <- List1]).
55+
List2 = [extract_scope_alias_mapping(Proplist) || {_, Proplist} <- List1],
56+
maps:from_list([ V || V <- List2, V =/= {}]).
5757

5858
extract_scope_alias_mapping(Proplist) ->
5959
Alias =
@@ -67,8 +67,14 @@ extract_scope_alias_mapping(Proplist) ->
6767
S -> convert_space_separated_string_to_list_of_binaries(S)
6868
end,
6969
case {Alias, Scope} of
70-
{{error, _} = Err0, _} -> Err0;
71-
{_, {error, _} = Err1 } -> Err1;
70+
{{error, _} = Err0, _} ->
71+
rabbit_log:error("Skipped wrong scope_aliases configuration: ~p",
72+
[Err0]),
73+
{};
74+
{_, {error, _} = Err1 } ->
75+
rabbit_log:error("Skipped wrong scope_aliases configuration: ~p",
76+
[Err1]),
77+
{};
7278
_ = V -> V
7379
end.
7480

deps/rabbitmq_auth_backend_oauth2/test/rabbit_oauth2_schema_SUITE.erl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ all() ->
4040
test_invalid_oauth_providers_endpoint_params,
4141
test_without_oauth_providers_with_endpoint_params,
4242
test_scope_aliases_configured_as_list_of_properties,
43-
test_scope_aliases_configured_as_map
43+
test_scope_aliases_configured_as_map,
44+
test_scope_aliases_configured_as_list_of_missing_properties
4445
].
4546

4647

@@ -298,6 +299,20 @@ test_scope_aliases_configured_as_list_of_properties(_) ->
298299
<<"developer">> := [<<"rabbitmq.tag:management">>, <<"rabbitmq.read:*/*">>]
299300
} = translate_scope_aliases(CuttlefishConf).
300301

302+
test_scope_aliases_configured_as_list_of_missing_properties(_) ->
303+
CuttlefishConf = [
304+
{["auth_oauth2","scope_aliases","1","alias"],
305+
"admin"}
306+
],
307+
#{} = rabbit_oauth2_schema:translate_scope_aliases(CuttlefishConf),
308+
309+
CuttlefishConf2 = [
310+
{["auth_oauth2","scope_aliases","1","scope"],
311+
"rabbitmq.tag:management rabbitmq.read:*/*"}
312+
],
313+
#{} = rabbit_oauth2_schema:translate_scope_aliases(CuttlefishConf2).
314+
315+
301316
test_scope_aliases_configured_as_map(_) ->
302317
CuttlefishConf = [
303318
{["auth_oauth2","scope_aliases","admin"],

0 commit comments

Comments
 (0)