@@ -46,8 +46,7 @@ groups() ->
4646 more_than_one_resource_server_id_not_allowed_in_one_token ,
4747 mqtt_expired_token ,
4848 mqtt_expirable_token ,
49- web_mqtt_expirable_token ,
50- amqp_expirable_token
49+ web_mqtt_expirable_token
5150 ]},
5251
5352 {token_refresh , [], [
@@ -73,7 +72,18 @@ groups() ->
7372 ]},
7473 {rich_authorization_requests , [], [
7574 test_successful_connection_with_rich_authorization_request_token
76- ]}
75+ ]},
76+ {amqp , [shuffle ],
77+ [
78+ amqp_token_expire ,
79+ amqp_token_refresh ,
80+ amqp_token_refresh_vhost_permission ,
81+ amqp_token_refresh_exchange_write_permission ,
82+ amqp_token_refresh_queue_read_permission ,
83+ amqp_token_refresh_anon_term_exchange_write_permission ,
84+ amqp_token_refresh_topic_write_permission ,
85+ amqp_token_refresh_expire
86+ ]}
7787 ].
7888
7989% %
@@ -100,7 +110,9 @@ init_per_suite(Config) ->
100110end_per_suite (Config ) ->
101111 rabbit_ct_helpers :run_teardown_steps (Config , rabbit_ct_broker_helpers :teardown_steps ()).
102112
103-
113+ init_per_group (amqp , Config ) ->
114+ {ok , _ } = application :ensure_all_started (rabbitmq_amqp_client ),
115+ Config ;
104116init_per_group (_Group , Config ) ->
105117 % % The broker is managed by {init,end}_per_testcase().
106118 lists :foreach (fun (Value ) ->
@@ -109,6 +121,8 @@ init_per_group(_Group, Config) ->
109121 [<<" vhost1" >>, <<" vhost2" >>, <<" vhost3" >>, <<" vhost4" >>]),
110122 Config .
111123
124+ end_per_group (amqp , Config ) ->
125+ Config ;
112126end_per_group (_Group , Config ) ->
113127 % % The broker is managed by {init,end}_per_testcase().
114128 lists :foreach (fun (Value ) ->
@@ -500,29 +514,20 @@ mqtt_expirable_token0(Port, AdditionalOpts, Connect, Config) ->
500514 after Millis * 2 -> ct :fail (" missing DISCONNECT packet from server" )
501515 end .
502516
503- amqp_expirable_token (Config ) ->
504- {ok , _ } = application :ensure_all_started (rabbitmq_amqp_client ),
505-
517+ % % Test that RabbitMQ closes the AMQP 1.0 connection when the token expires.
518+ amqp_token_expire (Config ) ->
506519 Seconds = 4 ,
507520 Millis = Seconds * 1000 ,
508521 {_Algo , Token } = generate_expirable_token (Config ,
509- [<<" rabbitmq.configure:* /*" >>,
510- <<" rabbitmq.write:* /*" >>,
511- <<" rabbitmq.read:* /*" >>],
522+ [<<" rabbitmq.configure:%2F /*" >>,
523+ <<" rabbitmq.write:%2F /*" >>,
524+ <<" rabbitmq.read:%2F /*" >>],
512525 Seconds ),
513526
514- % % Send and receive a message via AMQP 1.0.
527+ % % Send and receive a message.
528+ {Connection , Session , LinkPair } = amqp_init (Token , Config ),
515529 QName = atom_to_binary (? FUNCTION_NAME ),
516530 Address = rabbitmq_amqp_address :queue (QName ),
517- Host = ? config (rmq_hostname , Config ),
518- Port = rabbit_ct_broker_helpers :get_node_config (Config , 0 , tcp_port_amqp ),
519- OpnConf = #{address => Host ,
520- port => Port ,
521- container_id => <<" my container" >>,
522- sasl => {plain , <<" " >>, Token }},
523- {ok , Connection } = amqp10_client :open_connection (OpnConf ),
524- {ok , Session } = amqp10_client :begin_session_sync (Connection ),
525- {ok , LinkPair } = rabbitmq_amqp_client :attach_management_link_pair_sync (Session , <<" my link pair" >>),
526531 {ok , _ } = rabbitmq_amqp_client :declare_queue (LinkPair , QName , #{}),
527532 {ok , Sender } = amqp10_client :attach_sender_link (Session , <<" my sender" >>, Address ),
528533 receive {amqp10_event , {link , Sender , credited }} -> ok
@@ -544,6 +549,43 @@ amqp_expirable_token(Config) ->
544549 ct :fail (" server did not close our connection" )
545550 end .
546551
552+ amqp_token_refresh (Config ) ->
553+ ok .
554+
555+ % % Test that RabbitMQ closes the AMQP 1.0 connection if the client
556+ % % submits a new token without any permission to the vhost.
557+ amqp_token_refresh_vhost_permission (Config ) ->
558+ {_Algo , Token1 } = generate_valid_token (Config ),
559+ {Connection , Session , LinkPair } = amqp_init (Token1 , Config ),
560+
561+ {_Algo , Token2 } = generate_valid_token (Config ,
562+ [<<" rabbitmq.configure:wrongvhost/*" >>,
563+ <<" rabbitmq.write:wrongvhost/*" >>,
564+ <<" rabbitmq.read:wrongvhost/*" >>]),
565+ ok = rabbitmq_amqp_client :set_token (LinkPair , Token2 ),
566+ receive {amqp10_event ,
567+ {connection , Connection ,
568+ {closed , {unauthorized_access , Reason }}}} ->
569+ ? assertMatch (<<" access to vhost / failed for new credential:" , _ /binary >>,
570+ Reason )
571+ after 5000 -> ct :fail ({missing_event , ? LINE })
572+ end .
573+
574+ amqp_token_refresh_exchange_write_permission (Config ) ->
575+ ok .
576+
577+ amqp_token_refresh_queue_read_permission (Config ) ->
578+ ok .
579+
580+ amqp_token_refresh_anon_term_exchange_write_permission (Config ) ->
581+ ok .
582+
583+ amqp_token_refresh_topic_write_permission (Config ) ->
584+ ok .
585+
586+ amqp_token_refresh_expire (Config ) ->
587+ ok .
588+
547589test_successful_connection_with_complex_claim_as_a_map (Config ) ->
548590 {_Algo , Token } = generate_valid_token_with_extra_fields (
549591 Config ,
@@ -765,3 +807,21 @@ test_failed_connection_with_non_existent_scope_alias_in_scope_field(Config) ->
765807more_than_one_resource_server_id_not_allowed_in_one_token (Config ) ->
766808 {_Algo , Token } = generate_valid_token (Config , <<" rmq.configure:*/*" >>, [<<" prod" >>, <<" dev" >>]),
767809 {error , _ } = open_unmanaged_connection (Config , 0 , <<" username" >>, Token ).
810+
811+ amqp_init (Token , Config ) ->
812+ OpnConf = amqp_connection_config (Token , Config ),
813+ {ok , Connection } = amqp10_client :open_connection (OpnConf ),
814+ receive {amqp10_event , {connection , Connection , opened }} -> ok
815+ after 5000 -> ct :fail ({missing_event , ? LINE })
816+ end ,
817+ {ok , Session } = amqp10_client :begin_session_sync (Connection ),
818+ {ok , LinkPair } = rabbitmq_amqp_client :attach_management_link_pair_sync (Session , <<" my link pair" >>),
819+ {Connection , Session , LinkPair }.
820+
821+ amqp_connection_config (Token , Config ) ->
822+ Host = proplists :get_value (rmq_hostname , Config ),
823+ Port = rabbit_ct_broker_helpers :get_node_config (Config , 0 , tcp_port_amqp ),
824+ #{address => Host ,
825+ port => Port ,
826+ container_id => <<" my container" >>,
827+ sasl => {plain , <<>>, Token }}.
0 commit comments