@@ -48,6 +48,8 @@ groups() ->
4848 test_update_secret ,
4949 cannot_update_username_after_authenticated ,
5050 cannot_use_another_authmechanism_when_updating_secret ,
51+ update_secret_should_close_connection_if_wrong_secret ,
52+ update_secret_should_close_connection_if_unauthorized_vhost ,
5153 unauthenticated_client_rejected_tcp_connected ,
5254 timeout_tcp_connected ,
5355 unauthenticated_client_rejected_peer_properties_exchanged ,
@@ -165,6 +167,12 @@ init_per_testcase(cannot_update_username_after_authenticated = TestCase, Config)
165167 ok = rabbit_ct_broker_helpers :add_user (Config , <<" other" >>),
166168 rabbit_ct_helpers :testcase_started (Config , TestCase );
167169
170+ init_per_testcase (update_secret_should_close_connection_if_unauthorized_vhost = TestCase ,
171+ Config ) ->
172+ ok = rabbit_ct_broker_helpers :add_user (Config , <<" other" >>),
173+ ok = rabbit_ct_broker_helpers :set_full_permissions (Config , <<" other" >>, <<" /" >>),
174+ rabbit_ct_helpers :testcase_started (Config , TestCase );
175+
168176init_per_testcase (close_connection_on_consumer_update_timeout = TestCase , Config ) ->
169177 ok = rabbit_ct_broker_helpers :rpc (Config ,
170178 0 ,
@@ -200,6 +208,11 @@ end_per_testcase(cannot_update_username_after_authenticated = TestCase, Config)
200208 ok = rabbit_ct_broker_helpers :delete_user (Config , <<" other" >>),
201209 rabbit_ct_helpers :testcase_finished (Config , TestCase );
202210
211+ end_per_testcase (update_secret_should_close_connection_if_unauthorized_vhost = TestCase ,
212+ Config ) ->
213+ ok = rabbit_ct_broker_helpers :delete_user (Config , <<" other" >>),
214+ rabbit_ct_helpers :testcase_finished (Config , TestCase );
215+
203216end_per_testcase (close_connection_on_consumer_update_timeout = TestCase , Config ) ->
204217 ok = rabbit_ct_broker_helpers :rpc (Config ,
205218 0 ,
@@ -285,29 +298,53 @@ test_update_secret(Config) ->
285298 {S , C0 } = connect_and_authenticate (Transport , Config ),
286299 rabbit_ct_broker_helpers :change_password (Config , <<" guest" >>, <<" password" >>),
287300 C1 = expect_successful_authentication (
288- try_authenticate (Transport , S , C0 , <<" PLAIN" >>, <<" guest" >>, <<" password" >>)),
301+ try_authenticate (Transport , S , C0 , <<" PLAIN" >>, <<" guest" >>, <<" password" >>)),
289302 _C2 = test_close (Transport , S , C1 ),
290303 closed = wait_for_socket_close (Transport , S , 10 ),
291304 ok .
292305
293306cannot_update_username_after_authenticated (Config ) ->
294307 {S , C0 } = connect_and_authenticate (gen_tcp , Config ),
295- C1 = expect_unsuccessful_authentication (
296- try_authenticate (gen_tcp , S , C0 , <<" PLAIN" >>, <<" other" >>, <<" other" >>),
297- ? RESPONSE_SASL_CANNOT_CHANGE_USERNAME ),
298- _C2 = test_close (gen_tcp , S , C1 ),
308+ _C1 = expect_unsuccessful_authentication (
309+ try_authenticate (gen_tcp , S , C0 , <<" PLAIN" >>, <<" other" >>, <<" other" >>),
310+ ? RESPONSE_SASL_CANNOT_CHANGE_USERNAME ),
299311 closed = wait_for_socket_close (gen_tcp , S , 10 ),
300312 ok .
301313
302314cannot_use_another_authmechanism_when_updating_secret (Config ) ->
303315 {S , C0 } = connect_and_authenticate (gen_tcp , Config ),
304- C1 = expect_unsuccessful_authentication (
305- try_authenticate (gen_tcp , S , C0 , <<" EXTERNAL" >>, <<" guest" >>, <<" new_password" >>),
306- ? RESPONSE_SASL_CANNOT_CHANGE_MECHANISM ),
307- _C2 = test_close (gen_tcp , S , C1 ),
316+ _C1 = expect_unsuccessful_authentication (
317+ try_authenticate (gen_tcp , S , C0 , <<" EXTERNAL" >>, <<" guest" >>, <<" new_password" >>),
318+ ? RESPONSE_SASL_CANNOT_CHANGE_MECHANISM ),
308319 closed = wait_for_socket_close (gen_tcp , S , 10 ),
309320 ok .
310321
322+ update_secret_should_close_connection_if_wrong_secret (Config ) ->
323+ Transport = gen_tcp ,
324+ {S , C0 } = connect_and_authenticate (Transport , Config ),
325+ Pwd = rand :bytes (20 ),
326+ _C1 = expect_unsuccessful_authentication (
327+ try_authenticate (Transport , S , C0 , <<" PLAIN" >>, <<" guest" >>, Pwd ),
328+ ? RESPONSE_AUTHENTICATION_FAILURE ),
329+ closed = wait_for_socket_close (Transport , S , 10 ),
330+ ok .
331+
332+ update_secret_should_close_connection_if_unauthorized_vhost (Config ) ->
333+ T = gen_tcp ,
334+ Port = get_port (T , Config ),
335+ Opts = get_opts (T ),
336+ {ok , S } = T :connect (" localhost" , Port , Opts ),
337+ C0 = rabbit_stream_core :init (0 ),
338+ C1 = test_peer_properties (T , S , C0 ),
339+ Username = <<" other" >>,
340+ C2 = test_authenticate (T , S , C1 , Username ),
341+ ok = rabbit_ct_broker_helpers :clear_permissions (Config , Username , <<" /" >>),
342+ _C3 = expect_unsuccessful_authentication (
343+ try_authenticate (gen_tcp , S , C2 , <<" PLAIN" >>, Username , Username ),
344+ ? RESPONSE_VHOST_ACCESS_FAILURE ),
345+ closed = wait_for_socket_close (T , S , 10 ),
346+ ok .
347+
311348test_stream_tls (Config ) ->
312349 Stream = atom_to_binary (? FUNCTION_NAME , utf8 ),
313350 test_server (ssl , Stream , Config ),
0 commit comments