diff --git a/src/libraries/Common/tests/Tests/System/Net/aspnetcore/Http2/HPackDecoderTest.cs b/src/libraries/Common/tests/Tests/System/Net/aspnetcore/Http2/HPackDecoderTest.cs index 28e7a97107366..ff141b846b399 100644 --- a/src/libraries/Common/tests/Tests/System/Net/aspnetcore/Http2/HPackDecoderTest.cs +++ b/src/libraries/Common/tests/Tests/System/Net/aspnetcore/Http2/HPackDecoderTest.cs @@ -87,6 +87,10 @@ public class HPackDecoderTests .Concat(_headerValueHuffmanBytes) .ToArray(); + private static readonly byte[] _literalEmptyString = new byte[] { 0x00 }; + + private static readonly byte[] _literalEmptyStringHuffman = new byte[] { 0x80 }; + // & * // 11111000 11111111 private static readonly byte[] _huffmanLongPadding = new byte[] { 0x82, 0xf8, 0xff }; @@ -243,6 +247,43 @@ public void DecodesLiteralHeaderFieldWithoutIndexing_NewName() TestDecodeWithoutIndexing(encoded, _headerNameString, _headerValueString); } + [Fact] + public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_EmptyName() + { + byte[] encoded = _literalHeaderFieldWithoutIndexingNewName + .Concat(_literalEmptyString) + .Concat(_headerValue) + .ToArray(); + + HPackDecodingException exception = Assert.Throws(() => _decoder.Decode(encoded, endHeaders: true, handler: _handler)); + Assert.Equal(SR.Format(SR.net_http_invalid_header_name, string.Empty), exception.Message); + Assert.Empty(_handler.DecodedHeaders); + } + + [Fact] + public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_EmptyValue() + { + byte[] encoded = _literalHeaderFieldWithoutIndexingNewName + .Concat(_headerName) + .Concat(_literalEmptyString) + .ToArray(); + + TestDecodeWithoutIndexing(encoded, _headerNameString, string.Empty); + } + + [Fact] + public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_EmptyNameAndValue() + { + byte[] encoded = _literalHeaderFieldWithoutIndexingNewName + .Concat(_literalEmptyString) + .Concat(_literalEmptyString) + .ToArray(); + + HPackDecodingException exception = Assert.Throws(() => _decoder.Decode(encoded, endHeaders: true, handler: _handler)); + Assert.Equal(SR.Format(SR.net_http_invalid_header_name, string.Empty), exception.Message); + Assert.Empty(_handler.DecodedHeaders); + } + [Fact] public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedName() { @@ -254,6 +295,19 @@ public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedName( TestDecodeWithoutIndexing(encoded, _headerNameString, _headerValueString); } + [Fact] + public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedName_Empty() + { + byte[] encoded = _literalHeaderFieldWithoutIndexingNewName + .Concat(_literalEmptyStringHuffman) + .Concat(_headerValue) + .ToArray(); + + HPackDecodingException exception = Assert.Throws(() => _decoder.Decode(encoded, endHeaders: true, handler: _handler)); + Assert.Equal(SR.Format(SR.net_http_invalid_header_name, string.Empty), exception.Message); + Assert.Empty(_handler.DecodedHeaders); + } + [Fact] public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedValue() { @@ -265,6 +319,17 @@ public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedValue TestDecodeWithoutIndexing(encoded, _headerNameString, _headerValueString); } + [Fact] + public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedValue_Empty() + { + byte[] encoded = _literalHeaderFieldWithoutIndexingNewName + .Concat(_headerName) + .Concat(_literalEmptyStringHuffman) + .ToArray(); + + TestDecodeWithoutIndexing(encoded, _headerNameString, string.Empty); + } + [Fact] public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedNameAndValue() { @@ -276,6 +341,19 @@ public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedNameA TestDecodeWithoutIndexing(encoded, _headerNameString, _headerValueString); } + [Fact] + public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedNameAndValue_Empty() + { + byte[] encoded = _literalHeaderFieldWithoutIndexingNewName + .Concat(_literalEmptyStringHuffman) + .Concat(_literalEmptyStringHuffman) + .ToArray(); + + HPackDecodingException exception = Assert.Throws(() => _decoder.Decode(encoded, endHeaders: true, handler: _handler)); + Assert.Equal(SR.Format(SR.net_http_invalid_header_name, string.Empty), exception.Message); + Assert.Empty(_handler.DecodedHeaders); + } + [Fact] public void DecodesLiteralHeaderFieldWithoutIndexing_IndexedName() {