@@ -49,7 +49,8 @@ all() ->
4949 test_unsuccessful_access_with_a_token_that_uses_missing_scope_alias_in_scope_field ,
5050 test_unsuccessful_access_with_a_token_that_uses_missing_scope_alias_in_extra_scope_source_field ,
5151 test_username_from ,
52- {group , with_rabbitmq_node }
52+ {group , with_rabbitmq_node },
53+ {group , with_resource_server_id }
5354
5455 ].
5556groups () ->
@@ -62,11 +63,11 @@ groups() ->
6263 },
6364 {with_resource_server_id , [], [
6465 test_successful_access_with_a_token ,
65- test_validate_payload_resource_server_id_mismatch ,
6666 test_successful_access_with_a_token_that_uses_single_scope_alias_in_scope_field ,
6767 test_successful_access_with_a_token_that_uses_multiple_scope_aliases_in_scope_field ,
6868 test_successful_authorization_without_scopes ,
6969 test_successful_authentication_without_scopes ,
70+ test_successful_access_with_a_token_that_uses_single_scope_alias_with_var_expansion ,
7071 test_successful_access_with_a_token_that_uses_single_scope_alias_in_extra_scope_source_field ,
7172 test_successful_access_with_a_token_that_uses_multiple_scope_aliases_in_extra_scope_source_field ,
7273 normalize_token_scope_with_additional_scopes_complex_claims ,
@@ -634,7 +635,7 @@ normalize_token_scope_with_additional_scopes_complex_claims(_) ->
634635 <<" rabbitmq3" >> =>
635636 [<<" rabbitmq-resource.write:*/*" >>,
636637 <<" rabbitmq-resource-write" >>]},
637- [<<" read:*/*" >>, << " rabbitmq.rabbitmq-resource-read " >> ]
638+ [<<" read:*/*" >>]
638639 },
639640 {
640641 " claims are map with list content - empty result" ,
@@ -647,7 +648,7 @@ normalize_token_scope_with_additional_scopes_complex_claims(_) ->
647648 " claims are map with binary content" ,
648649 #{ <<" rabbitmq" >> => <<" rabbitmq-resource.read:*/* rabbitmq-resource-read" >>,
649650 <<" rabbitmq3" >> => <<" rabbitmq-resource.write:*/* rabbitmq-resource-write" >>},
650- [<<" rabbitmq.rabbitmq-resource. read:*/*" >>, << " rabbitmq.rabbitmq-resource-read " >>]
651+ [<<" read:*/*" >>]
651652 },
652653 {
653654 " claims are map with binary content - empty result" ,
@@ -777,6 +778,45 @@ test_successful_access_with_a_token_that_has_tag_scopes(_) ->
777778 {ok , # auth_user {username = Username , tags = [management , policymaker ]}} =
778779 user_login_authentication (Username , [{password , Token }]).
779780
781+ test_successful_access_with_a_token_that_uses_single_scope_alias_with_var_expansion (_ ) ->
782+ Jwk = ? UTIL_MOD :fixture_jwk (),
783+ UaaEnv = [{signing_keys , #{<<" token-key" >> => {map , Jwk }}}],
784+ set_env (key_config , UaaEnv ),
785+ Alias = <<" client-alias-1" >>,
786+ set_env (scope_aliases , #{
787+ Alias => [
788+ <<" rabbitmq.configure:{vhost}/q-{sub}/rk-{client_id}**" >>
789+ ]
790+ }),
791+
792+ VHost = <<" vhost" >>,
793+ Username = <<" bob" >>,
794+ ClientId = <<" rmq" >>,
795+ Token = ? UTIL_MOD :sign_token_hs (? UTIL_MOD :token_with_sub (
796+ ? UTIL_MOD :token_with_claim (
797+ ? UTIL_MOD :token_with_scope_alias_in_scope_field (Alias ), <<" client_id" >>, ClientId ),
798+ Username ), Jwk ),
799+
800+ {ok , # auth_user {username = Username } = AuthUser } =
801+ user_login_authentication (Username , [{password , Token }]),
802+
803+ % % vhost access
804+ assert_vhost_access_granted (AuthUser , ClientId ),
805+
806+ % % resource access
807+ assert_resource_access_denied (AuthUser , VHost , <<" none" >>, read ),
808+ assert_resource_access_granted (AuthUser , VHost , <<" q-bob" >>, configure ),
809+
810+ % % topic access
811+ assert_topic_access_refused (AuthUser , VHost , <<" q-bob" >>, configure ,
812+ #{routing_key => <<" rk-r2mq/#" >>}),
813+ assert_topic_access_granted (AuthUser , VHost , <<" q-bob" >>, configure ,
814+ #{routing_key => <<" rk-rmq/#" >>}),
815+
816+
817+ application :unset_env (rabbitmq_auth_backend_oauth2 , scope_aliases ),
818+ application :unset_env (rabbitmq_auth_backend_oauth2 , key_config ).
819+
780820test_successful_access_with_a_token_that_uses_single_scope_alias_in_scope_field (_ ) ->
781821 Jwk = ? UTIL_MOD :fixture_jwk (),
782822 UaaEnv = [{signing_keys , #{<<" token-key" >> => {map , Jwk }}}],
@@ -813,8 +853,7 @@ test_successful_access_with_a_token_that_uses_single_scope_alias_in_scope_field(
813853 assert_resource_access_denied (AuthUser , VHost , <<" three" >>, write ),
814854
815855 application :unset_env (rabbitmq_auth_backend_oauth2 , scope_aliases ),
816- application :unset_env (rabbitmq_auth_backend_oauth2 , key_config ),
817- application :unset_env (rabbitmq_auth_backend_oauth2 , resource_server_id ).
856+ application :unset_env (rabbitmq_auth_backend_oauth2 , key_config ).
818857
819858
820859test_successful_access_with_a_token_that_uses_single_scope_alias_in_scope_field_and_custom_scope_prefix (_ ) ->
@@ -855,8 +894,7 @@ test_successful_access_with_a_token_that_uses_single_scope_alias_in_scope_field_
855894
856895 application :unset_env (rabbitmq_auth_backend_oauth2 , scope_aliases ),
857896 application :unset_env (rabbitmq_auth_backend_oauth2 , key_config ),
858- application :unset_env (rabbitmq_auth_backend_oauth2 , scope_prefix ),
859- application :unset_env (rabbitmq_auth_backend_oauth2 , resource_server_id ).
897+ application :unset_env (rabbitmq_auth_backend_oauth2 , scope_prefix ).
860898
861899test_successful_access_with_a_token_that_uses_multiple_scope_aliases_in_scope_field (_ ) ->
862900 Jwk = ? UTIL_MOD :fixture_jwk (),
@@ -901,8 +939,7 @@ test_successful_access_with_a_token_that_uses_multiple_scope_aliases_in_scope_fi
901939 assert_resource_access_denied (AuthUser , VHost , <<" three" >>, write ),
902940
903941 application :unset_env (rabbitmq_auth_backend_oauth2 , scope_aliases ),
904- application :unset_env (rabbitmq_auth_backend_oauth2 , key_config ),
905- application :unset_env (rabbitmq_auth_backend_oauth2 , resource_server_id ).
942+ application :unset_env (rabbitmq_auth_backend_oauth2 , key_config ).
906943
907944test_unsuccessful_access_with_a_token_that_uses_missing_scope_alias_in_scope_field (_ ) ->
908945 Jwk = ? UTIL_MOD :fixture_jwk (),
@@ -976,8 +1013,7 @@ test_successful_access_with_a_token_that_uses_single_scope_alias_in_extra_scope_
9761013 assert_resource_access_denied (AuthUser , VHost , <<" three" >>, write ),
9771014
9781015 application :unset_env (rabbitmq_auth_backend_oauth2 , scope_aliases ),
979- application :unset_env (rabbitmq_auth_backend_oauth2 , key_config ),
980- application :unset_env (rabbitmq_auth_backend_oauth2 , resource_server_id ).
1016+ application :unset_env (rabbitmq_auth_backend_oauth2 , key_config ).
9811017
9821018test_successful_access_with_a_token_that_uses_multiple_scope_aliases_in_extra_scope_source_field (_ ) ->
9831019 Jwk = ? UTIL_MOD :fixture_jwk (),
@@ -1021,8 +1057,7 @@ test_successful_access_with_a_token_that_uses_multiple_scope_aliases_in_extra_sc
10211057 assert_resource_access_denied (AuthUser , VHost , <<" three" >>, write ),
10221058
10231059 application :unset_env (rabbitmq_auth_backend_oauth2 , scope_aliases ),
1024- application :unset_env (rabbitmq_auth_backend_oauth2 , key_config ),
1025- application :unset_env (rabbitmq_auth_backend_oauth2 , resource_server_id ).
1060+ application :unset_env (rabbitmq_auth_backend_oauth2 , key_config ).
10261061
10271062test_unsuccessful_access_with_a_token_that_uses_missing_scope_alias_in_extra_scope_source_field (_ ) ->
10281063 Jwk = ? UTIL_MOD :fixture_jwk (),
0 commit comments