@@ -52,7 +52,6 @@ public class Permissions extends BrokerTestCase
52
52
{
53
53
54
54
protected Channel adminCh ;
55
- protected Channel noAccessCh ;
56
55
57
56
public Permissions ()
58
57
{
@@ -82,21 +81,17 @@ protected void addRestrictedAccount()
82
81
{
83
82
runCtl ("add_user test test" );
84
83
runCtl ("add_user testadmin test" );
85
- runCtl ("add_user noaccess test" );
86
84
runCtl ("add_vhost /test" );
87
85
runCtl ("set_permissions -p /test test configure write read" );
88
86
runCtl ("set_permissions -p /test testadmin \" .*\" \" .*\" \" .*\" " );
89
- runCtl ("set_permissions -p /test -s all noaccess \" \" \" \" \" \" " );
90
87
}
91
88
92
89
protected void deleteRestrictedAccount ()
93
90
throws IOException
94
91
{
95
- runCtl ("clear_permissions -p /test noaccess" );
96
92
runCtl ("clear_permissions -p /test testadmin" );
97
93
runCtl ("clear_permissions -p /test test" );
98
94
runCtl ("delete_vhost /test" );
99
- runCtl ("delete_user noaccess" );
100
95
runCtl ("delete_user testadmin" );
101
96
runCtl ("delete_user test" );
102
97
}
@@ -122,12 +117,6 @@ public void with(String name) throws IOException {
122
117
adminCh .exchangeDeclare (name , "direct" );
123
118
adminCh .queueDeclare (name , false , false , false , null );
124
119
}});
125
-
126
- factory = new ConnectionFactory ();
127
- factory .setUsername ("noaccess" );
128
- factory .setPassword ("test" );
129
- factory .setVirtualHost ("/test" );
130
- noAccessCh = factory .newConnection ().createChannel ();
131
120
}
132
121
133
122
protected void releaseResources ()
@@ -139,7 +128,6 @@ public void with(String name) throws IOException {
139
128
adminCh .exchangeDelete (name );
140
129
}});
141
130
adminCh .getConnection ().abort ();
142
- noAccessCh .getConnection ().abort ();
143
131
}
144
132
145
133
protected void withNames (WithName action )
@@ -262,58 +250,88 @@ public void testAltExchConfiguration()
262
250
createAltExchConfigTest ("configure-and-read-me" ));
263
251
}
264
252
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
+
265
275
public void testNoAccess ()
266
- throws IOException
276
+ throws IOException , InterruptedException
267
277
{
278
+ runCtl ("set_permissions -p /test -s all test \" \" \" \" \" \" " );
279
+ Thread .sleep (2000 );
268
280
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
269
281
public void with (String _) throws IOException {
270
- noAccessCh .queueDeclare ("justaqueue" , false , false , true , null );
282
+ channel .queueDeclare ();
271
283
}}
272
284
);
285
+
286
+ commonNoAccessTests ();
287
+ }
288
+
289
+ private void commonNoAccessTests ()
290
+ throws IOException {
273
291
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
274
292
public void with (String _) throws IOException {
275
- noAccessCh .queueDeclare ();
293
+ channel .queueDeclare ("justaqueue" , false , false , true , null );
276
294
}}
277
295
);
278
296
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
279
297
public void with (String _) throws IOException {
280
- noAccessCh .queueDelete ("configure" );
298
+ channel .queueDelete ("configure" );
281
299
}}
282
300
);
283
301
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
284
302
public void with (String _) throws IOException {
285
- noAccessCh .queueBind ("write" , "write" , "write" );
303
+ channel .queueBind ("write" , "write" , "write" );
286
304
}}
287
305
);
288
306
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
289
307
public void with (String _) throws IOException {
290
- noAccessCh .queuePurge ("read" );
308
+ channel .queuePurge ("read" );
291
309
}}
292
310
);
293
311
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
294
312
public void with (String _) throws IOException {
295
- noAccessCh .exchangeDeclare ("justanexchange" , "direct" );
313
+ channel .exchangeDeclare ("justanexchange" , "direct" );
296
314
}}
297
315
);
298
316
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
299
317
public void with (String _) throws IOException {
300
- noAccessCh .exchangeDeclare ("configure" , "direct" );
318
+ channel .exchangeDeclare ("configure" , "direct" );
301
319
}}
302
320
);
303
321
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
304
322
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 ();
307
325
}}
308
326
);
309
327
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
310
328
public void with (String _) throws IOException {
311
- noAccessCh .basicGet ("read" , false );
329
+ channel .basicGet ("read" , false );
312
330
}}
313
331
);
314
332
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
315
333
public void with (String _) throws IOException {
316
- noAccessCh .basicConsume ("read" , null );
334
+ channel .basicConsume ("read" , null );
317
335
}}
318
336
);
319
337
}
@@ -333,7 +351,7 @@ protected void expectExceptionRun(int exceptionCode, WithName action)
333
351
(AMQP .Channel .Close ) ((Command )sse .getReason ()).getMethod ();
334
352
assertEquals (exceptionCode , closeMethod .getReplyCode ());
335
353
}
336
- noAccessCh = noAccessCh .getConnection ().createChannel ();
354
+ channel = channel .getConnection ().createChannel ();
337
355
}
338
356
}
339
357
0 commit comments