use of org.apache.activemq.transport.amqp.client.AmqpClient in project activemq-artemis by apache.
the class AmqpSecurityTest method testSaslAuthWithInvalidCredentials.
@Test(timeout = 60000)
public void testSaslAuthWithInvalidCredentials() throws Exception {
AmqpConnection connection = null;
AmqpClient client = createAmqpClient(fullUser, guestUser);
try {
connection = client.connect();
fail("Should not authenticate when invalid credentials provided");
} catch (Exception ex) {
// Expected
} finally {
if (connection != null) {
connection.close();
}
}
}
use of org.apache.activemq.transport.amqp.client.AmqpClient in project activemq-artemis by apache.
the class AmqpSecurityTest method testSaslAuthWithoutAuthzid.
@Test(timeout = 60000)
public void testSaslAuthWithoutAuthzid() throws Exception {
AmqpConnection connection = null;
AmqpClient client = createAmqpClient(guestUser, guestPass);
try {
connection = client.connect();
} catch (Exception ex) {
fail("Should authenticate even with authzid set");
} finally {
if (connection != null) {
connection.close();
}
}
}
use of org.apache.activemq.transport.amqp.client.AmqpClient in project activemq-artemis by apache.
the class AmqpSecurityTest method testSendMessageFailsOnAnonymousRelayWhenNotAuthorizedToSendToAddress.
@Test(timeout = 60000)
public void testSendMessageFailsOnAnonymousRelayWhenNotAuthorizedToSendToAddress() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
AmqpClient client = createAmqpClient(guestUser, guestPass);
client.setValidator(new AmqpValidator() {
@Override
public void inspectDeliveryUpdate(Sender sender, Delivery delivery) {
DeliveryState state = delivery.getRemoteState();
if (!delivery.remotelySettled()) {
markAsInvalid("delivery is not remotely settled");
}
if (state instanceof Rejected) {
Rejected rejected = (Rejected) state;
if (rejected.getError() == null || rejected.getError().getCondition() == null) {
markAsInvalid("Delivery should have been Rejected with an error condition");
} else {
ErrorCondition error = rejected.getError();
if (!error.getCondition().equals(AmqpError.UNAUTHORIZED_ACCESS)) {
markAsInvalid("Should have been tagged with unauthorized access error");
}
}
} else {
markAsInvalid("Delivery should have been Rejected");
}
latch.countDown();
}
});
AmqpConnection connection = client.connect();
try {
AmqpSession session = connection.createSession();
AmqpSender sender = session.createAnonymousSender();
AmqpMessage message = new AmqpMessage();
message.setAddress(getQueueName());
message.setMessageId("msg" + 1);
message.setText("Test-Message");
try {
sender.send(message);
fail("Should not be able to send, message should be rejected");
} catch (Exception ex) {
ex.printStackTrace();
} finally {
sender.close();
}
assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
connection.getStateInspector().assertValid();
} finally {
connection.close();
}
}
use of org.apache.activemq.transport.amqp.client.AmqpClient in project activemq-artemis by apache.
the class AmqpSendReceiveTest method testCloseBusyReceiver.
@Test(timeout = 60000)
public void testCloseBusyReceiver() throws Exception {
final int MSG_COUNT = 20;
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
AmqpSender sender = session.createSender(getQueueName());
for (int i = 0; i < MSG_COUNT; i++) {
AmqpMessage message = new AmqpMessage();
message.setMessageId("msg" + i);
message.setMessageAnnotation("serialNo", i);
message.setText("Test-Message");
System.out.println("Sending message: " + message.getMessageId());
sender.send(message);
}
sender.close();
Queue queue = getProxyToQueue(getQueueName());
Wait.assertEquals(MSG_COUNT, queue::getMessageCount);
AmqpReceiver receiver1 = session.createReceiver(getQueueName());
receiver1.flow(MSG_COUNT);
AmqpMessage received = receiver1.receive(5, TimeUnit.SECONDS);
assertNotNull("Should have got a message", received);
assertEquals("msg0", received.getMessageId());
receiver1.close();
AmqpReceiver receiver2 = session.createReceiver(getQueueName());
receiver2.flow(200);
for (int i = 0; i < MSG_COUNT; ++i) {
received = receiver2.receive(5, TimeUnit.SECONDS);
assertNotNull("Should have got a message", received);
System.out.println("Read message: " + received.getMessageId());
assertEquals("msg" + i, received.getMessageId());
}
receiver2.close();
connection.close();
}
use of org.apache.activemq.transport.amqp.client.AmqpClient in project activemq-artemis by apache.
the class AmqpSendReceiveTest method testReceiveMessageAndRefillCreditBeforeAccept.
@Test(timeout = 60000)
public void testReceiveMessageAndRefillCreditBeforeAccept() throws Exception {
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
final String address = getQueueName();
AmqpReceiver receiver = session.createReceiver(address);
AmqpSender sender = session.createSender(address);
for (int i = 0; i < 2; i++) {
AmqpMessage message = new AmqpMessage();
message.setMessageId("msg" + i);
sender.send(message);
}
sender.close();
receiver.flow(1);
AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
assertNotNull(received);
receiver.flow(1);
received.accept();
received = receiver.receive(10, TimeUnit.SECONDS);
assertNotNull(received);
received.accept();
receiver.close();
connection.close();
}
Aggregations