use of org.apache.qpid.tests.protocol.SpecificationTest 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(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
ConnectionTuneBody response = interaction.negotiateProtocol().consumeResponse(ConnectionStartBody.class).connection().startOkMechanism(ANONYMOUS).startOk().consumeResponse().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 {
final ChannelClosedResponse closeResponse = 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.tests.protocol.SpecificationTest in project qpid-broker-j by apache.
the class ConnectionTest method connectionTuneOkAndOpen.
@Test
@SpecificationTest(section = "1.4.2.6", description = "negotiate connection tuning parameters")
public void connectionTuneOkAndOpen() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
ConnectionTuneBody response = interaction.negotiateProtocol().consumeResponse(ConnectionStartBody.class).connection().startOkMechanism(ANONYMOUS).startOk().consumeResponse().getLatestResponse(ConnectionTuneBody.class);
interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkFrameMax(response.getFrameMax()).tuneOkHeartbeat(response.getHeartbeat()).tuneOk().connection().open().consumeResponse().getLatestResponse(ConnectionOpenOkBody.class);
}
}
use of org.apache.qpid.tests.protocol.SpecificationTest 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));
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.AMQP);
try (FrameTransport transport = new FrameTransport(addr).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.tests.protocol.SpecificationTest 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));
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.AMQP);
try (FrameTransport transport = new FrameTransport(addr).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.tests.protocol.SpecificationTest in project qpid-broker-j by apache.
the class ConnectionTest method authenticationBypassBySendingTuneOk.
@Test
@SpecificationTest(section = "1.4.", description = "open connection = C:protocolheader S:START C:START OK" + " *challenge S:TUNE C:TUNE OK C:OPEN S:OPEN OK")
public void authenticationBypassBySendingTuneOk() throws Exception {
final InetSocketAddress brokerAddress = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.AMQP);
try (FrameTransport transport = new FrameTransport(brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.negotiateProtocol().consumeResponse(ConnectionStartBody.class).connection().tuneOk().consumeResponse().getLatestResponse(ConnectionCloseBody.class);
}
}
Aggregations