@@ -52,7 +52,6 @@ public class Permissions extends BrokerTestCase
5252{
5353
5454 protected Channel adminCh ;
55- protected Channel noAccessCh ;
5655
5756 public Permissions ()
5857 {
@@ -82,21 +81,17 @@ protected void addRestrictedAccount()
8281 {
8382 runCtl ("add_user test test" );
8483 runCtl ("add_user testadmin test" );
85- runCtl ("add_user noaccess test" );
8684 runCtl ("add_vhost /test" );
8785 runCtl ("set_permissions -p /test test configure write read" );
8886 runCtl ("set_permissions -p /test testadmin \" .*\" \" .*\" \" .*\" " );
89- runCtl ("set_permissions -p /test -s all noaccess \" \" \" \" \" \" " );
9087 }
9188
9289 protected void deleteRestrictedAccount ()
9390 throws IOException
9491 {
95- runCtl ("clear_permissions -p /test noaccess" );
9692 runCtl ("clear_permissions -p /test testadmin" );
9793 runCtl ("clear_permissions -p /test test" );
9894 runCtl ("delete_vhost /test" );
99- runCtl ("delete_user noaccess" );
10095 runCtl ("delete_user testadmin" );
10196 runCtl ("delete_user test" );
10297 }
@@ -122,12 +117,6 @@ public void with(String name) throws IOException {
122117 adminCh .exchangeDeclare (name , "direct" );
123118 adminCh .queueDeclare (name , false , false , false , null );
124119 }});
125-
126- factory = new ConnectionFactory ();
127- factory .setUsername ("noaccess" );
128- factory .setPassword ("test" );
129- factory .setVirtualHost ("/test" );
130- noAccessCh = factory .newConnection ().createChannel ();
131120 }
132121
133122 protected void releaseResources ()
@@ -139,7 +128,6 @@ public void with(String name) throws IOException {
139128 adminCh .exchangeDelete (name );
140129 }});
141130 adminCh .getConnection ().abort ();
142- noAccessCh .getConnection ().abort ();
143131 }
144132
145133 protected void withNames (WithName action )
@@ -262,58 +250,88 @@ public void testAltExchConfiguration()
262250 createAltExchConfigTest ("configure-and-read-me" ));
263251 }
264252
253+ public void testClientNoAccess ()
254+ throws IOException , InterruptedException
255+ {
256+ runCtl ("set_permissions -p /test test -s client \" \" \" \" amq.direct" );
257+ Thread .sleep (2000 );
258+ {
259+ String queueName =
260+ channel .queueDeclare ().getQueue (); // configure
261+ channel .queueBind (queueName , "amq.direct" , queueName ); // write
262+ channel .queuePurge (queueName ); // read
263+ channel .queueDelete (queueName ); // configure
264+ }
265+
266+ expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
267+ public void with (String _) throws IOException {
268+ channel .queueDeclare ("amq.genbah" , false , false , false , null );
269+ }}
270+ );
271+
272+ commonNoAccessTests ();
273+ }
274+
265275 public void testNoAccess ()
266- throws IOException
276+ throws IOException , InterruptedException
267277 {
278+ runCtl ("set_permissions -p /test -s all test \" \" \" \" \" \" " );
279+ Thread .sleep (2000 );
268280 expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
269281 public void with (String _) throws IOException {
270- noAccessCh .queueDeclare ("justaqueue" , false , false , true , null );
282+ channel .queueDeclare ();
271283 }}
272284 );
285+
286+ commonNoAccessTests ();
287+ }
288+
289+ private void commonNoAccessTests ()
290+ throws IOException {
273291 expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
274292 public void with (String _) throws IOException {
275- noAccessCh .queueDeclare ();
293+ channel .queueDeclare ("justaqueue" , false , false , true , null );
276294 }}
277295 );
278296 expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
279297 public void with (String _) throws IOException {
280- noAccessCh .queueDelete ("configure" );
298+ channel .queueDelete ("configure" );
281299 }}
282300 );
283301 expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
284302 public void with (String _) throws IOException {
285- noAccessCh .queueBind ("write" , "write" , "write" );
303+ channel .queueBind ("write" , "write" , "write" );
286304 }}
287305 );
288306 expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
289307 public void with (String _) throws IOException {
290- noAccessCh .queuePurge ("read" );
308+ channel .queuePurge ("read" );
291309 }}
292310 );
293311 expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
294312 public void with (String _) throws IOException {
295- noAccessCh .exchangeDeclare ("justanexchange" , "direct" );
313+ channel .exchangeDeclare ("justanexchange" , "direct" );
296314 }}
297315 );
298316 expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
299317 public void with (String _) throws IOException {
300- noAccessCh .exchangeDeclare ("configure" , "direct" );
318+ channel .exchangeDeclare ("configure" , "direct" );
301319 }}
302320 );
303321 expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
304322 public void with (String _) throws IOException {
305- noAccessCh .basicPublish ("write" , "" , null , "foo" .getBytes ());
306- noAccessCh .queueDeclare ();
323+ channel .basicPublish ("write" , "" , null , "foo" .getBytes ());
324+ channel .queueDeclare ();
307325 }}
308326 );
309327 expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
310328 public void with (String _) throws IOException {
311- noAccessCh .basicGet ("read" , false );
329+ channel .basicGet ("read" , false );
312330 }}
313331 );
314332 expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
315333 public void with (String _) throws IOException {
316- noAccessCh .basicConsume ("read" , null );
334+ channel .basicConsume ("read" , null );
317335 }}
318336 );
319337 }
@@ -333,7 +351,7 @@ protected void expectExceptionRun(int exceptionCode, WithName action)
333351 (AMQP .Channel .Close ) ((Command )sse .getReason ()).getMethod ();
334352 assertEquals (exceptionCode , closeMethod .getReplyCode ());
335353 }
336- noAccessCh = noAccessCh .getConnection ().createChannel ();
354+ channel = channel .getConnection ().createChannel ();
337355 }
338356 }
339357
0 commit comments