Skip to content

Commit 2f59c21

Browse files
author
Simon MacMullen
committed
Test the "impersonator" tag.
1 parent 3ee465b commit 2f59c21

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

test/src/com/rabbitmq/client/test/functional/UserIDHeader.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,41 @@
1818

1919
import com.rabbitmq.client.AMQP;
2020
import com.rabbitmq.client.test.BrokerTestCase;
21+
import com.rabbitmq.tools.Host;
2122

2223
import java.io.IOException;
2324

2425
public class UserIDHeader extends BrokerTestCase {
26+
private static final AMQP.BasicProperties GOOD = new AMQP.BasicProperties.Builder().userId("guest").build();
27+
private static final AMQP.BasicProperties BAD = new AMQP.BasicProperties.Builder().userId("not the guest, honest").build();
28+
2529
public void testValidUserId() throws IOException {
26-
AMQP.BasicProperties properties = new AMQP.BasicProperties.Builder().userId("guest").build();
27-
channel.basicPublish("amq.fanout", "", properties, "".getBytes());
30+
publish(GOOD);
2831
}
2932

3033
public void testInvalidUserId() {
31-
AMQP.BasicProperties properties = new AMQP.BasicProperties.Builder().userId("not the guest, honest").build();
3234
try {
33-
channel.basicPublish("amq.fanout", "", properties, "".getBytes());
34-
channel.queueDeclare(); // To flush the channel
35+
publish(BAD);
3536
fail("Accepted publish with incorrect user ID");
3637
} catch (IOException e) {
3738
checkShutdownSignal(AMQP.PRECONDITION_FAILED, e);
3839
}
3940
}
41+
42+
public void testImpersonatedUserId() throws IOException {
43+
Host.rabbitmqctl("set_user_tags guest administrator impersonator");
44+
connection = null;
45+
channel = null;
46+
setUp();
47+
try {
48+
publish(BAD);
49+
} finally {
50+
Host.rabbitmqctl("set_user_tags guest administrator");
51+
}
52+
}
53+
54+
private void publish(AMQP.BasicProperties properties) throws IOException {
55+
channel.basicPublish("amq.fanout", "", properties, "".getBytes());
56+
channel.queueDeclare(); // To flush the channel
57+
}
4058
}

0 commit comments

Comments
 (0)