QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright (c) 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 5 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6 | #include <tuple> |
| 7 | |
vasilvv | 7cac7b0 | 2020-10-08 12:32:10 -0700 | [diff] [blame] | 8 | #include "absl/strings/string_view.h" |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 9 | #include "quic/platform/api/quic_test.h" |
| 10 | #include "quic/test_tools/qpack/qpack_decoder_test_utils.h" |
| 11 | #include "quic/test_tools/qpack/qpack_encoder_test_utils.h" |
| 12 | #include "quic/test_tools/qpack/qpack_test_utils.h" |
| 13 | #include "spdy/core/spdy_header_block.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 14 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 15 | using ::testing::Values; |
| 16 | |
| 17 | namespace quic { |
| 18 | namespace test { |
| 19 | namespace { |
| 20 | |
bnc | f21c1ad | 2019-06-20 20:09:50 -0700 | [diff] [blame] | 21 | class QpackRoundTripTest : public QuicTestWithParam<FragmentMode> { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 22 | public: |
bnc | f21c1ad | 2019-06-20 20:09:50 -0700 | [diff] [blame] | 23 | QpackRoundTripTest() = default; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 24 | ~QpackRoundTripTest() override = default; |
| 25 | |
QUICHE team | 232cf49 | 2020-10-27 08:21:26 -0700 | [diff] [blame] | 26 | spdy::Http2HeaderBlock EncodeThenDecode( |
| 27 | const spdy::Http2HeaderBlock& header_list) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 28 | NoopDecoderStreamErrorDelegate decoder_stream_error_delegate; |
renjietang | c2aa5cb | 2019-06-20 12:22:53 -0700 | [diff] [blame] | 29 | NoopQpackStreamSenderDelegate encoder_stream_sender_delegate; |
renjietang | 8a2df8f | 2019-08-07 10:43:52 -0700 | [diff] [blame] | 30 | QpackEncoder encoder(&decoder_stream_error_delegate); |
| 31 | encoder.set_qpack_stream_sender_delegate(&encoder_stream_sender_delegate); |
bnc | f21c1ad | 2019-06-20 20:09:50 -0700 | [diff] [blame] | 32 | std::string encoded_header_block = |
bnc | 609c24e | 2019-09-10 05:24:32 -0700 | [diff] [blame] | 33 | encoder.EncodeHeaderList(/* stream_id = */ 1, header_list, nullptr); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 34 | |
| 35 | TestHeadersHandler handler; |
| 36 | NoopEncoderStreamErrorDelegate encoder_stream_error_delegate; |
renjietang | c2aa5cb | 2019-06-20 12:22:53 -0700 | [diff] [blame] | 37 | NoopQpackStreamSenderDelegate decoder_stream_sender_delegate; |
bnc | 4c664c5 | 2019-08-04 18:14:12 -0700 | [diff] [blame] | 38 | // TODO(b/112770235): Test dynamic table and blocked streams. |
| 39 | QpackDecode( |
| 40 | /* maximum_dynamic_table_capacity = */ 0, |
| 41 | /* maximum_blocked_streams = */ 0, &encoder_stream_error_delegate, |
| 42 | &decoder_stream_sender_delegate, &handler, |
| 43 | FragmentModeToFragmentSizeGenerator(GetParam()), encoded_header_block); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 44 | |
| 45 | EXPECT_TRUE(handler.decoding_completed()); |
| 46 | EXPECT_FALSE(handler.decoding_error_detected()); |
| 47 | |
| 48 | return handler.ReleaseHeaderList(); |
| 49 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 50 | }; |
| 51 | |
QUICHE team | 1bfe0d7 | 2019-09-23 04:50:47 -0700 | [diff] [blame] | 52 | INSTANTIATE_TEST_SUITE_P(All, |
bnc | f21c1ad | 2019-06-20 20:09:50 -0700 | [diff] [blame] | 53 | QpackRoundTripTest, |
| 54 | Values(FragmentMode::kSingleChunk, |
| 55 | FragmentMode::kOctetByOctet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 56 | |
| 57 | TEST_P(QpackRoundTripTest, Empty) { |
QUICHE team | 232cf49 | 2020-10-27 08:21:26 -0700 | [diff] [blame] | 58 | spdy::Http2HeaderBlock header_list; |
| 59 | spdy::Http2HeaderBlock output = EncodeThenDecode(header_list); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 60 | EXPECT_EQ(header_list, output); |
| 61 | } |
| 62 | |
| 63 | TEST_P(QpackRoundTripTest, EmptyName) { |
QUICHE team | 232cf49 | 2020-10-27 08:21:26 -0700 | [diff] [blame] | 64 | spdy::Http2HeaderBlock header_list; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 65 | header_list["foo"] = "bar"; |
| 66 | header_list[""] = "bar"; |
| 67 | |
QUICHE team | 232cf49 | 2020-10-27 08:21:26 -0700 | [diff] [blame] | 68 | spdy::Http2HeaderBlock output = EncodeThenDecode(header_list); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 69 | EXPECT_EQ(header_list, output); |
| 70 | } |
| 71 | |
| 72 | TEST_P(QpackRoundTripTest, EmptyValue) { |
QUICHE team | 232cf49 | 2020-10-27 08:21:26 -0700 | [diff] [blame] | 73 | spdy::Http2HeaderBlock header_list; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 74 | header_list["foo"] = ""; |
| 75 | header_list[""] = ""; |
| 76 | |
QUICHE team | 232cf49 | 2020-10-27 08:21:26 -0700 | [diff] [blame] | 77 | spdy::Http2HeaderBlock output = EncodeThenDecode(header_list); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 78 | EXPECT_EQ(header_list, output); |
| 79 | } |
| 80 | |
| 81 | TEST_P(QpackRoundTripTest, MultipleWithLongEntries) { |
QUICHE team | 232cf49 | 2020-10-27 08:21:26 -0700 | [diff] [blame] | 82 | spdy::Http2HeaderBlock header_list; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 83 | header_list["foo"] = "bar"; |
| 84 | header_list[":path"] = "/"; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 85 | header_list["foobaar"] = std::string(127, 'Z'); |
| 86 | header_list[std::string(1000, 'b')] = std::string(1000, 'c'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 87 | |
QUICHE team | 232cf49 | 2020-10-27 08:21:26 -0700 | [diff] [blame] | 88 | spdy::Http2HeaderBlock output = EncodeThenDecode(header_list); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 89 | EXPECT_EQ(header_list, output); |
| 90 | } |
| 91 | |
| 92 | TEST_P(QpackRoundTripTest, StaticTable) { |
| 93 | { |
QUICHE team | 232cf49 | 2020-10-27 08:21:26 -0700 | [diff] [blame] | 94 | spdy::Http2HeaderBlock header_list; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 95 | header_list[":method"] = "GET"; |
| 96 | header_list["accept-encoding"] = "gzip, deflate"; |
| 97 | header_list["cache-control"] = ""; |
| 98 | header_list["foo"] = "bar"; |
| 99 | header_list[":path"] = "/"; |
| 100 | |
QUICHE team | 232cf49 | 2020-10-27 08:21:26 -0700 | [diff] [blame] | 101 | spdy::Http2HeaderBlock output = EncodeThenDecode(header_list); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 102 | EXPECT_EQ(header_list, output); |
| 103 | } |
| 104 | { |
QUICHE team | 232cf49 | 2020-10-27 08:21:26 -0700 | [diff] [blame] | 105 | spdy::Http2HeaderBlock header_list; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 106 | header_list[":method"] = "POST"; |
| 107 | header_list["accept-encoding"] = "brotli"; |
| 108 | header_list["cache-control"] = "foo"; |
| 109 | header_list["foo"] = "bar"; |
| 110 | header_list[":path"] = "/"; |
| 111 | |
QUICHE team | 232cf49 | 2020-10-27 08:21:26 -0700 | [diff] [blame] | 112 | spdy::Http2HeaderBlock output = EncodeThenDecode(header_list); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 113 | EXPECT_EQ(header_list, output); |
| 114 | } |
| 115 | { |
QUICHE team | 232cf49 | 2020-10-27 08:21:26 -0700 | [diff] [blame] | 116 | spdy::Http2HeaderBlock header_list; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 117 | header_list[":method"] = "CONNECT"; |
| 118 | header_list["accept-encoding"] = ""; |
| 119 | header_list["foo"] = "bar"; |
| 120 | header_list[":path"] = "/"; |
| 121 | |
QUICHE team | 232cf49 | 2020-10-27 08:21:26 -0700 | [diff] [blame] | 122 | spdy::Http2HeaderBlock output = EncodeThenDecode(header_list); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 123 | EXPECT_EQ(header_list, output); |
| 124 | } |
| 125 | } |
| 126 | |
bnc | 7805361 | 2019-04-25 20:08:12 -0700 | [diff] [blame] | 127 | TEST_P(QpackRoundTripTest, ValueHasNullCharacter) { |
QUICHE team | 232cf49 | 2020-10-27 08:21:26 -0700 | [diff] [blame] | 128 | spdy::Http2HeaderBlock header_list; |
vasilvv | 7cac7b0 | 2020-10-08 12:32:10 -0700 | [diff] [blame] | 129 | header_list["foo"] = absl::string_view("bar\0bar\0baz", 11); |
bnc | 7805361 | 2019-04-25 20:08:12 -0700 | [diff] [blame] | 130 | |
QUICHE team | 232cf49 | 2020-10-27 08:21:26 -0700 | [diff] [blame] | 131 | spdy::Http2HeaderBlock output = EncodeThenDecode(header_list); |
bnc | 7805361 | 2019-04-25 20:08:12 -0700 | [diff] [blame] | 132 | EXPECT_EQ(header_list, output); |
| 133 | } |
| 134 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 135 | } // namespace |
| 136 | } // namespace test |
| 137 | } // namespace quic |