OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/crypto/quic_crypto_client_config.h" | 5 #include "net/quic/crypto/quic_crypto_client_config.h" |
6 | 6 |
7 #include "net/quic/crypto/proof_verifier.h" | 7 #include "net/quic/crypto/proof_verifier.h" |
8 #include "net/quic/quic_session_key.h" | 8 #include "net/quic/quic_server_id.h" |
9 #include "net/quic/test_tools/mock_random.h" | 9 #include "net/quic/test_tools/mock_random.h" |
10 #include "net/quic/test_tools/quic_test_utils.h" | 10 #include "net/quic/test_tools/quic_test_utils.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 using std::string; | 13 using std::string; |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 namespace test { | 16 namespace test { |
17 | 17 |
18 TEST(QuicCryptoClientConfigTest, CachedState_IsEmpty) { | 18 TEST(QuicCryptoClientConfigTest, CachedState_IsEmpty) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 EXPECT_EQ(state.source_address_token(), other.source_address_token()); | 50 EXPECT_EQ(state.source_address_token(), other.source_address_token()); |
51 EXPECT_EQ(state.certs(), other.certs()); | 51 EXPECT_EQ(state.certs(), other.certs()); |
52 EXPECT_EQ(1u, other.generation_counter()); | 52 EXPECT_EQ(1u, other.generation_counter()); |
53 } | 53 } |
54 | 54 |
55 TEST(QuicCryptoClientConfigTest, InchoateChlo) { | 55 TEST(QuicCryptoClientConfigTest, InchoateChlo) { |
56 QuicCryptoClientConfig::CachedState state; | 56 QuicCryptoClientConfig::CachedState state; |
57 QuicCryptoClientConfig config; | 57 QuicCryptoClientConfig config; |
58 QuicCryptoNegotiatedParameters params; | 58 QuicCryptoNegotiatedParameters params; |
59 CryptoHandshakeMessage msg; | 59 CryptoHandshakeMessage msg; |
60 QuicSessionKey server_key("www.google.com", 80, false, kPrivacyModeDisabled); | 60 QuicServerId server_id("www.google.com", 80, false, kPrivacyModeDisabled); |
61 config.FillInchoateClientHello(server_key, QuicVersionMax(), &state, | 61 config.FillInchoateClientHello(server_id, QuicVersionMax(), &state, |
62 ¶ms, &msg); | 62 ¶ms, &msg); |
63 | 63 |
64 QuicTag cver; | 64 QuicTag cver; |
65 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kVER, &cver)); | 65 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kVER, &cver)); |
66 EXPECT_EQ(QuicVersionToQuicTag(QuicVersionMax()), cver); | 66 EXPECT_EQ(QuicVersionToQuicTag(QuicVersionMax()), cver); |
67 } | 67 } |
68 | 68 |
69 TEST(QuicCryptoClientConfigTest, FillClientHello) { | 69 TEST(QuicCryptoClientConfigTest, FillClientHello) { |
70 QuicCryptoClientConfig::CachedState state; | 70 QuicCryptoClientConfig::CachedState state; |
71 QuicCryptoClientConfig config; | 71 QuicCryptoClientConfig config; |
72 QuicCryptoNegotiatedParameters params; | 72 QuicCryptoNegotiatedParameters params; |
73 QuicConnectionId kConnectionId = 1234; | 73 QuicConnectionId kConnectionId = 1234; |
74 uint32 kInitialFlowControlWindow = 5678; | 74 uint32 kInitialFlowControlWindow = 5678; |
75 string error_details; | 75 string error_details; |
76 MockRandom rand; | 76 MockRandom rand; |
77 CryptoHandshakeMessage chlo; | 77 CryptoHandshakeMessage chlo; |
78 QuicSessionKey server_key("www.google.com", 80, false, kPrivacyModeDisabled); | 78 QuicServerId server_id("www.google.com", 80, false, kPrivacyModeDisabled); |
79 config.FillClientHello(server_key, | 79 config.FillClientHello(server_id, |
80 kConnectionId, | 80 kConnectionId, |
81 QuicVersionMax(), | 81 QuicVersionMax(), |
82 kInitialFlowControlWindow, | 82 kInitialFlowControlWindow, |
83 &state, | 83 &state, |
84 QuicWallTime::Zero(), | 84 QuicWallTime::Zero(), |
85 &rand, | 85 &rand, |
86 ¶ms, | 86 ¶ms, |
87 &chlo, | 87 &chlo, |
88 &error_details); | 88 &error_details); |
89 | 89 |
(...skipping 27 matching lines...) Expand all Loading... |
117 string error; | 117 string error; |
118 QuicCryptoClientConfig config; | 118 QuicCryptoClientConfig config; |
119 EXPECT_EQ(QUIC_VERSION_NEGOTIATION_MISMATCH, | 119 EXPECT_EQ(QUIC_VERSION_NEGOTIATION_MISMATCH, |
120 config.ProcessServerHello(msg, 0, supported_versions, | 120 config.ProcessServerHello(msg, 0, supported_versions, |
121 &cached, &out_params, &error)); | 121 &cached, &out_params, &error)); |
122 EXPECT_EQ("Downgrade attack detected", error); | 122 EXPECT_EQ("Downgrade attack detected", error); |
123 } | 123 } |
124 | 124 |
125 TEST(QuicCryptoClientConfigTest, InitializeFrom) { | 125 TEST(QuicCryptoClientConfigTest, InitializeFrom) { |
126 QuicCryptoClientConfig config; | 126 QuicCryptoClientConfig config; |
127 QuicSessionKey canonical_key1("www.google.com", 80, false, | 127 QuicServerId canonical_server_id("www.google.com", 80, false, |
128 kPrivacyModeDisabled); | 128 kPrivacyModeDisabled); |
129 QuicCryptoClientConfig::CachedState* state = | 129 QuicCryptoClientConfig::CachedState* state = |
130 config.LookupOrCreate(canonical_key1); | 130 config.LookupOrCreate(canonical_server_id); |
131 // TODO(rch): Populate other fields of |state|. | 131 // TODO(rch): Populate other fields of |state|. |
132 state->set_source_address_token("TOKEN"); | 132 state->set_source_address_token("TOKEN"); |
133 state->SetProofValid(); | 133 state->SetProofValid(); |
134 | 134 |
135 QuicSessionKey other_key("mail.google.com", 80, false, kPrivacyModeDisabled); | 135 QuicServerId other_server_id("mail.google.com", 80, false, |
136 config.InitializeFrom(other_key, canonical_key1, &config); | 136 kPrivacyModeDisabled); |
137 QuicCryptoClientConfig::CachedState* other = config.LookupOrCreate(other_key); | 137 config.InitializeFrom(other_server_id, canonical_server_id, &config); |
| 138 QuicCryptoClientConfig::CachedState* other = |
| 139 config.LookupOrCreate(other_server_id); |
138 | 140 |
139 EXPECT_EQ(state->server_config(), other->server_config()); | 141 EXPECT_EQ(state->server_config(), other->server_config()); |
140 EXPECT_EQ(state->source_address_token(), other->source_address_token()); | 142 EXPECT_EQ(state->source_address_token(), other->source_address_token()); |
141 EXPECT_EQ(state->certs(), other->certs()); | 143 EXPECT_EQ(state->certs(), other->certs()); |
142 EXPECT_EQ(1u, other->generation_counter()); | 144 EXPECT_EQ(1u, other->generation_counter()); |
143 } | 145 } |
144 | 146 |
145 } // namespace test | 147 } // namespace test |
146 } // namespace net | 148 } // namespace net |
OLD | NEW |