|
18 | 18 |
|
19 | 19 | import com.rabbitmq.client.AMQP;
|
20 | 20 | import com.rabbitmq.client.test.BrokerTestCase;
|
| 21 | +import com.rabbitmq.tools.Host; |
21 | 22 |
|
22 | 23 | import java.io.IOException;
|
23 | 24 |
|
24 | 25 | 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 | + |
25 | 29 | 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); |
28 | 31 | }
|
29 | 32 |
|
30 | 33 | public void testInvalidUserId() {
|
31 |
| - AMQP.BasicProperties properties = new AMQP.BasicProperties.Builder().userId("not the guest, honest").build(); |
32 | 34 | try {
|
33 |
| - channel.basicPublish("amq.fanout", "", properties, "".getBytes()); |
34 |
| - channel.queueDeclare(); // To flush the channel |
| 35 | + publish(BAD); |
35 | 36 | fail("Accepted publish with incorrect user ID");
|
36 | 37 | } catch (IOException e) {
|
37 | 38 | checkShutdownSignal(AMQP.PRECONDITION_FAILED, e);
|
38 | 39 | }
|
39 | 40 | }
|
| 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 | + } |
40 | 58 | }
|
0 commit comments