Issue #2679 - HTTP/2 Spec Compliance
Added tests for the problems with the Huffman encoding Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
0da9225056
commit
a72fe7e3c7
|
@ -462,25 +462,84 @@ public class HpackDecoderTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
8.1.2.6. Malformed Requests and Responses
|
|
||||||
× 1: Sends a HEADERS frame with the "content-length" header field which does not equal the DATA frame payload length
|
|
||||||
× 2: Sends a HEADERS frame with the "content-length" header field which does not equal the sum of the multiple DATA frames payload length
|
|
||||||
|
|
||||||
5. Primitive Type Representations
|
@Test()
|
||||||
5.2. String Literal Representation
|
public void testHuffmanEncodedStandard() throws Exception
|
||||||
× 1: Sends a Huffman-encoded string literal representation with padding longer than 7 bits
|
{
|
||||||
-> The endpoint MUST treat this as a decoding error.
|
HpackDecoder decoder = new HpackDecoder(4096, 8192);
|
||||||
Expected: GOAWAY Frame (Error Code: COMPRESSION_ERROR)
|
|
||||||
Connection closed
|
String encoded = "82868441" + "83" + "49509F";
|
||||||
Actual: DATA Frame (length:687, flags:0x01, stream_id:1)
|
ByteBuffer buffer = ByteBuffer.wrap(TypeUtil.fromHexString(encoded));
|
||||||
× 2: Sends a Huffman-encoded string literal representation padded by zero
|
|
||||||
-> The endpoint MUST treat this as a decoding error.
|
MetaData.Request request = (MetaData.Request)decoder.decode(buffer);
|
||||||
Expected: GOAWAY Frame (Error Code: COMPRESSION_ERROR)
|
|
||||||
Connection closed
|
assertEquals("GET", request.getMethod());
|
||||||
Actual: DATA Frame (length:687, flags:0x01, stream_id:1)
|
assertEquals(HttpScheme.HTTP.asString(), request.getURI().getScheme());
|
||||||
✔ 3: Sends a Huffman-encoded string literal representation containing the EOS symbol
|
assertEquals("/", request.getURI().getPath());
|
||||||
*/
|
assertEquals("test", request.getURI().getHost());
|
||||||
|
assertFalse(request.iterator().hasNext());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* 5.2.1: Sends a Huffman-encoded string literal representation with padding longer than 7 bits */
|
||||||
|
@Test()
|
||||||
|
public void testHuffmanEncodedExtraPadding() throws Exception
|
||||||
|
{
|
||||||
|
HpackDecoder decoder = new HpackDecoder(4096, 8192);
|
||||||
|
|
||||||
|
String encoded = "82868441" + "83" + "49509FFF";
|
||||||
|
ByteBuffer buffer = ByteBuffer.wrap(TypeUtil.fromHexString(encoded));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
decoder.decode(buffer);
|
||||||
|
Assert.fail();
|
||||||
|
}
|
||||||
|
catch (StreamException ex)
|
||||||
|
{
|
||||||
|
Assert.assertThat(ex.getMessage(), Matchers.containsString("Padding length exceeded"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* 5.2.2: Sends a Huffman-encoded string literal representation padded by zero */
|
||||||
|
@Test()
|
||||||
|
public void testHuffmanEncodedZeroPadding() throws Exception
|
||||||
|
{
|
||||||
|
HpackDecoder decoder = new HpackDecoder(4096, 8192);
|
||||||
|
|
||||||
|
String encoded = "82868441" + "83" + "495090";
|
||||||
|
ByteBuffer buffer = ByteBuffer.wrap(TypeUtil.fromHexString(encoded));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
decoder.decode(buffer);
|
||||||
|
Assert.fail();
|
||||||
|
}
|
||||||
|
catch (StreamException ex)
|
||||||
|
{
|
||||||
|
Assert.assertThat(ex.getMessage(), Matchers.containsString("Zero padded"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* 5.2.3: Sends a Huffman-encoded string literal representation containing the EOS symbol */
|
||||||
|
@Test()
|
||||||
|
public void testHuffmanEncodedWithEOS() throws Exception
|
||||||
|
{
|
||||||
|
HpackDecoder decoder = new HpackDecoder(4096, 8192);
|
||||||
|
|
||||||
|
String encoded = "82868441" + "87" + "497FFFFFFF427F";
|
||||||
|
ByteBuffer buffer = ByteBuffer.wrap(TypeUtil.fromHexString(encoded));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
decoder.decode(buffer);
|
||||||
|
Assert.fail();
|
||||||
|
}
|
||||||
|
catch (StreamException ex)
|
||||||
|
{
|
||||||
|
Assert.assertThat(ex.getMessage(), Matchers.containsString("EOS in content"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue