You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2015/06/03 15:56:45 UTC
svn commit: r1683337 - in /tomcat/trunk:
java/org/apache/coyote/http2/ConnectionSettings.java
test/org/apache/coyote/http2/Http2TestBase.java
test/org/apache/coyote/http2/TestHttp2Section_4_1.java
Author: markt
Date: Wed Jun 3 13:56:45 2015
New Revision: 1683337
URL: http://svn.apache.org/r1683337
Log:
Add a test for ignoring unknown frame types
Added:
tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_4_1.java (with props)
Modified:
tomcat/trunk/java/org/apache/coyote/http2/ConnectionSettings.java
tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java
Modified: tomcat/trunk/java/org/apache/coyote/http2/ConnectionSettings.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/ConnectionSettings.java?rev=1683337&r1=1683336&r2=1683337&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http2/ConnectionSettings.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http2/ConnectionSettings.java Wed Jun 3 13:56:45 2015
@@ -35,7 +35,9 @@ public class ConnectionSettings {
private static final int MAX_MAX_FRAME_SIZE = (1 << 24) - 1;
static final int DEFAULT_MAX_FRAME_SIZE = MIN_MAX_FRAME_SIZE;
- private volatile int headerTableSize = 4096;
+ static final int DEFAULT_HEADER_TABLE_SIZE = 4096;
+ private volatile int headerTableSize = DEFAULT_HEADER_TABLE_SIZE;
+
private volatile boolean enablePush = true;
private volatile long maxConcurrentStreams = UNLIMITED;
private volatile int initialWindowSize = DEFAULT_WINDOW_SIZE;
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=1683337&r1=1683336&r2=1683337&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java (original)
+++ tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java Wed Jun 3 13:56:45 2015
@@ -41,6 +41,7 @@ import org.apache.coyote.http2.HpackDeco
import org.apache.coyote.http2.Http2Parser.Input;
import org.apache.coyote.http2.Http2Parser.Output;
import org.apache.tomcat.util.codec.binary.Base64;
+import org.apache.tomcat.util.http.MimeHeaders;
/**
@@ -64,6 +65,7 @@ public abstract class Http2TestBase exte
}
private Socket s;
+ protected HpackEncoder hpackEncoder;
protected Input input;
protected TestOutput output;
protected Http2Parser parser;
@@ -83,6 +85,7 @@ public abstract class Http2TestBase exte
validateHttp2InitialResponse();
}
+
protected void validateHttp2InitialResponse() throws Exception {
// - 101 response acts as acknowledgement of the HTTP2-Settings header
// Need to read 4 frames
@@ -97,15 +100,61 @@ public abstract class Http2TestBase exte
Assert.assertEquals("0-Settings-End\n" +
"0-Settings-Ack\n" +
- "1-HeadersStart\n" +
- "1-Header-[:status]-[200]\n" +
- "1-HeadersEnd\n" +
- "1-Body-8192\n" +
- "1-EndOfStream", output.getTrace());
+ getSimpleResponseTrace(1)
+ , output.getTrace());
output.clearTrace();
}
+ protected void sendSimpleRequest(int streamId) throws IOException {
+ MimeHeaders headers = new MimeHeaders();
+ headers.addValue(":method").setString("GET");
+ headers.addValue(":path").setString("/any");
+ headers.addValue(":authority").setString("localhost:" + getPort());
+ ByteBuffer buf = ByteBuffer.allocate(128);
+ hpackEncoder.encode(headers, buf);
+
+ buf.flip();
+ byte[] frameHeader = new byte[9];
+
+ ByteUtil.setThreeBytes(frameHeader, 0, buf.limit());
+ // Header frame is type 0x01
+ frameHeader[3] = 0x01;
+ // Flags. end of headers (0x04). end of stream (0x01)
+ frameHeader[4] = 0x05;
+ // Stream id
+ ByteUtil.set31Bits(frameHeader, 5, streamId);
+ os.write(frameHeader);
+ os.write(buf.array(), buf.arrayOffset(), buf.limit());
+ os.flush();
+ }
+
+
+ protected void readSimpleResponse() throws IOException {
+ // Headers
+ parser.readFrame(true);
+ // Body
+ parser.readFrame(true);
+ }
+
+
+ protected String getSimpleResponseTrace(int streamId) {
+ StringBuilder result = new StringBuilder();
+ result.append(streamId);
+ result.append("-HeadersStart\n");
+ result.append(streamId);
+ result.append("-Header-[:status]-[200]\n");
+ result.append(streamId);
+ result.append("-HeadersEnd\n");
+ result.append(streamId);
+ result.append("-Body-8192\n");
+ result.append(streamId);
+ result.append("-EndOfStream\n");
+
+ return result.toString();
+ }
+
+
protected void enableHttp2() {
Connector connector = getTomcatInstance().getConnector();
Http2Protocol http2Protocol = new Http2Protocol();
@@ -291,7 +340,7 @@ public abstract class Http2TestBase exte
}
- private static class TestOutput implements Output, HeaderEmitter {
+ static class TestOutput implements Output, HeaderEmitter {
private StringBuffer trace = new StringBuffer();
private String lastStreamId = "0";
@@ -315,7 +364,7 @@ public abstract class Http2TestBase exte
@Override
public void endOfStream(int streamId) {
lastStreamId = Integer.toString(streamId);
- trace.append(lastStreamId + "-EndOfStream");
+ trace.append(lastStreamId + "-EndOfStream\n");
}
Added: tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_4_1.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_4_1.java?rev=1683337&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_4_1.java (added)
+++ tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_4_1.java Wed Jun 3 13:56:45 2015
@@ -0,0 +1,51 @@
+/*
+ * 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.coyote.http2;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Unit tests for Section 4.1 of
+ * <a href="https://tools.ietf.org/html/rfc7540">RFC 7540</a>.
+ * <br>
+ * The order of tests in this class is aligned with the order of the
+ * requirements in the RFC.
+ */
+public class TestHttp2Section_4_1 extends Http2TestBase {
+
+ private static final byte[] UNKNOWN_FRAME = new byte[] {
+ 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+ // TODO: Tests for over-sized frames. Better located in tests for section 6?
+
+ @Test
+ public void testUnknownFrameType() throws Exception {
+ hpackEncoder = new HpackEncoder(ConnectionSettings.DEFAULT_HEADER_TABLE_SIZE);
+
+ http2Connect();
+ os.write(UNKNOWN_FRAME);
+ os.flush();
+ sendSimpleRequest(3);
+ readSimpleResponse();
+ Assert.assertEquals(getSimpleResponseTrace(3), output.getTrace());
+ }
+
+ // TODO: Tests for unexpected flags. Better located in tests for section 6?
+
+ // TODO: Test that set reserved bit is ignored.
+}
Propchange: tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_4_1.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org