Skip to content

Commit eed36f0

Browse files
author
Alexandru Scvortov
committed
improved tests for no-access permissions
The tests now: - check if the no-access-all permissions prevent access from everything; - check if the no-access-client permissions allow access to amq.gen resources; - check if the no-access-client permissions prevent access from everything else.
1 parent 1f88aee commit eed36f0

File tree

1 file changed

+36
-25
lines changed

1 file changed

+36
-25
lines changed

test/src/com/rabbitmq/client/test/server/Permissions.java

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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,81 @@ 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+
commonNoAccessTests();
266+
}
267+
265268
public void testNoAccess()
266-
throws IOException
269+
throws IOException, InterruptedException
267270
{
271+
runCtl("set_permissions -p /test -s all test \"\" \"\" \"\"");
272+
Thread.sleep(2000);
268273
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
269274
public void with(String _) throws IOException {
270-
noAccessCh.queueDeclare("justaqueue", false, false, true, null);
275+
channel.queueDeclare();
271276
}}
272277
);
278+
279+
commonNoAccessTests();
280+
}
281+
282+
private void commonNoAccessTests()
283+
throws IOException {
273284
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
274285
public void with(String _) throws IOException {
275-
noAccessCh.queueDeclare();
286+
channel.queueDeclare("justaqueue", false, false, true, null);
276287
}}
277288
);
278289
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
279290
public void with(String _) throws IOException {
280-
noAccessCh.queueDelete("configure");
291+
channel.queueDelete("configure");
281292
}}
282293
);
283294
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
284295
public void with(String _) throws IOException {
285-
noAccessCh.queueBind("write", "write", "write");
296+
channel.queueBind("write", "write", "write");
286297
}}
287298
);
288299
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
289300
public void with(String _) throws IOException {
290-
noAccessCh.queuePurge("read");
301+
channel.queuePurge("read");
291302
}}
292303
);
293304
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
294305
public void with(String _) throws IOException {
295-
noAccessCh.exchangeDeclare("justanexchange", "direct");
306+
channel.exchangeDeclare("justanexchange", "direct");
296307
}}
297308
);
298309
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
299310
public void with(String _) throws IOException {
300-
noAccessCh.exchangeDeclare("configure", "direct");
311+
channel.exchangeDeclare("configure", "direct");
301312
}}
302313
);
303314
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
304315
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();
307318
}}
308319
);
309320
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
310321
public void with(String _) throws IOException {
311-
noAccessCh.basicGet("read", false);
322+
channel.basicGet("read", false);
312323
}}
313324
);
314325
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
315326
public void with(String _) throws IOException {
316-
noAccessCh.basicConsume("read", null);
327+
channel.basicConsume("read", null);
317328
}}
318329
);
319330
}
@@ -333,7 +344,7 @@ protected void expectExceptionRun(int exceptionCode, WithName action)
333344
(AMQP.Channel.Close) ((Command)sse.getReason()).getMethod();
334345
assertEquals(exceptionCode, closeMethod.getReplyCode());
335346
}
336-
noAccessCh = noAccessCh.getConnection().createChannel();
347+
channel = channel.getConnection().createChannel();
337348
}
338349
}
339350

0 commit comments

Comments
 (0)