Author: markt
Date: Wed Aug 19 22:10:50 2015
New Revision: 1696680
URL: http://svn.apache.org/r1696680
Log:
A couple more test cases for section 6.9
Test that window size is not allow to exceed 2^31 - 1
Modified:
tomcat/trunk/java/org/apache/coyote/http2/AbstractStream.java
tomcat/trunk/java/org/apache/coyote/http2/ConnectionSettingsRemote.java
tomcat/trunk/java/org/apache/coyote/http2/LocalStrings.properties
tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java
tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_6_9.java
Modified: tomcat/trunk/java/org/apache/coyote/http2/AbstractStream.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/AbstractStream.java?rev=1696680&r1=1696679&r2=1696680&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http2/AbstractStream.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http2/AbstractStream.java Wed Aug 19
22:10:50 2015
@@ -109,16 +109,26 @@ abstract class AbstractStream {
* @throws Http2Exception
*/
protected synchronized void incrementWindowSize(int increment) throws
Http2Exception {
- // Overflow protection
- if (Long.MAX_VALUE - increment < windowSize) {
- windowSize = Long.MAX_VALUE;
- } else {
- windowSize += increment;
- }
+ // No need for overflow protection here.
+ // Increment can't be more than Integer.MAX_VALUE and once windowSize
+ // goes beyond 2^31-1 an error is triggered.
+ windowSize += increment;
+
if (log.isDebugEnabled()) {
log.debug(sm.getString("abstractStream.windowSizeInc",
getConnectionId(),
getIdentifier(), Integer.toString(increment),
Long.toString(windowSize)));
}
+
+ if (windowSize > ConnectionSettingsRemote.MAX_WINDOW_SIZE) {
+ String msg = sm.getString("abstractStream.windowSizeTooBig",
getConnectionId(), identifier,
+ Integer.toString(increment), Long.toString(windowSize));
+ if (identifier.intValue() == 0) {
+ throw new ConnectionException(msg,
Http2Error.FLOW_CONTROL_ERROR);
+ } else {
+ throw new StreamException(
+ msg, Http2Error.FLOW_CONTROL_ERROR,
identifier.intValue());
+ }
+ }
}
Modified:
tomcat/trunk/java/org/apache/coyote/http2/ConnectionSettingsRemote.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/ConnectionSettingsRemote.java?rev=1696680&r1=1696679&r2=1696680&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http2/ConnectionSettingsRemote.java
(original)
+++ tomcat/trunk/java/org/apache/coyote/http2/ConnectionSettingsRemote.java Wed
Aug 19 22:10:50 2015
@@ -31,7 +31,7 @@ public class ConnectionSettingsRemote {
public static final int DEFAULT_INITIAL_WINDOW_SIZE = (1 << 16) - 1;
static final long UNLIMITED = ((long)1 << 32); // Use the maximum possible
- private static final int MAX_WINDOW_SIZE = (1 << 31) - 1;
+ static final int MAX_WINDOW_SIZE = (1 << 31) - 1;
private static final int MIN_MAX_FRAME_SIZE = 1 << 14;
private static final int MAX_MAX_FRAME_SIZE = (1 << 24) - 1;
Modified: tomcat/trunk/java/org/apache/coyote/http2/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/LocalStrings.properties?rev=1696680&r1=1696679&r2=1696680&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http2/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/coyote/http2/LocalStrings.properties Wed Aug
19 22:10:50 2015
@@ -15,6 +15,7 @@
abstractStream.windowSizeDec=Connection [{0}], Stream [{1}], reduce flow
control window by [{2}] to [{3}]
abstractStream.windowSizeInc=Connection [{0}], Stream [{1}], increase flow
control window by [{2}] to [{3}]
+abstractStream.windowSizeTooBig=Connection [{0}], Stream [{1}], increase in
window size of [{2}] to [{3}] exceeded permitted maximum
connectionPrefaceParser.eos=Unexpected end of stream while reading opening
client preface byte sequence. Only [{0}] bytes read.
connectionPrefaceParser.ioError=Failed to read opening client preface byte
sequence
Modified: tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java?rev=1696680&r1=1696679&r2=1696680&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java (original)
+++ tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java Wed Aug 19
22:10:50 2015
@@ -226,6 +226,12 @@ public abstract class Http2TestBase exte
protected void sendSimplePostRequest(int streamId, byte[] padding) throws
IOException {
+ sendSimplePostRequest(streamId, padding, true);
+ }
+
+
+ protected void sendSimplePostRequest(int streamId, byte[] padding, boolean
writeBody)
+ throws IOException {
byte[] headersFrameHeader = new byte[9];
ByteBuffer headersPayload = ByteBuffer.allocate(128);
byte[] dataFrameHeader = new byte[9];
@@ -234,7 +240,9 @@ public abstract class Http2TestBase exte
buildPostRequest(headersFrameHeader, headersPayload,
dataFrameHeader, dataPayload, padding, streamId);
writeFrame(headersFrameHeader, headersPayload);
- writeFrame(dataFrameHeader, dataPayload);
+ if (writeBody) {
+ writeFrame(dataFrameHeader, dataPayload);
+ }
}
Modified: tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_6_9.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_6_9.java?rev=1696680&r1=1696679&r2=1696680&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_6_9.java
(original)
+++ tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_6_9.java Wed Aug
19 22:10:50 2015
@@ -45,8 +45,7 @@ public class TestHttp2Section_6_9 extend
public void testZeroWindowUpdateStream() throws Exception {
http2Connect();
- sendPriority(3, 0, 15);
-
+ sendSimplePostRequest(3, null, false);
sendWindowUpdate(3, 0);
parser.readFrame(true);
@@ -125,5 +124,36 @@ public class TestHttp2Section_6_9 extend
}
+ @Test
+ public void testWindowSizeTooLargeStream() throws Exception {
+ http2Connect();
+
+ // Set up stream 3
+ sendSimplePostRequest(3, null, false);
+
+ // Super size the flow control window.
+ sendWindowUpdate(3, (1 << 31) - 1);
+
+ parser.readFrame(true);
+
+ Assert.assertEquals("3-RST-[" +
Http2Error.FLOW_CONTROL_ERROR.getCode() + "]",
+ output.getTrace());
+ }
+
+
+ @Test
+ public void testWindowSizeTooLargeConnection() throws Exception {
+ http2Connect();
+
+ // Super size the flow control window.
+ sendWindowUpdate(0, (1 << 31) - 1);
+
+ parser.readFrame(true);
+
+ Assert.assertTrue(output.getTrace(), output.getTrace().startsWith(
+ "0-Goaway-[1]-[" + Http2Error.FLOW_CONTROL_ERROR.getCode() +
"]-["));
+ }
+
+
// TODO: Remaining 6.9 tests
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]