OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http2/decoder/payload_decoders/headers_payload_decoder.h" | 5 #include "net/http2/decoder/payload_decoders/headers_payload_decoder.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/bind.h" | |
12 #include "base/logging.h" | 11 #include "base/logging.h" |
13 #include "net/http2/decoder/frame_parts.h" | 12 #include "net/http2/decoder/frame_parts.h" |
14 #include "net/http2/decoder/frame_parts_collector.h" | 13 #include "net/http2/decoder/frame_parts_collector.h" |
15 #include "net/http2/decoder/http2_frame_decoder_listener.h" | 14 #include "net/http2/decoder/http2_frame_decoder_listener.h" |
16 #include "net/http2/decoder/payload_decoders/payload_decoder_base_test_util.h" | 15 #include "net/http2/decoder/payload_decoders/payload_decoder_base_test_util.h" |
17 #include "net/http2/http2_constants.h" | 16 #include "net/http2/http2_constants.h" |
18 #include "net/http2/http2_structures_test_util.h" | 17 #include "net/http2/http2_structures_test_util.h" |
19 #include "net/http2/tools/http2_frame_builder.h" | 18 #include "net/http2/tools/http2_frame_builder.h" |
20 #include "net/http2/tools/http2_random.h" | 19 #include "net/http2/tools/http2_random.h" |
21 #include "net/http2/tools/random_decoder_test.h" | 20 #include "net/http2/tools/random_decoder_test.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 95 |
97 void OnFrameSizeError(const Http2FrameHeader& header) override { | 96 void OnFrameSizeError(const Http2FrameHeader& header) override { |
98 VLOG(1) << "OnFrameSizeError: " << header; | 97 VLOG(1) << "OnFrameSizeError: " << header; |
99 FrameError(header)->OnFrameSizeError(header); | 98 FrameError(header)->OnFrameSizeError(header); |
100 } | 99 } |
101 }; | 100 }; |
102 | 101 |
103 class HeadersPayloadDecoderTest | 102 class HeadersPayloadDecoderTest |
104 : public AbstractPaddablePayloadDecoderTest<HeadersPayloadDecoder, | 103 : public AbstractPaddablePayloadDecoderTest<HeadersPayloadDecoder, |
105 HeadersPayloadDecoderPeer, | 104 HeadersPayloadDecoderPeer, |
106 Listener> { | 105 Listener> {}; |
107 public: | |
108 static bool ApproveSizeForTruncated(size_t size) { | |
109 return size != Http2PriorityFields::EncodedSize(); | |
110 } | |
111 }; | |
112 | 106 |
113 INSTANTIATE_TEST_CASE_P(VariousPadLengths, | 107 INSTANTIATE_TEST_CASE_P(VariousPadLengths, |
114 HeadersPayloadDecoderTest, | 108 HeadersPayloadDecoderTest, |
115 ::testing::Values(0, 1, 2, 3, 4, 254, 255, 256)); | 109 ::testing::Values(0, 1, 2, 3, 4, 254, 255, 256)); |
116 | 110 |
117 // Decode various sizes of (fake) HPACK payload, both with and without the | 111 // Decode various sizes of (fake) HPACK payload, both with and without the |
118 // PRIORITY flag set. | 112 // PRIORITY flag set. |
119 TEST_P(HeadersPayloadDecoderTest, VariousHpackPayloadSizes) { | 113 TEST_P(HeadersPayloadDecoderTest, VariousHpackPayloadSizes) { |
120 for (size_t hpack_size : {0, 1, 2, 3, 255, 256, 1024}) { | 114 for (size_t hpack_size : {0, 1, 2, 3, 255, 256, 1024}) { |
121 LOG(INFO) << "########### hpack_size = " << hpack_size << " ###########"; | 115 LOG(INFO) << "########### hpack_size = " << hpack_size << " ###########"; |
(...skipping 24 matching lines...) Expand all Loading... |
146 } | 140 } |
147 EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(frame_builder_.buffer(), | 141 EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(frame_builder_.buffer(), |
148 expected)); | 142 expected)); |
149 } | 143 } |
150 } | 144 } |
151 } | 145 } |
152 | 146 |
153 // Confirm we get an error if the PRIORITY flag is set but the payload is | 147 // Confirm we get an error if the PRIORITY flag is set but the payload is |
154 // not long enough, regardless of the amount of (valid) padding. | 148 // not long enough, regardless of the amount of (valid) padding. |
155 TEST_P(HeadersPayloadDecoderTest, Truncated) { | 149 TEST_P(HeadersPayloadDecoderTest, Truncated) { |
| 150 auto approve_size = [](size_t size) { |
| 151 return size != Http2PriorityFields::EncodedSize(); |
| 152 }; |
156 Http2FrameBuilder fb; | 153 Http2FrameBuilder fb; |
157 fb.Append(Http2PriorityFields(RandStreamId(), 1 + Random().Rand8(), | 154 fb.Append(Http2PriorityFields(RandStreamId(), 1 + Random().Rand8(), |
158 Random().OneIn(2))); | 155 Random().OneIn(2))); |
159 EXPECT_TRUE(VerifyDetectsMultipleFrameSizeErrors( | 156 EXPECT_TRUE(VerifyDetectsMultipleFrameSizeErrors( |
160 Http2FrameFlag::FLAG_PRIORITY, fb.buffer(), | 157 Http2FrameFlag::FLAG_PRIORITY, fb.buffer(), approve_size, |
161 base::Bind(&HeadersPayloadDecoderTest::ApproveSizeForTruncated), | |
162 total_pad_length_)); | 158 total_pad_length_)); |
163 } | 159 } |
164 | 160 |
165 // Confirm we get an error if the PADDED flag is set but the payload is not | 161 // Confirm we get an error if the PADDED flag is set but the payload is not |
166 // long enough to hold even the Pad Length amount of padding. | 162 // long enough to hold even the Pad Length amount of padding. |
167 TEST_P(HeadersPayloadDecoderTest, PaddingTooLong) { | 163 TEST_P(HeadersPayloadDecoderTest, PaddingTooLong) { |
168 EXPECT_TRUE(VerifyDetectsPaddingTooLong()); | 164 EXPECT_TRUE(VerifyDetectsPaddingTooLong()); |
169 } | 165 } |
170 | 166 |
171 } // namespace | 167 } // namespace |
172 } // namespace test | 168 } // namespace test |
173 } // namespace net | 169 } // namespace net |
OLD | NEW |