1515package com .rabbitmq .stream .impl ;
1616
1717import static com .rabbitmq .stream .Cli .*;
18+ import static com .rabbitmq .stream .Cli .clearPermissions ;
1819import static com .rabbitmq .stream .impl .Assertions .assertThat ;
1920import static com .rabbitmq .stream .impl .TestUtils .BrokerVersion .RABBITMQ_3_13_0 ;
21+ import static com .rabbitmq .stream .impl .TestUtils .BrokerVersion .RABBITMQ_4_1_4 ;
2022import static org .assertj .core .api .Assertions .assertThat ;
2123import static org .assertj .core .api .Assertions .assertThatThrownBy ;
2224
@@ -196,6 +198,34 @@ void updateSecretBrokerShouldCloseConnectionWithUpdatedUsername() {
196198 }
197199 }
198200
201+ @ Test
202+ @ BrokerVersionAtLeast (RABBITMQ_4_1_4 )
203+ void updateSecretBrokerShouldCloseConnectionIfUnauthorizedVhost () {
204+ String u = "stream" ;
205+ String p = "stream" ;
206+ try {
207+ addUser (u , p );
208+ setPermissions (u , "/" , "^stream.*$" );
209+ TestUtils .Sync closedSync = TestUtils .sync ();
210+ Client client =
211+ cf .get (
212+ new Client .ClientParameters ()
213+ .username (u )
214+ .password (p )
215+ .shutdownListener (shutdownContext -> closedSync .down ()));
216+ clearPermissions (u );
217+ assertThatThrownBy (() -> client .authenticate (credentialsProvider (u , p )))
218+ .isInstanceOf (StreamException .class )
219+ .hasMessageContaining (
220+ String .valueOf (Constants .RESPONSE_CODE_VIRTUAL_HOST_ACCESS_FAILURE ));
221+ assertThat (closedSync ).completes ();
222+ assertThat (client .isOpen ()).isFalse ();
223+ client .close ();
224+ } finally {
225+ deleteUser (u );
226+ }
227+ }
228+
199229 @ Test
200230 @ BrokerVersionAtLeast (TestUtils .BrokerVersion .RABBITMQ_4_0_0 )
201231 void anonymousAuthenticationShouldWork () {
@@ -209,6 +239,6 @@ private static CredentialsProvider credentialsProvider(String username, String p
209239 }
210240
211241 private boolean connectionClosedOnUpdateSecretFailure () {
212- return TestUtils .atLeastVersion ("4.1.4" , brokerVersion );
242+ return TestUtils .atLeastVersion (RABBITMQ_4_1_4 . version () , brokerVersion );
213243 }
214244}
0 commit comments