use of org.apache.qpid.server.store.MessageHandle in project qpid-broker-j by apache.
the class AMQChannelTest method testPublishContentHeaderWhenMessageAuthorizationFails.
public void testPublishContentHeaderWhenMessageAuthorizationFails() throws Exception {
final String impostorId = "impostor";
doThrow(new AccessControlException("fail")).when(_amqConnection).checkAuthorizedMessagePrincipal(eq(impostorId));
when(_virtualHost.getDefaultDestination()).thenReturn(mock(MessageDestination.class));
when(_virtualHost.getMessageStore()).thenReturn(new NullMessageStore() {
@Override
public <T extends StorableMessageMetaData> MessageHandle<T> addMessage(final T metaData) {
MessageHandle messageHandle = new StoredMemoryMessage(1, metaData);
return messageHandle;
}
});
int channelId = 1;
AMQChannel channel = new AMQChannel(_amqConnection, channelId, _virtualHost.getMessageStore());
BasicContentHeaderProperties properties = new BasicContentHeaderProperties();
properties.setUserId(impostorId);
channel.receiveBasicPublish(AMQShortString.EMPTY_STRING, AMQShortString.EMPTY_STRING, false, false);
channel.receiveMessageHeader(properties, 0);
verify(_amqConnection).sendConnectionClose(eq(ErrorCodes.ACCESS_REFUSED), anyString(), eq(channelId));
verifyZeroInteractions(_messageDestination);
}
use of org.apache.qpid.server.store.MessageHandle in project qpid-broker-j by apache.
the class AMQChannelTest method testPublishContentHeaderWhenMessageAuthorizationSucceeds.
public void testPublishContentHeaderWhenMessageAuthorizationSucceeds() throws Exception {
when(_virtualHost.getDefaultDestination()).thenReturn(_messageDestination);
when(_virtualHost.getMessageStore()).thenReturn(new NullMessageStore() {
@Override
public <T extends StorableMessageMetaData> MessageHandle<T> addMessage(final T metaData) {
MessageHandle messageHandle = new StoredMemoryMessage(1, metaData);
return messageHandle;
}
});
final ArgumentCaptor<ServerMessage> messageCaptor = ArgumentCaptor.forClass(ServerMessage.class);
doAnswer(new Answer() {
@Override
public Object answer(final InvocationOnMock invocation) throws Throwable {
ServerMessage message = messageCaptor.getValue();
return new RoutingResult(message);
}
}).when(_messageDestination).route(messageCaptor.capture(), eq(ROUTING_KEY.toString()), any(InstanceProperties.class));
AMQChannel channel = new AMQChannel(_amqConnection, 1, _virtualHost.getMessageStore());
BasicContentHeaderProperties properties = new BasicContentHeaderProperties();
properties.setUserId(_amqConnection.getAuthorizedPrincipal().getName());
channel.receiveBasicPublish(AMQShortString.EMPTY_STRING, ROUTING_KEY, false, false);
channel.receiveMessageHeader(properties, 0);
verify(_messageDestination).route((ServerMessage) any(), eq(ROUTING_KEY.toString()), any(InstanceProperties.class));
}
Aggregations