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
2122all () ->
@@ -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
98100test_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
105108test_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
129132test_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+
280302cert_filename (Conf ) ->
281303 string :concat (? config (data_dir , Conf ), " certs/cert.pem" ).
282304
0 commit comments