Search in sources :

Example 11 with AmqpValidator

use of org.apache.activemq.transport.amqp.client.AmqpValidator in project activemq-artemis by apache.

the class AmqpSecurityTest method testSendAndRejected.

@Test(timeout = 60000)
public void testSendAndRejected() throws Exception {
    AmqpClient client = createAmqpClient(guestUser, guestPass);
    client.setValidator(new AmqpValidator() {

        @Override
        public void inspectOpenedResource(Sender sender) {
            ErrorCondition condition = sender.getRemoteCondition();
            if (condition != null && condition.getCondition() != null) {
                if (!condition.getCondition().equals(AmqpError.UNAUTHORIZED_ACCESS)) {
                    markAsInvalid("Should have been tagged with unauthorized access error");
                }
            } else {
                markAsInvalid("Sender should have been opened with an error");
            }
        }
    });
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    try {
        try {
            session.createSender(getQueueName());
            fail("Should not be able to consume here.");
        } catch (Exception ex) {
            IntegrationTestLogger.LOGGER.info("Caught expected exception");
        }
        connection.getStateInspector().assertValid();
    } finally {
        connection.close();
    }
}
Also used : AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Sender(org.apache.qpid.proton.engine.Sender) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Test(org.junit.Test)

Example 12 with AmqpValidator

use of org.apache.activemq.transport.amqp.client.AmqpValidator in project activemq-artemis by apache.

the class AmqpSecurityTest method testConsumerNotAuthorizedToCreateQueues.

@Test(timeout = 30000)
public void testConsumerNotAuthorizedToCreateQueues() throws Exception {
    AmqpClient client = createAmqpClient(noprivUser, noprivPass);
    client.setValidator(new AmqpValidator() {

        @Override
        public void inspectOpenedResource(Sender sender) {
            ErrorCondition condition = sender.getRemoteCondition();
            if (condition != null && condition.getCondition() != null) {
                if (!condition.getCondition().equals(AmqpError.UNAUTHORIZED_ACCESS)) {
                    markAsInvalid("Should have been tagged with unauthorized access error");
                }
            } else {
                markAsInvalid("Sender should have been opened with an error");
            }
        }
    });
    AmqpConnection connection = client.connect();
    try {
        AmqpSession session = connection.createSession();
        try {
            session.createReceiver(getQueueName(getPrecreatedQueueSize() + 1));
            fail("Should not be able to consume here.");
        } catch (Exception ex) {
            IntegrationTestLogger.LOGGER.info("Caught expected exception");
        }
        connection.getStateInspector().assertValid();
    } finally {
        connection.close();
    }
}
Also used : AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Sender(org.apache.qpid.proton.engine.Sender) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Test(org.junit.Test)

Example 13 with AmqpValidator

use of org.apache.activemq.transport.amqp.client.AmqpValidator in project activemq-artemis by apache.

the class AmqpSecurityTest method testReceiverNotAuthorized.

