@@ -130,6 +130,14 @@ groups() -> [
130
130
is_verify_aud_for_resource_one_returns_true ,
131
131
is_verify_aud_for_resource_two_returns_false
132
132
]},
133
+ get_scope_prefix_for_resource_one_returns_default_scope_prefix ,
134
+ {with_root_scope_prefix , [], [
135
+ get_scope_prefix_for_resource_one_returns_root_scope_prefix ,
136
+ {with_empty_scope_prefix_for_resource_one , [], [
137
+ get_scope_prefix_for_resource_one_returns_empty_scope_prefix ,
138
+ get_scope_prefix_for_resource_two_returns_root_scope_prefix
139
+ ]}
140
+ ]},
133
141
{with_jwks_url , [], [
134
142
get_oauth_provider_for_both_resources_should_return_root_oauth_provider ,
135
143
{with_oauth_providers_A_with_jwks_uri , [], [
@@ -160,6 +168,7 @@ groups() -> [
160
168
get_default_preferred_username_claims ,
161
169
get_preferred_username_claims ,
162
170
get_scope_prefix ,
171
+ get_empty_scope_prefix ,
163
172
get_scope_prefix_when_not_defined ,
164
173
get_resource_server_type ,
165
174
get_resource_server_type_when_not_defined ,
@@ -309,6 +318,16 @@ init_per_group(with_resource_server_id, Config) ->
309
318
application :set_env (rabbitmq_auth_backend_oauth2 , resource_server_id , ? RABBITMQ ),
310
319
Config ;
311
320
321
+ init_per_group (with_root_scope_prefix , Config ) ->
322
+ application :set_env (rabbitmq_auth_backend_oauth2 , scope_prefix , <<" some-prefix:" >>),
323
+ Config ;
324
+ init_per_group (with_empty_scope_prefix_for_resource_one , Config ) ->
325
+ ResourceServers = application :get_env (rabbitmq_auth_backend_oauth2 , resource_servers , #{}),
326
+ Proplist = maps :get (? RABBITMQ_RESOURCE_ONE , ResourceServers , []),
327
+ application :set_env (rabbitmq_auth_backend_oauth2 , resource_servers ,
328
+ maps :put (? RABBITMQ_RESOURCE_ONE , [{scope_prefix , <<" " >>} | proplists :delete (scope_prefix , Proplist )], ResourceServers )),
329
+ Config ;
330
+
312
331
init_per_group (with_verify_aud_false , Config ) ->
313
332
application :set_env (rabbitmq_auth_backend_oauth2 , verify_aud , false ),
314
333
Config ;
@@ -405,7 +424,9 @@ end_per_group(with_root_static_signing_keys, Config) ->
405
424
KeyConfig = call_get_env (Config , key_config , []),
406
425
call_set_env (Config , key_config , KeyConfig ),
407
426
Config ;
408
-
427
+ end_per_group (get_empty_scope_prefix , Config ) ->
428
+ application :unset_env (rabbitmq_auth_backend_oauth2 , scope_prefix ),
429
+ Config ;
409
430
end_per_group (with_resource_server_id , Config ) ->
410
431
application :unset_env (rabbitmq_auth_backend_oauth2 , resource_server_id ),
411
432
Config ;
@@ -418,6 +439,13 @@ end_per_group(with_verify_aud_false_for_resource_two, Config) ->
418
439
application :set_env (rabbitmq_auth_backend_oauth2 , resource_servers ,
419
440
maps :put (? RABBITMQ_RESOURCE_TWO , proplists :delete (verify_aud , Proplist ), ResourceServers )),
420
441
Config ;
442
+ end_per_group (with_empty_scope_prefix_for_resource_one , Config ) ->
443
+ ResourceServers = application :get_env (rabbitmq_auth_backend_oauth2 , resource_servers , #{}),
444
+ Proplist = maps :get (? RABBITMQ_RESOURCE_ONE , ResourceServers , []),
445
+ application :set_env (rabbitmq_auth_backend_oauth2 , resource_servers ,
446
+ maps :put (? RABBITMQ_RESOURCE_ONE , proplists :delete (scope_prefix , Proplist ), ResourceServers )),
447
+ Config ;
448
+
421
449
end_per_group (with_default_key , Config ) ->
422
450
KeyConfig = application :get_env (rabbitmq_auth_backend_oauth2 , key_config , []),
423
451
application :set_env (rabbitmq_auth_backend_oauth2 , key_config ,
@@ -507,6 +535,10 @@ end_per_group(inheritance_group, Config) ->
507
535
application :unset_env (rabbitmq_auth_backend_oauth2 , resource_servers ),
508
536
Config ;
509
537
538
+ end_per_group (with_root_scope_prefix , Config ) ->
539
+ application :unset_env (rabbitmq_auth_backend_oauth2 , scope_prefix ),
540
+ Config ;
541
+
510
542
end_per_group (_any , Config ) ->
511
543
Config .
512
544
@@ -520,6 +552,9 @@ init_per_testcase(get_additional_scopes_key_when_not_defined, Config) ->
520
552
init_per_testcase (is_verify_aud_when_is_false , Config ) ->
521
553
application :set_env (rabbitmq_auth_backend_oauth2 , verify_aud , false ),
522
554
Config ;
555
+ init_per_testcase (get_empty_scope_prefix , Config ) ->
556
+ application :set_env (rabbitmq_auth_backend_oauth2 , scope_prefix , <<" " >>),
557
+ Config ;
523
558
init_per_testcase (get_scope_prefix_when_not_defined , Config ) ->
524
559
application :unset_env (rabbitmq_auth_backend_oauth2 , scope_prefix ),
525
560
Config ;
@@ -756,11 +791,35 @@ get_scope_prefix_when_not_defined(_Config) ->
756
791
? assertEqual (<<" rabbitmq." >>, rabbit_oauth2_config :get_scope_prefix ()),
757
792
? assertEqual (<<" rabbitmq2." >>, rabbit_oauth2_config :get_scope_prefix (<<" rabbitmq2" >>)).
758
793
794
+ get_empty_scope_prefix (_Config ) ->
795
+ ? assertEqual (<<" " >>, rabbit_oauth2_config :get_scope_prefix ()),
796
+ ? assertEqual (<<" " >>, rabbit_oauth2_config :get_scope_prefix (<<" rabbitmq2" >>)).
797
+
759
798
get_scope_prefix (_Config ) ->
760
799
? assertEqual (<<" some-prefix-" >>, rabbit_oauth2_config :get_scope_prefix ()),
761
800
? assertEqual (<<" my-prefix:" >>, rabbit_oauth2_config :get_scope_prefix (<<" rabbitmq1" >>)),
762
801
? assertEqual (rabbit_oauth2_config :get_scope_prefix (), rabbit_oauth2_config :get_scope_prefix (<<" rabbitmq2" >>)).
763
802
803
+ get_scope_prefix_for_resource_one_returns_default_scope_prefix (_Config ) ->
804
+ ? assertEqual (undefined , application :get_env (rabbitmq_auth_backend_oauth2 , scope_prefix )),
805
+ ? assertEqual (append_paths (? RABBITMQ_RESOURCE_ONE , <<" ." >>),
806
+ rabbit_oauth2_config :get_scope_prefix (? RABBITMQ_RESOURCE_ONE )).
807
+ get_scope_prefix_for_resource_one_returns_root_scope_prefix (_Config ) ->
808
+ {ok , Prefix } = application :get_env (rabbitmq_auth_backend_oauth2 , scope_prefix ),
809
+ ? assertEqual (rabbit_oauth2_config :get_scope_prefix (),
810
+ rabbit_oauth2_config :get_scope_prefix (? RABBITMQ_RESOURCE_ONE )),
811
+ ? assertEqual (Prefix ,
812
+ rabbit_oauth2_config :get_scope_prefix (? RABBITMQ_RESOURCE_ONE )).
813
+ get_scope_prefix_for_resource_one_returns_empty_scope_prefix (_Config ) ->
814
+ ? assertEqual (<<" " >>,
815
+ rabbit_oauth2_config :get_scope_prefix (? RABBITMQ_RESOURCE_ONE )).
816
+ get_scope_prefix_for_resource_two_returns_root_scope_prefix (_Config ) ->
817
+ {ok , Prefix } = application :get_env (rabbitmq_auth_backend_oauth2 , scope_prefix ),
818
+ ? assertEqual (rabbit_oauth2_config :get_scope_prefix (),
819
+ rabbit_oauth2_config :get_scope_prefix (? RABBITMQ_RESOURCE_TWO )),
820
+ ? assertEqual (Prefix ,
821
+ rabbit_oauth2_config :get_scope_prefix (? RABBITMQ_RESOURCE_TWO )).
822
+
764
823
get_resource_server_type_when_not_defined (_Config ) ->
765
824
? assertEqual (<<>>, rabbit_oauth2_config :get_resource_server_type ()),
766
825
? assertEqual (<<>>, rabbit_oauth2_config :get_resource_server_type (<<" rabbitmq2" >>)).
0 commit comments