Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Unified Diff: net/quic/core/spdy_utils_test.cc

Issue 2961123002: Add tests for gfe/quic/spdy_utils::CopyAndValidateTrailers. (Closed)
Patch Set: Rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/core/spdy_utils_test.cc
diff --git a/net/quic/core/spdy_utils_test.cc b/net/quic/core/spdy_utils_test.cc
index 034af2537280bb3221abd66d7d8d5e07a807502f..b5978aa74c44425a85ce56b979bc129b4dbdc39d 100644
--- a/net/quic/core/spdy_utils_test.cc
+++ b/net/quic/core/spdy_utils_test.cc
@@ -194,6 +194,74 @@ TEST(CopyAndValidateHeaders, MultipleCookies) {
EXPECT_EQ(-1, content_length);
}
+TEST(CopyAndValidateTrailers, SimplestValidList) {
+ // Verify that the simplest trailers are valid: just a final byte offset that
+ // gets parsed successfully.
+ auto trailers = FromList({{kFinalOffsetHeaderKey, "1234"}});
+ size_t final_byte_offset = 0;
+ SpdyHeaderBlock block;
+ EXPECT_TRUE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
+ &block));
+ EXPECT_EQ(1234u, final_byte_offset);
+}
+
+TEST(CopyAndValidateTrailers, EmptyTrailerList) {
+ // An empty trailer list will fail as required key kFinalOffsetHeaderKey is
+ // not present.
+ QuicHeaderList trailers;
+ size_t final_byte_offset = 0;
+ SpdyHeaderBlock block;
+ EXPECT_FALSE(
+ SpdyUtils::CopyAndValidateTrailers(trailers, &final_byte_offset, &block));
+}
+
+TEST(CopyAndValidateTrailers, FinalByteOffsetNotPresent) {
+ // Validation fails if required kFinalOffsetHeaderKey is not present, even if
+ // the rest of the header block is valid.
+ auto trailers = FromList({{"key", "value"}});
+ size_t final_byte_offset = 0;
+ SpdyHeaderBlock block;
+ EXPECT_FALSE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
+ &block));
+}
+
+TEST(CopyAndValidateTrailers, EmptyName) {
+ // Trailer validation will fail with an empty header key, in an otherwise
+ // valid block of trailers.
+ auto trailers = FromList({{"", "value"}, {kFinalOffsetHeaderKey, "1234"}});
+ size_t final_byte_offset = 0;
+ SpdyHeaderBlock block;
+ EXPECT_FALSE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
+ &block));
+}
+
+TEST(CopyAndValidateTrailers, PseudoHeaderInTrailers) {
+ // Pseudo headers are illegal in trailers.
+ auto trailers =
+ FromList({{":pseudo_key", "value"}, {kFinalOffsetHeaderKey, "1234"}});
+ size_t final_byte_offset = 0;
+ SpdyHeaderBlock block;
+ EXPECT_FALSE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
+ &block));
+}
+
+TEST(CopyAndValidateTrailers, DuplicateTrailers) {
+ // Duplicate trailers are not allowed.
+ auto trailers = FromList({{"key", "value0"},
+ {"key", "value1"},
+ {"key", ""},
+ {"key", ""},
+ {"key", "value2"},
+ {"key", ""},
+ {kFinalOffsetHeaderKey, "1234"},
+ {"other_key", "value"},
+ {"key", "non_contiguous_duplicate"}});
+ size_t final_byte_offset = 0;
+ SpdyHeaderBlock block;
+ EXPECT_FALSE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
+ &block));
+}
+
TEST(GetUrlFromHeaderBlock, Basic) {
SpdyHeaderBlock headers;
EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), "");
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698