OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/tools/quic/chlo_extractor.h" | 5 #include "net/tools/quic/chlo_extractor.h" |
6 | 6 |
7 #include "net/quic/core/quic_framer.h" | 7 #include "net/quic/core/quic_framer.h" |
8 #include "net/quic/test_tools/crypto_test_utils.h" | 8 #include "net/quic/test_tools/crypto_test_utils.h" |
9 #include "net/quic/test_tools/quic_test_utils.h" | 9 #include "net/quic/test_tools/quic_test_utils.h" |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 string chlo_; | 41 string chlo_; |
42 }; | 42 }; |
43 | 43 |
44 class ChloExtractorTest : public ::testing::Test { | 44 class ChloExtractorTest : public ::testing::Test { |
45 public: | 45 public: |
46 ChloExtractorTest() { | 46 ChloExtractorTest() { |
47 header_.public_header.connection_id = 42; | 47 header_.public_header.connection_id = 42; |
48 header_.public_header.connection_id_length = PACKET_8BYTE_CONNECTION_ID; | 48 header_.public_header.connection_id_length = PACKET_8BYTE_CONNECTION_ID; |
49 header_.public_header.version_flag = true; | 49 header_.public_header.version_flag = true; |
50 header_.public_header.versions = | 50 header_.public_header.versions = |
51 SupportedVersions(QuicSupportedVersions().front()); | 51 SupportedVersions(AllSupportedVersions().front()); |
52 header_.public_header.reset_flag = false; | 52 header_.public_header.reset_flag = false; |
53 header_.public_header.packet_number_length = PACKET_6BYTE_PACKET_NUMBER; | 53 header_.public_header.packet_number_length = PACKET_6BYTE_PACKET_NUMBER; |
54 header_.packet_number = 1; | 54 header_.packet_number = 1; |
55 header_.entropy_flag = false; | 55 header_.entropy_flag = false; |
56 header_.entropy_hash = 0; | 56 header_.entropy_hash = 0; |
57 } | 57 } |
58 | 58 |
59 void MakePacket(QuicStreamFrame* stream_frame) { | 59 void MakePacket(QuicStreamFrame* stream_frame) { |
60 QuicFrame frame(stream_frame); | 60 QuicFrame frame(stream_frame); |
61 QuicFrames frames; | 61 QuicFrames frames; |
(...skipping 19 matching lines...) Expand all Loading... |
81 char buffer_[kMaxPacketSize]; | 81 char buffer_[kMaxPacketSize]; |
82 }; | 82 }; |
83 | 83 |
84 TEST_F(ChloExtractorTest, FindsValidChlo) { | 84 TEST_F(ChloExtractorTest, FindsValidChlo) { |
85 CryptoHandshakeMessage client_hello; | 85 CryptoHandshakeMessage client_hello; |
86 client_hello.set_tag(kCHLO); | 86 client_hello.set_tag(kCHLO); |
87 | 87 |
88 string client_hello_str( | 88 string client_hello_str( |
89 client_hello.GetSerialized().AsStringPiece().as_string()); | 89 client_hello.GetSerialized().AsStringPiece().as_string()); |
90 // Construct a CHLO with each supported version | 90 // Construct a CHLO with each supported version |
91 for (QuicVersion version : QuicSupportedVersions()) { | 91 for (QuicVersion version : AllSupportedVersions()) { |
92 QuicVersionVector versions(SupportedVersions(version)); | 92 QuicVersionVector versions(SupportedVersions(version)); |
93 header_.public_header.versions = versions; | 93 header_.public_header.versions = versions; |
94 MakePacket( | 94 MakePacket( |
95 new QuicStreamFrame(kCryptoStreamId, false, 0, client_hello_str)); | 95 new QuicStreamFrame(kCryptoStreamId, false, 0, client_hello_str)); |
96 EXPECT_TRUE(ChloExtractor::Extract(*packet_, versions, &delegate_)) | 96 EXPECT_TRUE(ChloExtractor::Extract(*packet_, versions, &delegate_)) |
97 << QuicVersionToString(version); | 97 << QuicVersionToString(version); |
98 EXPECT_EQ(version, delegate_.version()); | 98 EXPECT_EQ(version, delegate_.version()); |
99 EXPECT_EQ(header_.public_header.connection_id, delegate_.connection_id()); | 99 EXPECT_EQ(header_.public_header.connection_id, delegate_.connection_id()); |
100 EXPECT_EQ(client_hello.DebugString(), delegate_.chlo()) | 100 EXPECT_EQ(client_hello.DebugString(), delegate_.chlo()) |
101 << QuicVersionToString(version); | 101 << QuicVersionToString(version); |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 TEST_F(ChloExtractorTest, DoesNotFindValidChloOnWrongStream) { | 105 TEST_F(ChloExtractorTest, DoesNotFindValidChloOnWrongStream) { |
106 CryptoHandshakeMessage client_hello; | 106 CryptoHandshakeMessage client_hello; |
107 client_hello.set_tag(kCHLO); | 107 client_hello.set_tag(kCHLO); |
108 | 108 |
109 string client_hello_str( | 109 string client_hello_str( |
110 client_hello.GetSerialized().AsStringPiece().as_string()); | 110 client_hello.GetSerialized().AsStringPiece().as_string()); |
111 MakePacket( | 111 MakePacket( |
112 new QuicStreamFrame(kCryptoStreamId + 1, false, 0, client_hello_str)); | 112 new QuicStreamFrame(kCryptoStreamId + 1, false, 0, client_hello_str)); |
113 EXPECT_FALSE( | 113 EXPECT_FALSE( |
114 ChloExtractor::Extract(*packet_, QuicSupportedVersions(), &delegate_)); | 114 ChloExtractor::Extract(*packet_, AllSupportedVersions(), &delegate_)); |
115 } | 115 } |
116 | 116 |
117 TEST_F(ChloExtractorTest, DoesNotFindValidChloOnWrongOffset) { | 117 TEST_F(ChloExtractorTest, DoesNotFindValidChloOnWrongOffset) { |
118 CryptoHandshakeMessage client_hello; | 118 CryptoHandshakeMessage client_hello; |
119 client_hello.set_tag(kCHLO); | 119 client_hello.set_tag(kCHLO); |
120 | 120 |
121 string client_hello_str( | 121 string client_hello_str( |
122 client_hello.GetSerialized().AsStringPiece().as_string()); | 122 client_hello.GetSerialized().AsStringPiece().as_string()); |
123 MakePacket(new QuicStreamFrame(kCryptoStreamId, false, 1, client_hello_str)); | 123 MakePacket(new QuicStreamFrame(kCryptoStreamId, false, 1, client_hello_str)); |
124 EXPECT_FALSE( | 124 EXPECT_FALSE( |
125 ChloExtractor::Extract(*packet_, QuicSupportedVersions(), &delegate_)); | 125 ChloExtractor::Extract(*packet_, AllSupportedVersions(), &delegate_)); |
126 } | 126 } |
127 | 127 |
128 TEST_F(ChloExtractorTest, DoesNotFindInvalidChlo) { | 128 TEST_F(ChloExtractorTest, DoesNotFindInvalidChlo) { |
129 MakePacket(new QuicStreamFrame(kCryptoStreamId, false, 0, "foo")); | 129 MakePacket(new QuicStreamFrame(kCryptoStreamId, false, 0, "foo")); |
130 EXPECT_FALSE( | 130 EXPECT_FALSE( |
131 ChloExtractor::Extract(*packet_, QuicSupportedVersions(), &delegate_)); | 131 ChloExtractor::Extract(*packet_, AllSupportedVersions(), &delegate_)); |
132 } | 132 } |
133 | 133 |
134 } // namespace | 134 } // namespace |
135 } // namespace test | 135 } // namespace test |
136 } // namespace net | 136 } // namespace net |
OLD | NEW |