@Test(timeout = 30000)
public void testReceiverNotAuthorized() throws Exception {
    AmqpClient client = createAmqpClient(noprivUser, noprivPass);
    client.setValidator(new AmqpValidator() {

        @Override
        public void inspectOpenedResource(Receiver receiver) {
            ErrorCondition condition = receiver.getRemoteCondition();
            if (condition != null && condition.getCondition() != null) {
                if (!condition.getCondition().equals(AmqpError.UNAUTHORIZED_ACCESS)) {
                    markAsInvalid("Should have been tagged with unauthorized access error");
                }
            } else {
                markAsInvalid("Receiver should have been opened with an error");
            }
        }
    });
    AmqpConnection connection = client.connect();
    try {
        AmqpSession session = connection.createSession();
        try {
            session.createReceiver(getQueueName());
            fail("Should not be able to consume here.");
        } catch (Exception ex) {
            IntegrationTestLogger.LOGGER.info("Caught expected exception");
        }
        connection.getStateInspector().assertValid();
    } finally {
        connection.close();
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Receiver(org.apache.qpid.proton.engine.Receiver) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Test(org.junit.Test)

Example 14 with AmqpValidator

use of org.apache.activemq.transport.amqp.client.AmqpValidator in project activemq-artemis by apache.

the class AmqpSenderTest method testUnsettledSender.

@Test(timeout = 60000)
public void testUnsettledSender() throws Exception {
    final int MSG_COUNT = 1000;
    final CountDownLatch settled = new CountDownLatch(MSG_COUNT);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    connection.setStateInspector(new AmqpValidator() {

        @Override
        public void inspectDeliveryUpdate(Sender sender, Delivery delivery) {
            if (delivery.remotelySettled()) {
                IntegrationTestLogger.LOGGER.trace("Remote settled message for sender: " + sender.getName());
                settled.countDown();
            }
        }
    });
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName(), false);
    for (int i = 1; i <= MSG_COUNT; ++i) {
        AmqpMessage message = new AmqpMessage();
        message.setText("Test-Message: " + i);
        sender.send(message);
        if (i % 1000 == 0) {
            IntegrationTestLogger.LOGGER.info("Sent message: " + i);
        }
    }
    Queue queueView = getProxyToQueue(getQueueName());
    Wait.assertTrue("All messages should arrive", () -> queueView.getMessageCount() == MSG_COUNT);
    sender.close();
    assertTrue("Remote should have settled all deliveries", settled.await(5, TimeUnit.MINUTES));
    connection.close();
}
Also used : AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Sender(org.apache.qpid.proton.engine.Sender) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Delivery(org.apache.qpid.proton.engine.Delivery) CountDownLatch(java.util.concurrent.CountDownLatch) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Queue(org.apache.activemq.artemis.core.server.Queue) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Test(org.junit.Test)

Example 15 with AmqpValidator

use of org.apache.activemq.transport.amqp.client.AmqpValidator in project activemq-artemis by apache.

the class AmqpSessionTest method testSessionClosedDoesNotGetReceiverDetachFromRemote.

@Test(timeout = 60000)
public void testSessionClosedDoesNotGetReceiverDetachFromRemote() throws Exception {
    AmqpClient client = createAmqpClient();
    assertNotNull(client);
    client.setValidator(new AmqpValidator() {

        @Override
        public void inspectClosedResource(Session session) {
            IntegrationTestLogger.LOGGER.info("Session closed: " + session.getContext());
        }

        @Override
        public void inspectDetachedResource(Receiver receiver) {
            markAsInvalid("Broker should not detach receiver linked to closed session.");
        }

        @Override
        public void inspectClosedResource(Receiver receiver) {
            markAsInvalid("Broker should not close receiver linked to closed session.");
        }
    });
    AmqpConnection connection = addConnection(client.connect());
    assertNotNull(connection);
    AmqpSession session = connection.createSession();
    assertNotNull(session);
    AmqpReceiver receiver = session.createReceiver(getQueueName());
    assertNotNull(receiver);
    session.close();
    connection.getStateInspector().assertValid();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Receiver(org.apache.qpid.proton.engine.Receiver) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Session(org.apache.qpid.proton.engine.Session) Test(org.junit.Test)

Aggregations

AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)21 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)21 AmqpValidator (org.apache.activemq.transport.amqp.client.AmqpValidator)21 Test (org.junit.Test)21 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)15 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)8 Receiver (org.apache.qpid.proton.engine.Receiver)8 Map (java.util.Map)7 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)7 Sender (org.apache.qpid.proton.engine.Sender)7 Connection (org.apache.qpid.proton.engine.Connection)6 HashMap (java.util.HashMap)5 Source (org.apache.qpid.proton.amqp.messaging.Source)5 ErrorCondition (org.apache.qpid.proton.amqp.transport.ErrorCondition)5 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)4 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)4 Delivery (org.apache.qpid.proton.engine.Delivery)4 Symbol (org.apache.qpid.proton.amqp.Symbol)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 DescribedType (org.apache.qpid.proton.amqp.DescribedType)2