Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync shared code from aspnetcore #105765

Merged
merged 4 commits into from
Aug 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading