Search in sources :

Example 1 with MessageHandle

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);
}
Also used : MessageHandle(org.apache.qpid.server.store.MessageHandle) MessageDestination(org.apache.qpid.server.message.MessageDestination) AccessControlException(java.security.AccessControlException) StoredMemoryMessage(org.apache.qpid.server.store.StoredMemoryMessage) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) Matchers.anyString(org.mockito.Matchers.anyString) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)

Example 2 with MessageHandle

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));
}
Also used : InstanceProperties(org.apache.qpid.server.message.InstanceProperties) ServerMessage(org.apache.qpid.server.message.ServerMessage) StoredMemoryMessage(org.apache.qpid.server.store.StoredMemoryMessage) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) RoutingResult(org.apache.qpid.server.message.RoutingResult) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) MessageHandle(org.apache.qpid.server.store.MessageHandle) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Aggregations

BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)2 MessageHandle (org.apache.qpid.server.store.MessageHandle)2 NullMessageStore (org.apache.qpid.server.store.NullMessageStore)2 StoredMemoryMessage (org.apache.qpid.server.store.StoredMemoryMessage)2 AccessControlException (java.security.AccessControlException)1 InstanceProperties (org.apache.qpid.server.message.InstanceProperties)1 MessageDestination (org.apache.qpid.server.message.MessageDestination)1 RoutingResult (org.apache.qpid.server.message.RoutingResult)1 ServerMessage (org.apache.qpid.server.message.ServerMessage)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1