Skip to content

Commit

Permalink
QPID-8648: [Broker-J] Allow for max frame size >4096 before Open fram…
Browse files Browse the repository at this point in the history
…e (SASL)
  • Loading branch information
dakirily committed Jan 24, 2024
1 parent 40c2d09 commit e512b4a
Show file tree
Hide file tree
Showing 7 changed files with 553 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public class AMQPConnection_1_0Impl extends AbstractAMQPConnection<AMQPConnectio
private final SubjectCreator _subjectCreator;

private int _channelMax = 0;
private int _maxFrameSize = 4096;
private int _maxFrameSize;
private String _remoteContainerId;

private SocketAddress _remoteAddress;
Expand Down Expand Up @@ -262,6 +262,8 @@ public class AMQPConnection_1_0Impl extends AbstractAMQPConnection<AMQPConnectio
_incomingIdleTimeout = 1000L * port.getHeartbeatDelay();

_frameWriter = new FrameWriter(getDescribedTypeRegistry(), getSender());

_maxFrameSize = getBroker().getNetworkBufferSize();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@
import org.apache.qpid.tests.protocol.SpecificationTest;
import org.apache.qpid.tests.protocol.v1_0.FrameTransport;
import org.apache.qpid.tests.protocol.v1_0.Interaction;
import org.apache.qpid.tests.utils.AddOAuth2MockProvider;
import org.apache.qpid.tests.utils.BrokerAdmin;
import org.apache.qpid.tests.utils.BrokerAdminUsingTestBase;

public class SaslTest extends BrokerAdminUsingTestBase
{
private static final Symbol CRAM_MD5 = Symbol.getSymbol("CRAM-MD5");
private static final Symbol PLAIN = Symbol.getSymbol("PLAIN");
private static final Symbol OAUTH2 = Symbol.getSymbol("XOAUTH2");

private static final byte[] SASL_AMQP_HEADER_BYTES = "AMQP\3\1\0\0".getBytes(StandardCharsets.UTF_8);
private static final byte[] AMQP_HEADER_BYTES = "AMQP\0\1\0\0".getBytes(StandardCharsets.UTF_8);
Expand Down Expand Up @@ -329,4 +331,39 @@ public void emptyFramesDisallowed() throws Exception
transport.assertNoMoreResponsesAndChannelClosed();
}
}

@Test
@AddOAuth2MockProvider()
@SpecificationTest(section = "5.3.2", description = "SASL Negotiation")
public void veryLongOauth2Token() throws Exception
{
final byte[] TOKEN = ("user=xxx\1auth=Bearer " + "A".repeat(10_0000) + "\1host=localhost\1\1")
.getBytes(StandardCharsets.US_ASCII);

try (final FrameTransport transport = new FrameTransport(getBrokerAdmin(), BrokerAdmin.PortType.AMQP).connect())
{
final Interaction interaction = transport.newInteraction();
final byte[] saslHeaderResponse = interaction.protocolHeader(SASL_AMQP_HEADER_BYTES)
.negotiateProtocol().consumeResponse()
.getLatestResponse(byte[].class);
assertThat(saslHeaderResponse, is(equalTo(SASL_AMQP_HEADER_BYTES)));

final SaslMechanisms saslMechanismsResponse = interaction.consumeResponse().getLatestResponse(SaslMechanisms.class);
assumeTrue(hasItem(OAUTH2).matches(Arrays.asList(saslMechanismsResponse.getSaslServerMechanisms())));

final Binary initialResponse = new Binary(TOKEN);
final SaslOutcome saslOutcome = interaction.saslMechanism(OAUTH2)
.saslInitialResponse(initialResponse)
.saslInit().consumeResponse()
.getLatestResponse(SaslOutcome.class);
assertThat(saslOutcome.getCode(), equalTo(SaslCode.OK));

final byte[] headerResponse = interaction.protocolHeader(AMQP_HEADER_BYTES)
.negotiateProtocol().consumeResponse()
.getLatestResponse(byte[].class);
assertThat(headerResponse, is(equalTo(AMQP_HEADER_BYTES)));

transport.assertNoMoreResponses();
}
}
}
4 changes: 4 additions & 0 deletions systests/systests-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.qpid.tests.utils;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface AddOAuth2MockProvider
{
}
Loading

0 comments on commit e512b4a

Please sign in to comment.