Search in sources :

Example 6 with org.apache.qpid.server.protocol.v0_8.transport

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"));
    }
}
Also used : 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 7 with org.apache.qpid.server.protocol.v0_8.transport

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

Example 8 with org.apache.qpid.server.protocol.v0_8.transport

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())));
    }
}
Also used : 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 9 with org.apache.qpid.server.protocol.v0_8.transport

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

Example 10 with org.apache.qpid.server.protocol.v0_8.transport

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

Aggregations

Test (org.junit.Test)88 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)72 ChannelOpenOkBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody)44 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)32 Interaction (org.apache.qpid.tests.protocol.v0_8.Interaction)21 FrameTransport (org.apache.qpid.tests.protocol.v0_8.FrameTransport)20 Matchers.emptyString (org.hamcrest.Matchers.emptyString)18 ChannelCloseBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelCloseBody)17 QueueDeclareOkBody (org.apache.qpid.server.protocol.v0_8.transport.QueueDeclareOkBody)15 ConnectionCloseBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionCloseBody)13 ConnectionTuneBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody)12 ExchangeBoundOkBody (org.apache.qpid.server.protocol.v0_8.transport.ExchangeBoundOkBody)11 ExchangeDeclareOkBody (org.apache.qpid.server.protocol.v0_8.transport.ExchangeDeclareOkBody)11 ContentBody (org.apache.qpid.server.protocol.v0_8.transport.ContentBody)9 BasicConsumeOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody)8 BasicDeliverBody (org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody)8 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)8 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)7 ConnectionStartBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody)7 BasicQosOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicQosOkBody)6