@@ -61,7 +61,9 @@ groups() ->
61
61
should_receive_metadata_update_after_update_secret ,
62
62
store_offset_requires_read_access ,
63
63
offset_lag_calculation ,
64
- test_super_stream_duplicate_partitions
64
+ test_super_stream_duplicate_partitions ,
65
+ authentication_error_should_close_with_delay ,
66
+ unauthorized_vhost_access_should_close_with_delay
65
67
]},
66
68
% % Run `test_global_counters` on its own so the global metrics are
67
69
% % initialised to 0 for each testcase
@@ -173,6 +175,10 @@ init_per_testcase(store_offset_requires_read_access = TestCase, Config) ->
173
175
ok = rabbit_ct_broker_helpers :add_user (Config , <<" test" >>),
174
176
rabbit_ct_helpers :testcase_started (Config , TestCase );
175
177
178
+ init_per_testcase (unauthorized_vhost_access_should_close_with_delay = TestCase , Config ) ->
179
+ ok = rabbit_ct_broker_helpers :add_user (Config , <<" other" >>),
180
+ rabbit_ct_helpers :testcase_started (Config , TestCase );
181
+
176
182
init_per_testcase (TestCase , Config ) ->
177
183
rabbit_ct_helpers :testcase_started (Config , TestCase ).
178
184
@@ -201,6 +207,9 @@ end_per_testcase(vhost_queue_limit = TestCase, Config) ->
201
207
end_per_testcase (store_offset_requires_read_access = TestCase , Config ) ->
202
208
ok = rabbit_ct_broker_helpers :delete_user (Config , <<" test" >>),
203
209
rabbit_ct_helpers :testcase_finished (Config , TestCase );
210
+ end_per_testcase (unauthorized_vhost_access_should_close_with_delay = TestCase , Config ) ->
211
+ ok = rabbit_ct_broker_helpers :delete_user (Config , <<" other" >>),
212
+ rabbit_ct_helpers :testcase_finished (Config , TestCase );
204
213
end_per_testcase (TestCase , Config ) ->
205
214
rabbit_ct_helpers :testcase_finished (Config , TestCase ).
206
215
@@ -890,6 +899,41 @@ offset_lag_calculation(Config) ->
890
899
891
900
ok .
892
901
902
+ authentication_error_should_close_with_delay (Config ) ->
903
+ T = gen_tcp ,
904
+ Port = get_port (T , Config ),
905
+ Opts = get_opts (T ),
906
+ {ok , S } = T :connect (" localhost" , Port , Opts ),
907
+ C0 = rabbit_stream_core :init (0 ),
908
+ C1 = test_peer_properties (T , S , C0 ),
909
+ Start = erlang :monotonic_time (millisecond ),
910
+ _ = expect_unsuccessful_authentication (
911
+ try_authenticate (T , S , C1 , <<" PLAIN" >>, <<" guest" >>, <<" wrong password" >>),
912
+ ? RESPONSE_AUTHENTICATION_FAILURE ),
913
+ End = erlang :monotonic_time (millisecond ),
914
+ % % the stream reader module defines the delay (3 seconds)
915
+ ? assert (End - Start > 2_000 ),
916
+ closed = wait_for_socket_close (T , S , 10 ),
917
+ ok .
918
+
919
+ unauthorized_vhost_access_should_close_with_delay (Config ) ->
920
+ T = gen_tcp ,
921
+ Port = get_port (T , Config ),
922
+ Opts = get_opts (T ),
923
+ {ok , S } = T :connect (" localhost" , Port , Opts ),
924
+ C0 = rabbit_stream_core :init (0 ),
925
+ C1 = test_peer_properties (T , S , C0 ),
926
+ User = <<" other" >>,
927
+ C2 = test_plain_sasl_authenticate (T , S , sasl_handshake (T , S , C1 ), User ),
928
+ Start = erlang :monotonic_time (millisecond ),
929
+ R = do_tune (T , S , C2 ),
930
+ ? assertMatch ({{response ,_ ,{open ,12 }}, _ }, R ),
931
+ End = erlang :monotonic_time (millisecond ),
932
+ % % the stream reader module defines the delay (3 seconds)
933
+ ? assert (End - Start > 2_000 ),
934
+ closed = wait_for_socket_close (T , S , 10 ),
935
+ ok .
936
+
893
937
consumer_offset_info (Config , ConnectionName ) ->
894
938
[[{offset , Offset },
895
939
{offset_lag , Lag }]] = rpc (Config , 0 , ? MODULE ,
@@ -1093,12 +1137,15 @@ test_peer_properties(Transport, S, Properties, C0) ->
1093
1137
C .
1094
1138
1095
1139
test_authenticate (Transport , S , C0 ) ->
1096
- tune (Transport , S ,
1097
- test_plain_sasl_authenticate (Transport , S , sasl_handshake (Transport , S , C0 ), <<" guest" >>)).
1140
+ tune (Transport , S ,
1141
+ test_plain_sasl_authenticate (Transport , S , sasl_handshake (Transport , S , C0 ), <<" guest" >>)).
1098
1142
1099
1143
test_authenticate (Transport , S , C0 , Username ) ->
1100
- tune (Transport , S ,
1101
- test_plain_sasl_authenticate (Transport , S , sasl_handshake (Transport , S , C0 ), Username )).
1144
+ test_authenticate (Transport , S , C0 , Username , Username ).
1145
+
1146
+ test_authenticate (Transport , S , C0 , Username , Password ) ->
1147
+ tune (Transport , S ,
1148
+ test_plain_sasl_authenticate (Transport , S , sasl_handshake (Transport , S , C0 ), Username , Password )).
1102
1149
1103
1150
sasl_handshake (Transport , S , C0 ) ->
1104
1151
SaslHandshakeFrame = request (sasl_handshake ),
@@ -1115,7 +1162,10 @@ sasl_handshake(Transport, S, C0) ->
1115
1162
C1 .
1116
1163
1117
1164
test_plain_sasl_authenticate (Transport , S , C1 , Username ) ->
1118
- expect_successful_authentication (plain_sasl_authenticate (Transport , S , C1 , Username , Username )).
1165
+ test_plain_sasl_authenticate (Transport , S , C1 , Username , Username ).
1166
+
1167
+ test_plain_sasl_authenticate (Transport , S , C1 , Username , Password ) ->
1168
+ expect_successful_authentication (plain_sasl_authenticate (Transport , S , C1 , Username , Password )).
1119
1169
1120
1170
plain_sasl_authenticate (Transport , S , C1 , Username , Password ) ->
1121
1171
Null = 0 ,
@@ -1136,6 +1186,10 @@ sasl_authenticate(Transport, S, C1, AuthMethod, AuthBody) ->
1136
1186
receive_commands (Transport , S , C1 ).
1137
1187
1138
1188
tune (Transport , S , C2 ) ->
1189
+ {{response , _ , {open , ? RESPONSE_CODE_OK , _ }}, C3 } = do_tune (Transport , S , C2 ),
1190
+ C3 .
1191
+
1192
+ do_tune (Transport , S , C2 ) ->
1139
1193
{Tune , C3 } = receive_commands (Transport , S , C2 ),
1140
1194
{tune , ? DEFAULT_FRAME_MAX , ? DEFAULT_HEARTBEAT } = Tune ,
1141
1195
@@ -1147,10 +1201,7 @@ tune(Transport, S, C2) ->
1147
1201
VirtualHost = <<" /" >>,
1148
1202
OpenFrame = request (3 , {open , VirtualHost }),
1149
1203
ok = Transport :send (S , OpenFrame ),
1150
- {{response , 3 , {open , ? RESPONSE_CODE_OK , _ConnectionProperties }},
1151
- C4 } =
1152
- receive_commands (Transport , S , C3 ),
1153
- C4 .
1204
+ receive_commands (Transport , S , C3 ).
1154
1205
1155
1206
test_create_stream (Transport , S , Stream , C0 ) ->
1156
1207
CreateStreamFrame = request ({create_stream , Stream , #{}}),
0 commit comments