Skip to content

Commit b3d5a53

Browse files
author
Simon MacMullen
committed
Merge bug22875 into default
2 parents 796ab58 + a92d59e commit b3d5a53

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

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

Lines changed: 76 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,69 @@ 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+
}}
273+
);
274+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
275+
public void with(String _) throws IOException {
276+
noAccessCh.queueDelete("configure");
277+
}}
278+
);
279+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
280+
public void with(String _) throws IOException {
281+
noAccessCh.queueBind("write", "write", "write");
282+
}}
283+
);
284+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
285+
public void with(String _) throws IOException {
286+
noAccessCh.queuePurge("read");
287+
}}
288+
);
289+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
290+
public void with(String _) throws IOException {
291+
noAccessCh.exchangeDeclare("justanexchange", "direct");
292+
}}
293+
);
294+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
295+
public void with(String _) throws IOException {
296+
noAccessCh.exchangeDeclare("configure", "direct");
297+
}}
298+
);
299+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
300+
public void with(String _) throws IOException {
301+
noAccessCh.basicPublish("write", "", null, "foo".getBytes());
302+
noAccessCh.queueDeclare();
303+
}}
304+
);
305+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
306+
public void with(String _) throws IOException {
307+
noAccessCh.basicGet("read", false);
308+
}}
309+
);
310+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
311+
public void with(String _) throws IOException {
312+
noAccessCh.basicConsume("read", null);
313+
}}
314+
);
315+
}
316+
317+
protected void expectExceptionRun(int exceptionCode, WithName action)
318+
throws IOException
319+
{
320+
try {
321+
action.with("");
322+
fail();
323+
} catch (IOException e) {
324+
noAccessCh = noAccessConn.createChannel();
325+
checkShutdownSignal(exceptionCode, e);
326+
}
327+
}
328+
253329
protected WithName createAltExchConfigTest(final String exchange)
254330
throws IOException
255331
{

0 commit comments

Comments
 (0)