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/push_promise_payload_decoder.h" | 5 #include "net/http2/decoder/payload_decoders/push_promise_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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 void OnFrameSizeError(const Http2FrameHeader& header) override { | 88 void OnFrameSizeError(const Http2FrameHeader& header) override { |
90 VLOG(1) << "OnFrameSizeError: " << header; | 89 VLOG(1) << "OnFrameSizeError: " << header; |
91 FrameError(header)->OnFrameSizeError(header); | 90 FrameError(header)->OnFrameSizeError(header); |
92 } | 91 } |
93 }; | 92 }; |
94 | 93 |
95 class PushPromisePayloadDecoderTest | 94 class PushPromisePayloadDecoderTest |
96 : public AbstractPaddablePayloadDecoderTest<PushPromisePayloadDecoder, | 95 : public AbstractPaddablePayloadDecoderTest<PushPromisePayloadDecoder, |
97 PushPromisePayloadDecoderPeer, | 96 PushPromisePayloadDecoderPeer, |
98 Listener> { | 97 Listener> { |
99 public: | |
100 static bool ApproveSizeForTruncated(size_t size) { | |
101 return size != Http2PushPromiseFields::EncodedSize(); | |
102 } | |
103 }; | 98 }; |
104 | 99 |
105 INSTANTIATE_TEST_CASE_P(VariousPadLengths, | 100 INSTANTIATE_TEST_CASE_P(VariousPadLengths, |
106 PushPromisePayloadDecoderTest, | 101 PushPromisePayloadDecoderTest, |
107 ::testing::Values(0, 1, 2, 3, 4, 254, 255, 256)); | 102 ::testing::Values(0, 1, 2, 3, 4, 254, 255, 256)); |
108 | 103 |
109 // Payload contains the required Http2PushPromiseFields, followed by some | 104 // Payload contains the required Http2PushPromiseFields, followed by some |
110 // (fake) HPACK payload. | 105 // (fake) HPACK payload. |
111 TEST_P(PushPromisePayloadDecoderTest, VariousHpackPayloadSizes) { | 106 TEST_P(PushPromisePayloadDecoderTest, VariousHpackPayloadSizes) { |
112 for (size_t hpack_size : {0, 1, 2, 3, 255, 256, 1024}) { | 107 for (size_t hpack_size : {0, 1, 2, 3, 255, 256, 1024}) { |
(...skipping 11 matching lines...) Expand all Loading... |
124 FrameParts expected(frame_header, hpack_payload, total_pad_length_); | 119 FrameParts expected(frame_header, hpack_payload, total_pad_length_); |
125 expected.opt_push_promise = push_promise; | 120 expected.opt_push_promise = push_promise; |
126 EXPECT_TRUE( | 121 EXPECT_TRUE( |
127 DecodePayloadAndValidateSeveralWays(frame_builder_.buffer(), expected)); | 122 DecodePayloadAndValidateSeveralWays(frame_builder_.buffer(), expected)); |
128 } | 123 } |
129 } | 124 } |
130 | 125 |
131 // Confirm we get an error if the payload is not long enough for the required | 126 // Confirm we get an error if the payload is not long enough for the required |
132 // portion of the payload, regardless of the amount of (valid) padding. | 127 // portion of the payload, regardless of the amount of (valid) padding. |
133 TEST_P(PushPromisePayloadDecoderTest, Truncated) { | 128 TEST_P(PushPromisePayloadDecoderTest, Truncated) { |
| 129 auto approve_size = [](size_t size) { |
| 130 return size != Http2PushPromiseFields::EncodedSize(); |
| 131 }; |
134 Http2PushPromiseFields push_promise{RandStreamId()}; | 132 Http2PushPromiseFields push_promise{RandStreamId()}; |
135 Http2FrameBuilder fb; | 133 Http2FrameBuilder fb; |
136 fb.Append(push_promise); | 134 fb.Append(push_promise); |
137 EXPECT_TRUE(VerifyDetectsMultipleFrameSizeErrors( | 135 EXPECT_TRUE(VerifyDetectsMultipleFrameSizeErrors(0, fb.buffer(), approve_size, |
138 0, fb.buffer(), | 136 total_pad_length_)); |
139 base::Bind(&PushPromisePayloadDecoderTest::ApproveSizeForTruncated), | |
140 total_pad_length_)); | |
141 } | 137 } |
142 | 138 |
143 // Confirm we get an error if the PADDED flag is set but the payload is not | 139 // Confirm we get an error if the PADDED flag is set but the payload is not |
144 // long enough to hold even the Pad Length amount of padding. | 140 // long enough to hold even the Pad Length amount of padding. |
145 TEST_P(PushPromisePayloadDecoderTest, PaddingTooLong) { | 141 TEST_P(PushPromisePayloadDecoderTest, PaddingTooLong) { |
146 EXPECT_TRUE(VerifyDetectsPaddingTooLong()); | 142 EXPECT_TRUE(VerifyDetectsPaddingTooLong()); |
147 } | 143 } |
148 | 144 |
149 } // namespace | 145 } // namespace |
150 } // namespace test | 146 } // namespace test |
151 } // namespace net | 147 } // namespace net |
OLD | NEW |