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

Side by Side Diff: net/quic/quic_packet_creator_test.cc

Issue 1904213002: QUIC: support diversified keys with version 33. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hkdf
Patch Set: Rebase Created 4 years, 8 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 unified diff | Download patch
« no previous file with comments | « net/quic/quic_packet_creator.cc ('k') | net/quic/quic_packet_generator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/quic/quic_packet_creator.h" 5 #include "net/quic/quic_packet_creator.h"
6 6
7 #include <cstdint> 7 #include <cstdint>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 } 55 }
56 56
57 QuicVersion version; 57 QuicVersion version;
58 QuicConnectionIdLength connection_id_length; 58 QuicConnectionIdLength connection_id_length;
59 bool version_serialization; 59 bool version_serialization;
60 }; 60 };
61 61
62 // Constructs various test permutations. 62 // Constructs various test permutations.
63 vector<TestParams> GetTestParams() { 63 vector<TestParams> GetTestParams() {
64 vector<TestParams> params; 64 vector<TestParams> params;
65 QuicConnectionIdLength max = PACKET_8BYTE_CONNECTION_ID; 65 constexpr QuicConnectionIdLength kMax = PACKET_8BYTE_CONNECTION_ID;
66 QuicVersionVector all_supported_versions = QuicSupportedVersions(); 66 QuicVersionVector all_supported_versions = QuicSupportedVersions();
67 for (size_t i = 0; i < all_supported_versions.size(); ++i) { 67 for (size_t i = 0; i < all_supported_versions.size(); ++i) {
68 params.push_back(TestParams(all_supported_versions[i], true, max)); 68 params.push_back(TestParams(all_supported_versions[i], true, kMax));
69 params.push_back(TestParams(all_supported_versions[i], false, max)); 69 params.push_back(TestParams(all_supported_versions[i], false, kMax));
70 } 70 }
71 params.push_back( 71 params.push_back(
72 TestParams(all_supported_versions[0], true, PACKET_0BYTE_CONNECTION_ID)); 72 TestParams(all_supported_versions[0], true, PACKET_0BYTE_CONNECTION_ID));
73 params.push_back( 73 params.push_back(TestParams(all_supported_versions[0], true, kMax));
74 TestParams(all_supported_versions[0], true, PACKET_1BYTE_CONNECTION_ID));
75 params.push_back(
76 TestParams(all_supported_versions[0], true, PACKET_4BYTE_CONNECTION_ID));
77 params.push_back(TestParams(all_supported_versions[0], true, max));
78 return params; 74 return params;
79 } 75 }
80 76
81 class MockDelegate : public QuicPacketCreator::DelegateInterface { 77 class MockDelegate : public QuicPacketCreator::DelegateInterface {
82 public: 78 public:
83 MockDelegate() {} 79 MockDelegate() {}
84 ~MockDelegate() override {} 80 ~MockDelegate() override {}
85 81
86 MOCK_METHOD1(OnSerializedPacket, void(SerializedPacket* packet)); 82 MOCK_METHOD1(OnSerializedPacket, void(SerializedPacket* packet));
87 MOCK_METHOD3(OnUnrecoverableError, 83 MOCK_METHOD3(OnUnrecoverableError,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 frame.stream_frame->frame_length)); 174 frame.stream_frame->frame_length));
179 EXPECT_EQ(offset, frame.stream_frame->offset); 175 EXPECT_EQ(offset, frame.stream_frame->offset);
180 EXPECT_EQ(fin, frame.stream_frame->fin); 176 EXPECT_EQ(fin, frame.stream_frame->fin);
181 } 177 }
182 178
183 // Returns the number of bytes consumed by the header of packet, including 179 // Returns the number of bytes consumed by the header of packet, including
184 // the version. 180 // the version.
185 size_t GetPacketHeaderOverhead() { 181 size_t GetPacketHeaderOverhead() {
186 return GetPacketHeaderSize( 182 return GetPacketHeaderSize(
187 creator_.connection_id_length(), kIncludeVersion, !kIncludePathId, 183 creator_.connection_id_length(), kIncludeVersion, !kIncludePathId,
184 !kIncludeDiversificationNonce,
188 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); 185 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_));
189 } 186 }
190 187
191 // Returns the number of bytes of overhead that will be added to a packet 188 // Returns the number of bytes of overhead that will be added to a packet
192 // of maximum length. 189 // of maximum length.
193 size_t GetEncryptionOverhead() { 190 size_t GetEncryptionOverhead() {
194 return creator_.max_packet_length() - 191 return creator_.max_packet_length() -
195 client_framer_.GetMaxPlaintextSize(creator_.max_packet_length()); 192 client_framer_.GetMaxPlaintextSize(creator_.max_packet_length());
196 } 193 }
197 194
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 TEST_P(QuicPacketCreatorTest, ConsumeDataLargerThanOneStreamFrame) { 809 TEST_P(QuicPacketCreatorTest, ConsumeDataLargerThanOneStreamFrame) {
813 if (!GetParam().version_serialization) { 810 if (!GetParam().version_serialization) {
814 creator_.StopSendingVersion(); 811 creator_.StopSendingVersion();
815 } 812 }
816 // A string larger than fits into a frame. 813 // A string larger than fits into a frame.
817 size_t payload_length; 814 size_t payload_length;
818 creator_.SetMaxPacketLength(GetPacketLengthForOneStream( 815 creator_.SetMaxPacketLength(GetPacketLengthForOneStream(
819 client_framer_.version(), 816 client_framer_.version(),
820 QuicPacketCreatorPeer::SendVersionInPacket(&creator_), 817 QuicPacketCreatorPeer::SendVersionInPacket(&creator_),
821 QuicPacketCreatorPeer::SendPathIdInPacket(&creator_), 818 QuicPacketCreatorPeer::SendPathIdInPacket(&creator_),
822 creator_.connection_id_length(), PACKET_1BYTE_PACKET_NUMBER, 819 !kIncludeDiversificationNonce, creator_.connection_id_length(),
823 &payload_length)); 820 PACKET_1BYTE_PACKET_NUMBER, &payload_length));
824 QuicFrame frame; 821 QuicFrame frame;
825 const string too_long_payload(payload_length * 2, 'a'); 822 const string too_long_payload(payload_length * 2, 'a');
826 QuicIOVector io_vector(MakeIOVector(too_long_payload)); 823 QuicIOVector io_vector(MakeIOVector(too_long_payload));
827 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 824 EXPECT_CALL(delegate_, OnSerializedPacket(_))
828 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); 825 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
829 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, true, false, &frame)); 826 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, true, false, &frame));
830 ASSERT_TRUE(frame.stream_frame); 827 ASSERT_TRUE(frame.stream_frame);
831 size_t consumed = frame.stream_frame->frame_length; 828 size_t consumed = frame.stream_frame->frame_length;
832 EXPECT_EQ(payload_length, consumed); 829 EXPECT_EQ(payload_length, consumed);
833 const string payload(payload_length, 'a'); 830 const string payload(payload_length, 'a');
834 CheckStreamFrame(frame, 1u, payload, 0u, false); 831 CheckStreamFrame(frame, 1u, payload, 0u, false);
835 creator_.Flush(); 832 creator_.Flush();
836 DeleteSerializedPacket(); 833 DeleteSerializedPacket();
837 } 834 }
838 835
839 TEST_P(QuicPacketCreatorTest, AddFrameAndFlush) { 836 TEST_P(QuicPacketCreatorTest, AddFrameAndFlush) {
840 if (!GetParam().version_serialization) { 837 if (!GetParam().version_serialization) {
841 creator_.StopSendingVersion(); 838 creator_.StopSendingVersion();
842 } 839 }
843 const size_t max_plaintext_size = 840 const size_t max_plaintext_size =
844 client_framer_.GetMaxPlaintextSize(creator_.max_packet_length()); 841 client_framer_.GetMaxPlaintextSize(creator_.max_packet_length());
845 EXPECT_FALSE(creator_.HasPendingFrames()); 842 EXPECT_FALSE(creator_.HasPendingFrames());
846 EXPECT_EQ(max_plaintext_size - 843 EXPECT_EQ(max_plaintext_size -
847 GetPacketHeaderSize( 844 GetPacketHeaderSize(
848 creator_.connection_id_length(), 845 creator_.connection_id_length(),
849 QuicPacketCreatorPeer::SendVersionInPacket(&creator_), 846 QuicPacketCreatorPeer::SendVersionInPacket(&creator_),
850 QuicPacketCreatorPeer::SendPathIdInPacket(&creator_), 847 QuicPacketCreatorPeer::SendPathIdInPacket(&creator_),
851 PACKET_1BYTE_PACKET_NUMBER), 848 !kIncludeDiversificationNonce, PACKET_1BYTE_PACKET_NUMBER),
852 creator_.BytesFree()); 849 creator_.BytesFree());
853 850
854 // Add a variety of frame types and then a padding frame. 851 // Add a variety of frame types and then a padding frame.
855 QuicAckFrame ack_frame(MakeAckFrame(0u)); 852 QuicAckFrame ack_frame(MakeAckFrame(0u));
856 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&ack_frame))); 853 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&ack_frame)));
857 EXPECT_TRUE(creator_.HasPendingFrames()); 854 EXPECT_TRUE(creator_.HasPendingFrames());
858 855
859 QuicFrame frame; 856 QuicFrame frame;
860 QuicIOVector io_vector(MakeIOVector("test")); 857 QuicIOVector io_vector(MakeIOVector("test"));
861 ASSERT_TRUE( 858 ASSERT_TRUE(
(...skipping 20 matching lines...) Expand all
882 ASSERT_EQ(1u, retransmittable.size()); 879 ASSERT_EQ(1u, retransmittable.size());
883 EXPECT_EQ(STREAM_FRAME, retransmittable[0].type); 880 EXPECT_EQ(STREAM_FRAME, retransmittable[0].type);
884 ASSERT_TRUE(retransmittable[0].stream_frame); 881 ASSERT_TRUE(retransmittable[0].stream_frame);
885 DeleteSerializedPacket(); 882 DeleteSerializedPacket();
886 883
887 EXPECT_FALSE(creator_.HasPendingFrames()); 884 EXPECT_FALSE(creator_.HasPendingFrames());
888 EXPECT_EQ(max_plaintext_size - 885 EXPECT_EQ(max_plaintext_size -
889 GetPacketHeaderSize( 886 GetPacketHeaderSize(
890 creator_.connection_id_length(), 887 creator_.connection_id_length(),
891 QuicPacketCreatorPeer::SendVersionInPacket(&creator_), 888 QuicPacketCreatorPeer::SendVersionInPacket(&creator_),
892 /*include_path_id=*/false, PACKET_1BYTE_PACKET_NUMBER), 889 /*include_path_id=*/false, !kIncludeDiversificationNonce,
890 PACKET_1BYTE_PACKET_NUMBER),
893 creator_.BytesFree()); 891 creator_.BytesFree());
894 } 892 }
895 893
896 TEST_P(QuicPacketCreatorTest, SerializeTruncatedAckFrameWithLargePacketSize) { 894 TEST_P(QuicPacketCreatorTest, SerializeTruncatedAckFrameWithLargePacketSize) {
897 if (!GetParam().version_serialization) { 895 if (!GetParam().version_serialization) {
898 creator_.StopSendingVersion(); 896 creator_.StopSendingVersion();
899 } 897 }
900 creator_.SetMaxPacketLength(kMaxPacketSize); 898 creator_.SetMaxPacketLength(kMaxPacketSize);
901 899
902 // Serialized length of ack frame with 2000 nack ranges should be limited by 900 // Serialized length of ack frame with 2000 nack ranges should be limited by
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 EXPECT_CALL(delegate_, OnUnrecoverableError(_, _, _)); 1140 EXPECT_CALL(delegate_, OnUnrecoverableError(_, _, _));
1143 QuicStreamFrame stream_frame(kHeadersStreamId, /*fin=*/false, 0u, 1141 QuicStreamFrame stream_frame(kHeadersStreamId, /*fin=*/false, 0u,
1144 StringPiece()); 1142 StringPiece());
1145 EXPECT_DFATAL(creator_.AddSavedFrame(QuicFrame(&stream_frame)), 1143 EXPECT_DFATAL(creator_.AddSavedFrame(QuicFrame(&stream_frame)),
1146 "Cannot send stream data without encryption."); 1144 "Cannot send stream data without encryption.");
1147 } 1145 }
1148 1146
1149 } // namespace 1147 } // namespace
1150 } // namespace test 1148 } // namespace test
1151 } // namespace net 1149 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_packet_creator.cc ('k') | net/quic/quic_packet_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698