@@ -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,81 @@ 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
+ commonNoAccessTests ();
266
+ }
267
+
265
268
public void testNoAccess ()
266
- throws IOException
269
+ throws IOException , InterruptedException
267
270
{
271
+ runCtl ("set_permissions -p /test -s all test \" \" \" \" \" \" " );
272
+ Thread .sleep (2000 );
268
273
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
269
274
public void with (String _) throws IOException {
270
- noAccessCh .queueDeclare ("justaqueue" , false , false , true , null );
275
+ channel .queueDeclare ();
271
276
}}
272
277
);
278
+
279
+ commonNoAccessTests ();
280
+ }
281
+
282
+ private void commonNoAccessTests ()
283
+ throws IOException {
273
284
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
274
285
public void with (String _) throws IOException {
275
- noAccessCh .queueDeclare ();
286
+ channel .queueDeclare ("justaqueue" , false , false , true , null );
276
287
}}
277
288
);
278
289
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
279
290
public void with (String _) throws IOException {
280
- noAccessCh .queueDelete ("configure" );
291
+ channel .queueDelete ("configure" );
281
292
}}
282
293
);
283
294
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
284
295
public void with (String _) throws IOException {
285
- noAccessCh .queueBind ("write" , "write" , "write" );
296
+ channel .queueBind ("write" , "write" , "write" );
286
297
}}
287
298
);
288
299
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
289
300
public void with (String _) throws IOException {
290
- noAccessCh .queuePurge ("read" );
301
+ channel .queuePurge ("read" );
291
302
}}
292
303
);
293
304
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
294
305
public void with (String _) throws IOException {
295
- noAccessCh .exchangeDeclare ("justanexchange" , "direct" );
306
+ channel .exchangeDeclare ("justanexchange" , "direct" );
296
307
}}
297
308
);
298
309
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
299
310
public void with (String _) throws IOException {
300
- noAccessCh .exchangeDeclare ("configure" , "direct" );
311
+ channel .exchangeDeclare ("configure" , "direct" );
301
312
}}
302
313
);
303
314
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
304
315
public void with (String _) throws IOException {
305
- noAccessCh .basicPublish ("write" , "" , null , "foo" .getBytes ());
306
- noAccessCh .queueDeclare ();
316
+ channel .basicPublish ("write" , "" , null , "foo" .getBytes ());
317
+ channel .queueDeclare ();
307
318
}}
308
319
);
309
320
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
310
321
public void with (String _) throws IOException {
311
- noAccessCh .basicGet ("read" , false );
322
+ channel .basicGet ("read" , false );
312
323
}}
313
324
);
314
325
expectExceptionRun (AMQP .ACCESS_REFUSED , new WithName () {
315
326
public void with (String _) throws IOException {
316
- noAccessCh .basicConsume ("read" , null );
327
+ channel .basicConsume ("read" , null );
317
328
}}
318
329
);
319
330
}
@@ -333,7 +344,7 @@ protected void expectExceptionRun(int exceptionCode, WithName action)
333
344
(AMQP .Channel .Close ) ((Command )sse .getReason ()).getMethod ();
334
345
assertEquals (exceptionCode , closeMethod .getReplyCode ());
335
346
}
336
- noAccessCh = noAccessCh .getConnection ().createChannel ();
347
+ channel = channel .getConnection ().createChannel ();
337
348
}
338
349
}
339
350
0 commit comments