Skip to content

Commit d671583

Browse files
author
Alexandru Scvortov
committed
added tests for the "" "" "" permission special case
1 parent 66a4a5e commit d671583

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

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

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public class Permissions extends BrokerTestCase
5252
{
5353

5454
protected Channel adminCh;
55+
protected Connection noAccessConn;
56+
protected Channel noAccessCh;
5557

5658
public Permissions()
5759
{
@@ -81,17 +83,21 @@ protected void addRestrictedAccount()
8183
{
8284
runCtl("add_user test test");
8385
runCtl("add_user testadmin test");
86+
runCtl("add_user noaccess test");
8487
runCtl("add_vhost /test");
8588
runCtl("set_permissions -p /test test configure write read");
8689
runCtl("set_permissions -p /test testadmin \".*\" \".*\" \".*\"");
90+
runCtl("set_permissions -p /test noaccess \"\" \"\" \"\"");
8791
}
8892

8993
protected void deleteRestrictedAccount()
9094
throws IOException
9195
{
96+
runCtl("clear_permissions -p /test noaccess");
9297
runCtl("clear_permissions -p /test testadmin");
9398
runCtl("clear_permissions -p /test test");
9499
runCtl("delete_vhost /test");
100+
runCtl("delete_user noaccess");
95101
runCtl("delete_user testadmin");
96102
runCtl("delete_user test");
97103
}
@@ -117,6 +123,13 @@ public void with(String name) throws IOException {
117123
adminCh.exchangeDeclare(name, "direct");
118124
adminCh.queueDeclare(name, false, false, false, null);
119125
}});
126+
127+
factory = new ConnectionFactory();
128+
factory.setUsername("noaccess");
129+
factory.setPassword("test");
130+
factory.setVirtualHost("/test");
131+
noAccessConn = factory.newConnection();
132+
noAccessCh = noAccessConn.createChannel();
120133
}
121134

122135
protected void releaseResources()
@@ -250,6 +263,77 @@ public void testAltExchConfiguration()
250263
createAltExchConfigTest("configure-and-read-me"));
251264
}
252265

266+
public void testNoAccess()
267+
throws IOException
268+
{
269+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
270+
public void with(String _) throws IOException {
271+
noAccessCh.queueDeclare("justaqueue", false, false, true, null);
272+
fail("user noaccess should not be able to declare a queue");
273+
}
274+
});
275+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
276+
public void with(String _) throws IOException {
277+
noAccessCh.queueDelete("configure");
278+
fail("user noaccess should not be able to delete a queue");
279+
}
280+
});
281+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
282+
public void with(String _) throws IOException {
283+
noAccessCh.queueBind("write", "write", "write");
284+
fail("user noaccess should not be able to bind a queue");
285+
}
286+
});
287+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
288+
public void with(String _) throws IOException {
289+
noAccessCh.queuePurge("read");
290+
fail("user noaccess should not be able to purge a queue");
291+
}
292+
});
293+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
294+
public void with(String _) throws IOException {
295+
noAccessCh.exchangeDeclare("justanexchange", "direct");
296+
fail("user noaccess should not be able to declare an exchange");
297+
}
298+
});
299+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
300+
public void with(String _) throws IOException {
301+
noAccessCh.exchangeDeclare("configure", "direct");
302+
fail("user noaccess should not be able to delete an exchange");
303+
}
304+
});
305+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
306+
public void with(String _) throws IOException {
307+
noAccessCh.basicPublish("write", "", null, "foo".getBytes());
308+
noAccessCh.queueDeclare();
309+
fail("user noaccess should not be able to publish");
310+
}
311+
});
312+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
313+
public void with(String _) throws IOException {
314+
noAccessCh.basicGet("read", false);
315+
fail("user noaccess should not be able to get");
316+
}
317+
});
318+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
319+
public void with(String _) throws IOException {
320+
noAccessCh.basicConsume("read", null);
321+
fail("user noaccess should not be able to consume");
322+
}
323+
});
324+
}
325+
326+
protected void expectExceptionRun(int exceptionCode, WithName action)
327+
throws IOException
328+
{
329+
try {
330+
action.with("");
331+
} catch (IOException e) {
332+
noAccessCh = noAccessConn.createChannel();
333+
checkShutdownSignal(exceptionCode, e);
334+
}
335+
}
336+
253337
protected WithName createAltExchConfigTest(final String exchange)
254338
throws IOException
255339
{

0 commit comments

Comments
 (0)