ARTEMIS-547 tests for auth on attach

This commit is contained in:
Timothy Bish 2017-04-28 12:19:25 -04:00 committed by Justin Bertram
parent 27fce00468
commit 90efd86133
2 changed files with 11 additions and 34 deletions

View File

@ -16,7 +16,6 @@
*/ */
package org.apache.activemq.artemis.tests.integration.amqp; package org.apache.activemq.artemis.tests.integration.amqp;
import java.io.IOException;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -95,34 +94,20 @@ public class AmqpSecurityTest extends AmqpClientTestSupport {
@Test(timeout = 60000) @Test(timeout = 60000)
public void testSendAndRejected() throws Exception { public void testSendAndRejected() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
AmqpClient client = createAmqpClient(guestUser, guestPass); AmqpClient client = createAmqpClient(guestUser, guestPass);
client.setValidator(new AmqpValidator() { client.setValidator(new AmqpValidator() {
@Override @Override
public void inspectDeliveryUpdate(Sender sender, Delivery delivery) { public void inspectOpenedResource(Sender sender) {
DeliveryState state = delivery.getRemoteState(); ErrorCondition condition = sender.getRemoteCondition();
if (!delivery.remotelySettled()) { if (condition != null && condition.getCondition() != null) {
markAsInvalid("delivery is not remotely settled"); if (!condition.getCondition().equals(AmqpError.UNAUTHORIZED_ACCESS)) {
}
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"); markAsInvalid("Should have been tagged with unauthorized access error");
} }
}
} else { } else {
markAsInvalid("Delivery should have been Rejected"); markAsInvalid("Sender should have been opened with an error");
} }
latch.countDown();
} }
}); });
@ -130,19 +115,13 @@ public class AmqpSecurityTest extends AmqpClientTestSupport {
AmqpSession session = connection.createSession(); AmqpSession session = connection.createSession();
try { try {
AmqpSender sender = session.createSender(getQueueName());
AmqpMessage message = new AmqpMessage();
message.setMessageId("msg" + 1);
message.setMessageAnnotation("serialNo", 1);
message.setText("Test-Message");
try { try {
sender.send(message); session.createSender(getQueueName());
} catch (IOException e) { fail("Should not be able to consume here.");
} catch (Exception ex) {
IntegrationTestLogger.LOGGER.info("Caught expected exception");
} }
assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
connection.getStateInspector().assertValid(); connection.getStateInspector().assertValid();
} finally { } finally {
connection.close(); connection.close();

View File

@ -193,9 +193,7 @@ public class JMSConnectionWithSecurityTest extends JMSClientTestSupport {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = session.createQueue(getQueueName()); javax.jms.Queue queue = session.createQueue(getQueueName());
try { try {
// TODO - This seems a bit odd, can attach but not send session.createProducer(queue);
MessageProducer producer = session.createProducer(queue);
producer.send(session.createMessage());
fail("Should not be able to produce here."); fail("Should not be able to produce here.");
} catch (JMSSecurityException jmsSE) { } catch (JMSSecurityException jmsSE) {
IntegrationTestLogger.LOGGER.info("Caught expected exception"); IntegrationTestLogger.LOGGER.info("Caught expected exception");