Skip to content

Commit 2db8dc1

Browse files
Merge pull request #243 from rabbitmq/rabbitmq-server-1099
Add test for topic permission on queue bind/unbind
2 parents 06b6d85 + 6427eb2 commit 2db8dc1

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ protected void createResources() throws IOException, TimeoutException {
4040
channel.exchangeDeclare(notProtectedTopic, BuiltinExchangeType.TOPIC);
4141
channel.exchangeDeclare(noneTopicExchange, BuiltinExchangeType.DIRECT);
4242

43-
Host.rabbitmqctl("set_topic_permissions -p / guest " + protectedTopic + " \"^a\" \"^b\"");
44-
Host.rabbitmqctl("set_topic_permissions -p / guest " + noneTopicExchange + " \"^a\" \"^b\"");
43+
Host.rabbitmqctl("set_topic_permissions -p / guest " + protectedTopic + " \"^a\" \"^x\"");
44+
Host.rabbitmqctl("set_topic_permissions -p / guest " + noneTopicExchange + " \"^a\" \"^x\"");
4545
}
4646

4747
@Override
@@ -87,6 +87,39 @@ public Void call() throws Exception {
8787
return null;
8888
}
8989
});
90+
assertAccessOk("Binding/unbinding on protected exchange with matching routing key, should pass", new Callable<Void>() {
91+
@Override
92+
public Void call() throws Exception {
93+
String queue = channel.queueDeclare().getQueue();
94+
channel.queueBind(queue, protectedTopic, "x.y.z");
95+
channel.basicQos(0);
96+
channel.queueUnbind(queue, protectedTopic, "x.y.z");
97+
channel.basicQos(0);
98+
return null;
99+
}
100+
});
101+
assertAccessRefused("Binding/unbinding on protected exchange with none-matching routing key, should not pass", new Callable<Void>() {
102+
@Override
103+
public Void call() throws Exception {
104+
String queue = channel.queueDeclare().getQueue();
105+
channel.queueBind(queue, protectedTopic, "y.z");
106+
channel.basicQos(0);
107+
channel.queueUnbind(queue, protectedTopic, "y.z");
108+
channel.basicQos(0);
109+
return null;
110+
}
111+
});
112+
assertAccessOk("Binding/unbinding on not-protected exchange with none-matching routing key, should pass", new Callable<Void>() {
113+
@Override
114+
public Void call() throws Exception {
115+
String queue = channel.queueDeclare().getQueue();
116+
channel.queueBind(queue, notProtectedTopic, "y.z");
117+
channel.basicQos(0);
118+
channel.queueUnbind(queue, notProtectedTopic, "y.z");
119+
channel.basicQos(0);
120+
return null;
121+
}
122+
});
90123
}
91124

92125
void assertAccessOk(String description, Callable<Void> action) {

0 commit comments

Comments
 (0)