use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.
the class ConnectionTest method connectionSecureUnsuccessfulAuthentication.
@Test
@SpecificationTest(section = "1.4.2.3", description = "security challenge data")
public void connectionSecureUnsuccessfulAuthentication() throws Exception {
assumeThat(getBrokerAdmin().isSASLMechanismSupported(PLAIN), is(true));
try (FrameTransport transport = new FrameTransport(getBrokerAdmin(), BrokerAdmin.PortType.AMQP).connect()) {
final byte[] initialResponse = String.format("\0%s\0%s", getBrokerAdmin().getValidUsername(), "badpassword").getBytes(StandardCharsets.US_ASCII);
final Interaction interaction = transport.newInteraction();
final ConnectionStartBody start = interaction.negotiateProtocol().consumeResponse().getLatestResponse(ConnectionStartBody.class);
assertThat(Arrays.asList(new String(start.getMechanisms()).split(" ")), hasItem(PLAIN));
final ConnectionCloseBody close = interaction.connection().startOkMechanism(PLAIN).startOk().consumeResponse(ConnectionSecureBody.class).connection().secureOk(initialResponse).consumeResponse().getLatestResponse(ConnectionCloseBody.class);
assertThat(close.getReplyCode(), is(equalTo(ErrorCodes.NOT_ALLOWED)));
assertThat(String.valueOf(close.getReplyText()).toLowerCase(), containsString("authentication failed"));
}
}
use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.
the class ConnectionTest method overlySizedContentBodyFrame.
@Test
@SpecificationTest(section = "4.2.3", description = "A peer MUST NOT send frames larger than the agreed-upon size. A peer that receives an " + "oversized frame MUST signal a connection exception with reply code 501 (frame error).")
public void overlySizedContentBodyFrame() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
ConnectionTuneBody response = interaction.authenticateConnection().getLatestResponse(ConnectionTuneBody.class);
final long frameMax = response.getFrameMax();
// Older Qpid JMS Client 0-x had a defect that meant they could send content body frames that were too
// large. Rather then limiting the user content of each frame to frameSize - 8, it sent frameSize bytes
// of user content meaning the resultant frame was too big. The server accommodates this behaviour
// by reducing the frame-size advertised to the client.
// Should be frameMax - 8 + 1.
final int overlyLargeFrameBodySize = (int) (frameMax + 1);
final byte[] bodyBytes = new byte[overlyLargeFrameBodySize];
interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkFrameMax(frameMax).tuneOkHeartbeat(response.getHeartbeat()).tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class).channel().open().consumeResponse(ChannelOpenOkBody.class).basic().publish().basic().contentHeader(bodyBytes.length).basic().contentBody(bodyBytes);
// Server actually abruptly closes the connection. We might see a graceful TCP/IP close or a broken pipe.
try {
interaction.consumeResponse().getLatestResponse(ChannelClosedResponse.class);
} catch (ExecutionException e) {
Throwable original = e.getCause();
if (original instanceof IOException) {
// PASS
} else {
throw new RuntimeException(original);
}
}
}
}
use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.
the class ConnectionTest method connectionStart.
@Test
@SpecificationTest(section = "1.4.2.1", description = "start connection negotiation")
public void connectionStart() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
ConnectionStartBody response = interaction.negotiateProtocol().consumeResponse().getLatestResponse(ConnectionStartBody.class);
assertThat(response.getVersionMajor(), is(equalTo((short) transport.getProtocolVersion().getMajorVersion())));
assertThat(response.getVersionMinor(), is(equalTo((short) transport.getProtocolVersion().getActualMinorVersion())));
}
}
use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.
the class ExchangeTest method exchangeUnsupportedExchangeType.
@Test
@SpecificationTest(section = "1.6.2.1", description = "The client MUST NOT attempt to declare an exchange with a type that the server does not " + "support.")
public void exchangeUnsupportedExchangeType() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.negotiateOpen().channel().open().consumeResponse(ChannelOpenOkBody.class).exchange().declareType(ExchangeDefaults.DIRECT_EXCHANGE_CLASS).declareName(TEST_EXCHANGE).declare().consumeResponse(ExchangeDeclareOkBody.class);
ConnectionCloseBody response = interaction.exchange().declarePassive(true).declareType(ExchangeDefaults.TOPIC_EXCHANGE_CLASS).declareName(TEST_EXCHANGE).declare().consumeResponse().getLatestResponse(ConnectionCloseBody.class);
assertThat(response.getReplyCode(), is(equalTo(ErrorCodes.NOT_ALLOWED)));
}
}
use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.
the class ExchangeTest method exchangeDeclare.
@Test
@SpecificationTest(section = "1.6.2.1", description = "verify exchange exists, create if needed")
public void exchangeDeclare() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.negotiateOpen().channel().open().consumeResponse(ChannelOpenOkBody.class).exchange().declareName(TEST_EXCHANGE).declare().consumeResponse(ExchangeDeclareOkBody.class);
ExchangeBoundOkBody response = interaction.exchange().boundExchangeName(TEST_EXCHANGE).bound().consumeResponse().getLatestResponse(ExchangeBoundOkBody.class);
assertThat(response.getReplyCode(), is(equalTo(ExchangeBoundOkBody.NO_BINDINGS)));
}
}
Aggregations