Search in sources :

Example 1 with ConnectionStartBody

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

use of org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody 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 3 with ConnectionStartBody

use of org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody 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 4 with ConnectionStartBody

use of org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody in project qpid-broker-j by apache.

the class ConnectionTest method connectionSecure.

@Test
@SpecificationTest(section = "1.4.2.3", description = "security challenge data")
public void connectionSecure() 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(), getBrokerAdmin().getValidPassword()).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 ConnectionSecureBody secure = interaction.connection().startOkMechanism(PLAIN).startOk().consumeResponse().getLatestResponse(ConnectionSecureBody.class);
        assertThat(secure.getChallenge(), is(anyOf(nullValue(), equalTo(new byte[0]))));
        final ConnectionTuneBody tune = interaction.connection().secureOk(initialResponse).consumeResponse().getLatestResponse(ConnectionTuneBody.class);
        interaction.connection().tuneOkChannelMax(tune.getChannelMax()).tuneOkFrameMax(tune.getFrameMax()).tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class);
    }
}
Also used : 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 5 with ConnectionStartBody

use of org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody in project qpid-broker-j by apache.

the class AuthenticationTimeoutTest method authenticationTimeout.

@Test
public void authenticationTimeout() throws Exception {
    assumeThat(getBrokerAdmin().isSASLMechanismSupported("PLAIN"), 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("PLAIN"));
        interaction.connection().startOkMechanism("PLAIN").startOk().consumeResponse(ConnectionSecureBody.class);
        transport.assertNoMoreResponsesAndChannelClosed();
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v0_8.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v0_8.Interaction) ConnectionStartBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody) Test(org.junit.Test)

Aggregations

ConnectionStartBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody)6 Test (org.junit.Test)5 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)4 ConnectionSecureBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionSecureBody)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 ConnectionTuneBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody)2 ConnectionCloseBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionCloseBody)1 FrameTransport (org.apache.qpid.tests.protocol.v0_8.FrameTransport)1 Interaction (org.apache.qpid.tests.protocol.v0_8.Interaction)1