Skip to content

Commit

Permalink
Sync shared code from aspnetcore (#105765)
Browse files Browse the repository at this point in the history
Co-authored-by: Tratcher <[email protected]>
Co-authored-by: Andrew Casey <[email protected]>
Co-authored-by: Larry Ewing <[email protected]>
Co-authored-by: Eric Erhardt <[email protected]>
  • Loading branch information
5 people authored Aug 2, 2024
1 parent 3e572e9 commit d9fc0f1
Showing 1 changed file with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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<HPackDecodingException>(() => _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<HPackDecodingException>(() => _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()
{
Expand All @@ -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<HPackDecodingException>(() => _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()
{
Expand All @@ -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()
{
Expand All @@ -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<HPackDecodingException>(() => _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()
{
Expand Down

0 comments on commit d9fc0f1

Please sign in to comment.