use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.
the class ConnectionTest method connectionSecureWithChallengeResponse.
@Test
@SpecificationTest(section = "1.4.2.3", description = "security challenge data")
public void connectionSecureWithChallengeResponse() throws Exception {
assumeThat(getBrokerAdmin().isSASLMechanismSupported(CRAM_MD5), is(true));
try (FrameTransport transport = new FrameTransport(getBrokerAdmin(), BrokerAdmin.PortType.AMQP).connect()) {
final Interaction interaction = transport.newInteraction();
final ConnectionStartBody start = interaction.negotiateProtocol().consumeResponse().getLatestResponse(ConnectionStartBody.class);
assertThat(Arrays.asList(new String(start.getMechanisms()).split(" ")), hasItem(CRAM_MD5));
final ConnectionSecureBody secure = interaction.connection().startOkMechanism(CRAM_MD5).startOk().consumeResponse().getLatestResponse(ConnectionSecureBody.class);
byte[] response = generateCramMD5ClientResponse(getBrokerAdmin().getValidUsername(), getBrokerAdmin().getValidPassword(), secure.getChallenge());
final ConnectionTuneBody tune = interaction.connection().secureOk(response).consumeResponse().getLatestResponse(ConnectionTuneBody.class);
interaction.connection().tuneOkChannelMax(tune.getChannelMax()).tuneOkFrameMax(tune.getFrameMax()).tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class);
}
}
use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.
the class LargeHeadersTest method headersFillContentHeaderFrame.
@Test
public /**
* Tests boundary case where headers exactly fill the content header frame
*/
void headersFillContentHeaderFrame() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
String consumerTag = "A";
ConnectionTuneBody connTune = interaction.authenticateConnection().getLatestResponse(ConnectionTuneBody.class);
final String headerName = "test";
final int headerValueSize = (int) (connTune.getFrameMax() - calculateContentHeaderFramingOverhead(headerName));
final String headerValue = generateLongString(headerValueSize);
final Map<String, Object> messageHeaders = Collections.singletonMap(headerName, headerValue);
interaction.connection().tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class).channel().open().consumeResponse(ChannelOpenOkBody.class).basic().qosPrefetchCount(1).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(BrokerAdmin.TEST_QUEUE_NAME).consumeNoAck(true).consume().consumeResponse(BasicConsumeOkBody.class).channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().contentHeaderPropertiesHeaders(messageHeaders).publishExchange("").publishRoutingKey(BrokerAdmin.TEST_QUEUE_NAME).publishMessage().consumeResponse(BasicDeliverBody.class);
BasicDeliverBody delivery = interaction.getLatestResponse(BasicDeliverBody.class);
assertThat(delivery.getConsumerTag(), is(equalTo(AMQShortString.valueOf(consumerTag))));
ContentHeaderBody header = interaction.consumeResponse(ContentHeaderBody.class).getLatestResponse(ContentHeaderBody.class);
assertThat(header.getBodySize(), is(equalTo(0L)));
BasicContentHeaderProperties properties = header.getProperties();
Map<String, Object> receivedHeaders = new HashMap<>(properties.getHeadersAsMap());
assertThat(receivedHeaders, is(equalTo(new HashMap<>(messageHeaders))));
}
}
use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.
the class MalformedMessageTest method consumeMalformedMessage.
@Test
public void consumeMalformedMessage() throws Exception {
final FieldTable malformedHeader = createHeadersWithMalformedLongString();
final byte[] contentBytes = CONTENT_TEXT.getBytes(StandardCharsets.UTF_8);
final String content2 = "message2";
final byte[] content2Bytes = content2.getBytes(StandardCharsets.UTF_8);
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
String consumerTag = "A";
interaction.negotiateOpen().channel().open().consumeResponse(ChannelOpenOkBody.class).basic().qosPrefetchCount(1).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(BrokerAdmin.TEST_QUEUE_NAME).consume().consumeResponse(BasicConsumeOkBody.class).channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().publishExchange("").publishRoutingKey(BrokerAdmin.TEST_QUEUE_NAME).contentHeaderPropertiesHeaders(malformedHeader).content(contentBytes).publishMessage().basic().publishExchange("").publishRoutingKey(BrokerAdmin.TEST_QUEUE_NAME).contentHeaderPropertiesContentType("text/plain").contentHeaderPropertiesHeaders(Collections.emptyMap()).content(content2Bytes).publishMessage();
BasicDeliverBody delivery = interaction.consumeResponse(BasicDeliverBody.class).getLatestResponse(BasicDeliverBody.class);
assertThat(delivery.getConsumerTag(), is(equalTo(AMQShortString.valueOf(consumerTag))));
assertThat(delivery.getConsumerTag(), is(notNullValue()));
assertThat(delivery.getRedelivered(), is(equalTo(false)));
assertThat(delivery.getExchange(), is(nullValue()));
assertThat(delivery.getRoutingKey(), is(equalTo(AMQShortString.valueOf(BrokerAdmin.TEST_QUEUE_NAME))));
ContentHeaderBody header = interaction.consumeResponse(ContentHeaderBody.class).getLatestResponse(ContentHeaderBody.class);
assertThat(header.getBodySize(), is(equalTo((long) content2Bytes.length)));
BasicContentHeaderProperties properties = header.getProperties();
Map<String, Object> receivedHeaders = new HashMap<>(properties.getHeadersAsMap());
assertThat(receivedHeaders.isEmpty(), is(equalTo(true)));
String receivedContent = interaction.consumeResponse(ContentBody.class).getLatestResponseContentBodyAsString();
assertThat(receivedContent, is(equalTo(content2)));
interaction.channel().close().consumeResponse(ChannelCloseOkBody.class, ChannelFlowOkBody.class);
}
}
use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.
the class MalformedMessageTest method publishMalformedMessageInTransactionExceedingMaxUncommittedLimit.
@Test
public void publishMalformedMessageInTransactionExceedingMaxUncommittedLimit() throws Exception {
assumeThat("Persistent store is required for the test", getBrokerAdmin().supportsRestart(), is(equalTo(true)));
final FieldTable malformedHeader = createMalformedHeadersWithMissingValue("prop");
final BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
basicContentHeaderProperties.setHeaders(malformedHeader);
basicContentHeaderProperties.setContentType("text/plain");
basicContentHeaderProperties.setDeliveryMode(BasicContentHeaderProperties.PERSISTENT);
byte[] contentBytes = CONTENT_TEXT.getBytes(StandardCharsets.UTF_8);
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.negotiateOpen().channel().open().consumeResponse(ChannelOpenOkBody.class).tx().select().consumeResponse(TxSelectOkBody.class).basic().publishExchange("").publishRoutingKey(BrokerAdmin.TEST_QUEUE_NAME).contentHeaderPropertiesHeaders(malformedHeader).content(contentBytes).publishMessage().tx().commit().consumeResponse().getLatestResponse(ChannelClosedResponse.class);
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
}
}
use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.
the class QueueTest method queueUnbindWithoutRoutingKey.
@Test
@SpecificationTest(section = "1.7.2.5", description = "unbind a queue from an exchange")
public void queueUnbindWithoutRoutingKey() throws Exception {
getBrokerAdmin().createQueue(BrokerAdmin.TEST_QUEUE_NAME);
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
String testExchange = "testExchange";
interaction.negotiateOpen().channel().open().consumeResponse(ChannelOpenOkBody.class).exchange().declareName(testExchange).declare().consumeResponse(ExchangeDeclareOkBody.class).queue().bindName(testExchange).bindQueueName(BrokerAdmin.TEST_QUEUE_NAME).bind().consumeResponse(QueueBindOkBody.class).queue().unbindName(testExchange).unbindQueueName(BrokerAdmin.TEST_QUEUE_NAME).unbind().consumeResponse(QueueUnbindOkBody.class);
}
}
Aggregations