| 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/goaway_payload_decoder.h" | 5 #include "net/http2/decoder/payload_decoders/goaway_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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 62 |
| 64 void OnFrameSizeError(const Http2FrameHeader& header) override { | 63 void OnFrameSizeError(const Http2FrameHeader& header) override { |
| 65 VLOG(1) << "OnFrameSizeError: " << header; | 64 VLOG(1) << "OnFrameSizeError: " << header; |
| 66 FrameError(header)->OnFrameSizeError(header); | 65 FrameError(header)->OnFrameSizeError(header); |
| 67 } | 66 } |
| 68 }; | 67 }; |
| 69 | 68 |
| 70 class GoAwayPayloadDecoderTest | 69 class GoAwayPayloadDecoderTest |
| 71 : public AbstractPayloadDecoderTest<GoAwayPayloadDecoder, | 70 : public AbstractPayloadDecoderTest<GoAwayPayloadDecoder, |
| 72 GoAwayPayloadDecoderPeer, | 71 GoAwayPayloadDecoderPeer, |
| 73 Listener> { | 72 Listener> {}; |
| 74 public: | |
| 75 static bool ApproveSizeForTruncated(size_t size) { | |
| 76 return size != Http2GoAwayFields::EncodedSize(); | |
| 77 } | |
| 78 }; | |
| 79 | 73 |
| 80 // Confirm we get an error if the payload is not long enough to hold | 74 // Confirm we get an error if the payload is not long enough to hold |
| 81 // Http2GoAwayFields. | 75 // Http2GoAwayFields. |
| 82 TEST_F(GoAwayPayloadDecoderTest, Truncated) { | 76 TEST_F(GoAwayPayloadDecoderTest, Truncated) { |
| 77 auto approve_size = [](size_t size) { |
| 78 return size != Http2GoAwayFields::EncodedSize(); |
| 79 }; |
| 83 Http2FrameBuilder fb; | 80 Http2FrameBuilder fb; |
| 84 fb.Append(Http2GoAwayFields(123, Http2ErrorCode::ENHANCE_YOUR_CALM)); | 81 fb.Append(Http2GoAwayFields(123, Http2ErrorCode::ENHANCE_YOUR_CALM)); |
| 85 EXPECT_TRUE(VerifyDetectsFrameSizeError( | 82 EXPECT_TRUE(VerifyDetectsFrameSizeError(0, fb.buffer(), approve_size)); |
| 86 0, fb.buffer(), | |
| 87 base::Bind(&GoAwayPayloadDecoderTest::ApproveSizeForTruncated))); | |
| 88 } | 83 } |
| 89 | 84 |
| 90 class GoAwayOpaqueDataLengthTests | 85 class GoAwayOpaqueDataLengthTests |
| 91 : public GoAwayPayloadDecoderTest, | 86 : public GoAwayPayloadDecoderTest, |
| 92 public ::testing::WithParamInterface<uint32_t> { | 87 public ::testing::WithParamInterface<uint32_t> { |
| 93 protected: | 88 protected: |
| 94 GoAwayOpaqueDataLengthTests() : length_(GetParam()) { | 89 GoAwayOpaqueDataLengthTests() : length_(GetParam()) { |
| 95 VLOG(1) << "################ length_=" << length_ << " ################"; | 90 VLOG(1) << "################ length_=" << length_ << " ################"; |
| 96 } | 91 } |
| 97 | 92 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 113 RandStreamId()); | 108 RandStreamId()); |
| 114 set_frame_header(header); | 109 set_frame_header(header); |
| 115 FrameParts expected(header, opaque_data); | 110 FrameParts expected(header, opaque_data); |
| 116 expected.opt_goaway = goaway; | 111 expected.opt_goaway = goaway; |
| 117 ASSERT_TRUE(DecodePayloadAndValidateSeveralWays(fb.buffer(), expected)); | 112 ASSERT_TRUE(DecodePayloadAndValidateSeveralWays(fb.buffer(), expected)); |
| 118 } | 113 } |
| 119 | 114 |
| 120 } // namespace | 115 } // namespace |
| 121 } // namespace test | 116 } // namespace test |
| 122 } // namespace net | 117 } // namespace net |
| OLD | NEW |