Search in sources :

Example 36 with SpecificationTest

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);
            }
        }
    }
}
Also used : ConnectionStartBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody) IOException(java.io.IOException) ChannelClosedResponse(org.apache.qpid.tests.protocol.ChannelClosedResponse) ConnectionOpenOkBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionOpenOkBody) ConnectionTuneBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 37 with SpecificationTest

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);
    }
}
Also used : ConnectionTuneBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody) ConnectionStartBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 38 with SpecificationTest

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"));
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ConnectionCloseBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionCloseBody) ConnectionStartBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 39 with SpecificationTest

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);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ConnectionStartBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody) ConnectionTuneBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody) Matchers.containsString(org.hamcrest.Matchers.containsString) ConnectionSecureBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionSecureBody) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 40 with SpecificationTest

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);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)209 Test (org.junit.Test)209 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)106 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)82 InetSocketAddress (java.net.InetSocketAddress)52 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)52 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)45 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)37 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)35 ChannelOpenOkBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody)29 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)28 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)28 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)26 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)22 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)19 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)16 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)15 ChannelCloseBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelCloseBody)14 ConnectionStartBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody)14 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)14