Skip to content

Commit eadebf5

Browse files
Handle wrong scope_aliases configuration
1 parent dfc8f31 commit eadebf5

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
@@ -51,8 +51,8 @@ extract_scope_aliases_as_list_of_alias_scope_props(Settings) ->
5151
List0 = [{Index, {list_to_atom(Attr), V}}
5252
|| {[?AUTH_OAUTH2, ?SCOPE_ALIASES, Index, Attr], V} <- Settings ],
5353
List1 = maps:to_list(maps:groups_from_list(KeyFun, ValueFun, List0)),
54-
maps:from_list([
55-
extract_scope_alias_mapping(Proplist) || {_, Proplist} <- List1]).
54+
List2 = [extract_scope_alias_mapping(Proplist) || {_, Proplist} <- List1],
55+
maps:from_list([ V || V <- List2, V =/= {}]).
5656

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

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
@@ -29,7 +29,8 @@ all() ->
2929
test_with_many_resource_servers,
3030
test_resource_servers_attributes,
3131
test_scope_aliases_configured_as_list_of_properties,
32-
test_scope_aliases_configured_as_map
32+
test_scope_aliases_configured_as_map,
33+
test_scope_aliases_configured_as_list_of_missing_properties
3334
].
3435

3536

@@ -237,6 +238,20 @@ test_scope_aliases_configured_as_list_of_properties(_) ->
237238
<<"developer">> := [<<"rabbitmq.tag:management">>, <<"rabbitmq.read:*/*">>]
238239
} = rabbit_oauth2_schema:translate_scope_aliases(CuttlefishConf).
239240

241+
test_scope_aliases_configured_as_list_of_missing_properties(_) ->
242+
CuttlefishConf = [
243+
{["auth_oauth2","scope_aliases","1","alias"],
244+
"admin"}
245+
],
246+
#{} = rabbit_oauth2_schema:translate_scope_aliases(CuttlefishConf),
247+
248+
CuttlefishConf2 = [
249+
{["auth_oauth2","scope_aliases","1","scope"],
250+
"rabbitmq.tag:management rabbitmq.read:*/*"}
251+
],
252+
#{} = rabbit_oauth2_schema:translate_scope_aliases(CuttlefishConf2).
253+
254+
240255
test_scope_aliases_configured_as_map(_) ->
241256
CuttlefishConf = [
242257
{["auth_oauth2","scope_aliases","admin"],

0 commit comments

Comments
 (0)