Skip to content

Commit

Permalink
Add test to confirm that the server ignores the reserved bit if set
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1683339 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Jun 3, 2015
1 parent f4361d1 commit d742b96
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
24 changes: 18 additions & 6 deletions test/org/apache/coyote/http2/Http2TestBase.java
Expand Up @@ -107,25 +107,37 @@ protected void validateHttp2InitialResponse() throws Exception {




protected void sendSimpleRequest(int streamId) throws IOException { protected void sendSimpleRequest(int streamId) throws IOException {
byte[] frameHeader = new byte[9];
ByteBuffer headersPayload = ByteBuffer.allocate(128);

buildSimpleRequest(frameHeader, headersPayload, streamId);
writeSimpleRequest(frameHeader, headersPayload);
}


protected void buildSimpleRequest(byte[] frameHeader, ByteBuffer headersPayload, int streamId) {
MimeHeaders headers = new MimeHeaders(); MimeHeaders headers = new MimeHeaders();
headers.addValue(":method").setString("GET"); headers.addValue(":method").setString("GET");
headers.addValue(":path").setString("/any"); headers.addValue(":path").setString("/any");
headers.addValue(":authority").setString("localhost:" + getPort()); headers.addValue(":authority").setString("localhost:" + getPort());
ByteBuffer buf = ByteBuffer.allocate(128); hpackEncoder.encode(headers, headersPayload);
hpackEncoder.encode(headers, buf);


buf.flip(); headersPayload.flip();
byte[] frameHeader = new byte[9];


ByteUtil.setThreeBytes(frameHeader, 0, buf.limit()); ByteUtil.setThreeBytes(frameHeader, 0, headersPayload.limit());
// Header frame is type 0x01 // Header frame is type 0x01
frameHeader[3] = 0x01; frameHeader[3] = 0x01;
// Flags. end of headers (0x04). end of stream (0x01) // Flags. end of headers (0x04). end of stream (0x01)
frameHeader[4] = 0x05; frameHeader[4] = 0x05;
// Stream id // Stream id
ByteUtil.set31Bits(frameHeader, 5, streamId); ByteUtil.set31Bits(frameHeader, 5, streamId);
}


protected void writeSimpleRequest(byte[] frameHeader, ByteBuffer headersPayload)
throws IOException {
os.write(frameHeader); os.write(frameHeader);
os.write(buf.array(), buf.arrayOffset(), buf.limit()); os.write(headersPayload.array(), headersPayload.arrayOffset(), headersPayload.limit());
os.flush(); os.flush();
} }


Expand Down
27 changes: 26 additions & 1 deletion test/org/apache/coyote/http2/TestHttp2Section_4_1.java
Expand Up @@ -16,6 +16,8 @@
*/ */
package org.apache.coyote.http2; package org.apache.coyote.http2;


import java.nio.ByteBuffer;

import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;


Expand All @@ -33,6 +35,7 @@ public class TestHttp2Section_4_1 extends Http2TestBase {


// TODO: Tests for over-sized frames. Better located in tests for section 6? // TODO: Tests for over-sized frames. Better located in tests for section 6?



@Test @Test
public void testUnknownFrameType() throws Exception { public void testUnknownFrameType() throws Exception {
hpackEncoder = new HpackEncoder(ConnectionSettings.DEFAULT_HEADER_TABLE_SIZE); hpackEncoder = new HpackEncoder(ConnectionSettings.DEFAULT_HEADER_TABLE_SIZE);
Expand All @@ -45,7 +48,29 @@ public void testUnknownFrameType() throws Exception {
Assert.assertEquals(getSimpleResponseTrace(3), output.getTrace()); Assert.assertEquals(getSimpleResponseTrace(3), output.getTrace());
} }



// TODO: Tests for unexpected flags. Better located in tests for section 6? // TODO: Tests for unexpected flags. Better located in tests for section 6?


// TODO: Test that set reserved bit is ignored.
@Test
public void testReservedBitIgnored() throws Exception {
hpackEncoder = new HpackEncoder(ConnectionSettings.DEFAULT_HEADER_TABLE_SIZE);

// HTTP2 upgrade
http2Connect();

// Build the simple request
byte[] frameHeader = new byte[9];
ByteBuffer headersPayload = ByteBuffer.allocate(128);
buildSimpleRequest(frameHeader, headersPayload, 3);

// Tweak the header to set the reserved bit
frameHeader[5] = (byte) (frameHeader[5] | 0x80);

// Process the request
writeSimpleRequest(frameHeader, headersPayload);

readSimpleResponse();
Assert.assertEquals(getSimpleResponseTrace(3), output.getTrace());
}
} }

0 comments on commit d742b96

Please sign in to comment.