Skip to content

Commit 02b770c

Browse files
Test translation function of scope_aliases
1 parent 76c5c86 commit 02b770c

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

deps/rabbitmq_auth_backend_oauth2/src/rabbit_oauth2_schema.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ extract_oauth_providers_signing_keys(Settings) ->
251251
KeyFun = fun extract_key_as_binary/1,
252252

253253
IndexedSigningKeys = [{Name, {list_to_binary(Kid), list_to_binary(V)}} ||
254-
{[?AUTH_OAUTH2, ?OAUTH_PROVIDERS, Name, "signing_keys", Kid], V}
254+
{[?AUTH_OAUTH2, ?OAUTH_PROVIDERS, Name, ?SIGNING_KEYS, Kid], V}
255255
<- Settings ],
256256
maps:map(fun(_K,V)-> [{signing_keys, translate_list_of_signing_keys(V)}] end,
257257
maps:groups_from_list(KeyFun, fun({_, V}) -> V end, IndexedSigningKeys)).

deps/rabbitmq_auth_backend_oauth2/test/rabbit_oauth2_schema_SUITE.erl

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
-import(rabbit_oauth2_schema, [
1616
translate_endpoint_params/2,
1717
translate_oauth_providers/1,
18-
translate_resource_servers/1
18+
translate_resource_servers/1,
19+
translate_scope_aliases/1
1920
]).
2021

2122
all() ->
@@ -37,7 +38,8 @@ all() ->
3738
test_with_many_resource_servers,
3839
test_resource_servers_attributes,
3940
test_invalid_oauth_providers_endpoint_params,
40-
test_without_oauth_providers_with_endpoint_params
41+
test_without_oauth_providers_with_endpoint_params,
42+
test_scope_aliases
4143

4244
].
4345

@@ -97,10 +99,11 @@ test_without_oauth_providers_with_endpoint_params(_) ->
9799

98100
test_with_one_oauth_provider(_) ->
99101
Conf = [
100-
{["auth_oauth2","oauth_providers","keycloak","issuer"],"https://rabbit"}
102+
{["auth_oauth2","oauth_providers","keycloak","issuer"],
103+
"https://rabbit"}
101104
],
102-
#{<<"keycloak">> := [{issuer, "https://rabbit"}]
103-
} = translate_oauth_providers(Conf).
105+
#{<<"keycloak">> := [{issuer, <<"https://rabbit">>}]
106+
} = rabbit_oauth2_schema:translate_oauth_providers(Conf).
104107

105108
test_with_one_resource_server(_) ->
106109
Conf = [
@@ -118,7 +121,7 @@ test_with_many_oauth_providers(_) ->
118121
{["auth_oauth2","oauth_providers","uaa","discovery_endpoint_path"],
119122
"/some-path"}
120123
],
121-
#{<<"keycloak">> := [{issuer, "https://keycloak"}
124+
#{<<"keycloak">> := [{issuer, <<"https://keycloak">>}
122125
],
123126
<<"uaa">> := [{issuer, "https://uaa"},
124127
{discovery_endpoint_path, "/some-path"}
@@ -128,8 +131,10 @@ test_with_many_oauth_providers(_) ->
128131

129132
test_with_many_resource_servers(_) ->
130133
Conf = [
131-
{["auth_oauth2","resource_servers","rabbitmq1","id"], "rabbitmq1"},
132-
{["auth_oauth2","resource_servers","rabbitmq2","id"], "rabbitmq2"}
134+
{["auth_oauth2","resource_servers","rabbitmq1","id"],
135+
"rabbitmq1"},
136+
{["auth_oauth2","resource_servers","rabbitmq2","id"],
137+
"rabbitmq2"}
133138
],
134139
#{<<"rabbitmq1">> := [{id, <<"rabbitmq1">>}
135140
],
@@ -268,7 +273,7 @@ test_oauth_providers_signing_keys(Conf) ->
268273
{["auth_oauth2","oauth_providers","keycloak","signing_keys","1"],
269274
cert_filename(Conf)}
270275
],
271-
#{<<"keycloak">> := [{issuer, "https://keycloak"},
276+
#{<<"keycloak">> := [{issuer, <<"https://keycloak">>},
272277
{signing_keys, SigningKeys}
273278
]
274279
} = sort_settings(translate_oauth_providers(CuttlefishConf)),
@@ -277,6 +282,23 @@ test_oauth_providers_signing_keys(Conf) ->
277282
<<"2">> := {pem, <<"I'm not a certificate">>}
278283
} = SigningKeys.
279284

285+
test_scope_aliases(_) ->
286+
CuttlefishConf = [
287+
{["auth_oauth2","scope_aliases","1","alias"],
288+
"admin"},
289+
{["auth_oauth2","scope_aliases","1","scope"],
290+
"rabbitmq.tag:administrator"},
291+
{["auth_oauth2","scope_aliases","2","alias"],
292+
"developer"},
293+
{["auth_oauth2","scope_aliases","2","scope"],
294+
"rabbitmq.tag:management rabbitmq.read:*/*"}
295+
],
296+
#{
297+
<<"admin">> := [<<"rabbitmq.tag:administrator">>],
298+
<<"developer">> := [<<"rabbitmq.tag:management">>, <<"rabbitmq.read:*/*">>]
299+
} = translate_scope_aliases(CuttlefishConf).
300+
301+
280302
cert_filename(Conf) ->
281303
string:concat(?config(data_dir, Conf), "certs/cert.pem").
282304

0 commit comments

Comments
 (0)