@@ -58,7 +58,8 @@ groups() ->
5858 test_failed_connection_with_a_token_with_insufficient_resource_permission ,
5959 test_failed_connection_with_algorithm_restriction ,
6060 test_failed_token_refresh_case1 ,
61- test_failed_token_refresh_case2
61+ test_failed_token_refresh_case2 ,
62+ cannot_change_username_on_refreshed_token
6263 ]},
6364 {no_peer_verification , [], [
6465 {group , happy_path },
@@ -521,6 +522,11 @@ generate_valid_token(Config, Jwk, Scopes, Audience) ->
521522 IncludeKid = rabbit_ct_helpers :get_config (Config , include_kid , true ),
522523 ? UTIL_MOD :sign_token_hs (Token , Jwk , IncludeKid ).
523524
525+ generate_valid_token_with_sub (Config , Jwk , Scopes , Sub ) ->
526+ Token = ? UTIL_MOD :token_with_sub (? UTIL_MOD :fixture_token_with_scopes (Scopes ), Sub ),
527+ IncludeKid = rabbit_ct_helpers :get_config (Config , include_kid , true ),
528+ ? UTIL_MOD :sign_token_hs (Token , Jwk , IncludeKid ).
529+
524530generate_valid_token_with_extra_fields (Config , ExtraFields ) ->
525531 Jwk =
526532 case rabbit_ct_helpers :get_config (Config , fixture_jwk ) of
@@ -937,6 +943,33 @@ test_failed_token_refresh_case2(Config) ->
937943
938944 close_connection (Conn ).
939945
946+ cannot_change_username_on_refreshed_token (Config ) ->
947+ Jwk =
948+ case get_config (Config , fixture_jwk ) of
949+ undefined -> ? UTIL_MOD :fixture_jwk ();
950+ Value -> Value
951+ end ,
952+ {_ , CurToken } = generate_valid_token (Config , Jwk , <<" oldUsername" >>, [
953+ <<" rabbitmq.configure:vhost4/*" >>,
954+ <<" rabbitmq.write:vhost4/*" >>,
955+ <<" rabbitmq.read:vhost4/*" >>]),
956+ Conn = open_unmanaged_connection (Config , 0 , <<" vhost4" >>,
957+ <<" oldUsername" >>, CurToken ),
958+
959+ {_ , RefreshToken } = generate_valid_token_with_sub (Config , Jwk , <<" newUsername" >>,
960+ [<<" rabbitmq.configure:vhost4/*" >>,
961+ <<" rabbitmq.write:vhost4/*" >>,
962+ <<" rabbitmq.read:vhost4/*" >>]),
963+
964+ % % the error is communicated asynchronously via a connection-level error
965+ {error , _ } = amqp_connection :update_secret (Conn , RefreshToken ,
966+ <<" token refresh" >>),
967+
968+ ? assertExit ({{shutdown , {connection_closing , {server_initiated_close , 530 , _ }}}, _ },
969+ amqp_connection :open_channel (Conn )),
970+
971+ close_connection (Conn ).
972+
940973test_failed_connection_with_algorithm_restriction (Config ) ->
941974 {_Algo , Token } = get_config (Config , fixture_jwt ),
942975 ? assertMatch ({error , {auth_failure , _ }},
0 commit comments