OLD | NEW |
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/core/quic_crypto_server_stream.h" | 5 #include "net/quic/core/quic_crypto_server_stream.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "net/quic/core/crypto/aes_128_gcm_12_encrypter.h" | 11 #include "net/quic/core/crypto/aes_128_gcm_12_encrypter.h" |
12 #include "net/quic/core/crypto/crypto_framer.h" | 12 #include "net/quic/core/crypto/crypto_framer.h" |
13 #include "net/quic/core/crypto/crypto_handshake.h" | 13 #include "net/quic/core/crypto/crypto_handshake.h" |
14 #include "net/quic/core/crypto/crypto_protocol.h" | 14 #include "net/quic/core/crypto/crypto_protocol.h" |
15 #include "net/quic/core/crypto/crypto_utils.h" | 15 #include "net/quic/core/crypto/crypto_utils.h" |
16 #include "net/quic/core/crypto/quic_crypto_server_config.h" | 16 #include "net/quic/core/crypto/quic_crypto_server_config.h" |
17 #include "net/quic/core/crypto/quic_decrypter.h" | 17 #include "net/quic/core/crypto/quic_decrypter.h" |
18 #include "net/quic/core/crypto/quic_encrypter.h" | 18 #include "net/quic/core/crypto/quic_encrypter.h" |
19 #include "net/quic/core/crypto/quic_random.h" | 19 #include "net/quic/core/crypto/quic_random.h" |
20 #include "net/quic/core/quic_crypto_client_stream.h" | 20 #include "net/quic/core/quic_crypto_client_stream.h" |
21 #include "net/quic/core/quic_packets.h" | 21 #include "net/quic/core/quic_packets.h" |
22 #include "net/quic/core/quic_session.h" | 22 #include "net/quic/core/quic_session.h" |
23 #include "net/quic/platform/api/quic_flags.h" | 23 #include "net/quic/platform/api/quic_flags.h" |
24 #include "net/quic/platform/api/quic_logging.h" | 24 #include "net/quic/platform/api/quic_logging.h" |
25 #include "net/quic/platform/api/quic_ptr_util.h" | 25 #include "net/quic/platform/api/quic_ptr_util.h" |
26 #include "net/quic/platform/api/quic_socket_address.h" | 26 #include "net/quic/platform/api/quic_socket_address.h" |
| 27 #include "net/quic/platform/api/quic_test.h" |
27 #include "net/quic/test_tools/crypto_test_utils.h" | 28 #include "net/quic/test_tools/crypto_test_utils.h" |
28 #include "net/quic/test_tools/failing_proof_source.h" | 29 #include "net/quic/test_tools/failing_proof_source.h" |
29 #include "net/quic/test_tools/fake_proof_source.h" | 30 #include "net/quic/test_tools/fake_proof_source.h" |
30 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" | 31 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" |
31 #include "net/quic/test_tools/quic_test_utils.h" | 32 #include "net/quic/test_tools/quic_test_utils.h" |
32 #include "testing/gmock/include/gmock/gmock.h" | |
33 #include "testing/gtest/include/gtest/gtest.h" | |
34 | 33 |
35 namespace net { | 34 namespace net { |
36 class QuicConnection; | 35 class QuicConnection; |
37 class QuicStream; | 36 class QuicStream; |
38 } // namespace net | 37 } // namespace net |
39 | 38 |
40 using std::string; | 39 using std::string; |
41 using testing::_; | 40 using testing::_; |
42 | 41 |
43 namespace net { | 42 namespace net { |
44 namespace test { | 43 namespace test { |
45 | 44 |
46 class QuicCryptoServerStreamPeer { | 45 class QuicCryptoServerStreamPeer { |
47 public: | 46 public: |
48 static bool DoesPeerSupportStatelessRejects( | 47 static bool DoesPeerSupportStatelessRejects( |
49 const CryptoHandshakeMessage& message) { | 48 const CryptoHandshakeMessage& message) { |
50 return net::QuicCryptoServerStream::DoesPeerSupportStatelessRejects( | 49 return net::QuicCryptoServerStream::DoesPeerSupportStatelessRejects( |
51 message); | 50 message); |
52 } | 51 } |
53 }; | 52 }; |
54 | 53 |
55 namespace { | 54 namespace { |
56 | 55 |
57 const char kServerHostname[] = "test.example.com"; | 56 const char kServerHostname[] = "test.example.com"; |
58 const uint16_t kServerPort = 443; | 57 const uint16_t kServerPort = 443; |
59 | 58 |
60 class QuicCryptoServerStreamTest : public ::testing::TestWithParam<bool> { | 59 class QuicCryptoServerStreamTest : public QuicTestWithParam<bool> { |
61 public: | 60 public: |
62 QuicCryptoServerStreamTest() | 61 QuicCryptoServerStreamTest() |
63 : QuicCryptoServerStreamTest(crypto_test_utils::ProofSourceForTesting()) { | 62 : QuicCryptoServerStreamTest(crypto_test_utils::ProofSourceForTesting()) { |
64 } | 63 } |
65 | 64 |
66 explicit QuicCryptoServerStreamTest(std::unique_ptr<ProofSource> proof_source) | 65 explicit QuicCryptoServerStreamTest(std::unique_ptr<ProofSource> proof_source) |
67 : server_crypto_config_(QuicCryptoServerConfig::TESTING, | 66 : server_crypto_config_(QuicCryptoServerConfig::TESTING, |
68 QuicRandom::GetInstance(), | 67 QuicRandom::GetInstance(), |
69 std::move(proof_source)), | 68 std::move(proof_source)), |
70 server_compressed_certs_cache_( | 69 server_compressed_certs_cache_( |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 CHECK(server_connection_); | 147 CHECK(server_connection_); |
149 CHECK(client_session_ != nullptr); | 148 CHECK(client_session_ != nullptr); |
150 | 149 |
151 EXPECT_CALL(*client_session_, OnProofValid(_)).Times(testing::AnyNumber()); | 150 EXPECT_CALL(*client_session_, OnProofValid(_)).Times(testing::AnyNumber()); |
152 client_stream()->CryptoConnect(); | 151 client_stream()->CryptoConnect(); |
153 crypto_test_utils::AdvanceHandshake(client_connection_, client_stream(), 0, | 152 crypto_test_utils::AdvanceHandshake(client_connection_, client_stream(), 0, |
154 server_connection_, server_stream(), 0); | 153 server_connection_, server_stream(), 0); |
155 } | 154 } |
156 | 155 |
157 protected: | 156 protected: |
158 QuicFlagSaver flags_; // Save/restore all QUIC flag values. | |
159 | |
160 // Every connection gets its own MockQuicConnectionHelper and | 157 // Every connection gets its own MockQuicConnectionHelper and |
161 // MockAlarmFactory, tracked separately from the server and client state so | 158 // MockAlarmFactory, tracked separately from the server and client state so |
162 // their lifetimes persist through the whole test. | 159 // their lifetimes persist through the whole test. |
163 std::vector<std::unique_ptr<MockQuicConnectionHelper>> helpers_; | 160 std::vector<std::unique_ptr<MockQuicConnectionHelper>> helpers_; |
164 std::vector<std::unique_ptr<MockAlarmFactory>> alarm_factories_; | 161 std::vector<std::unique_ptr<MockAlarmFactory>> alarm_factories_; |
165 | 162 |
166 // Server state. | 163 // Server state. |
167 PacketSavingConnection* server_connection_; | 164 PacketSavingConnection* server_connection_; |
168 std::unique_ptr<TestQuicSpdyServerSession> server_session_; | 165 std::unique_ptr<TestQuicSpdyServerSession> server_session_; |
169 QuicCryptoServerConfig server_crypto_config_; | 166 QuicCryptoServerConfig server_crypto_config_; |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 EXPECT_CALL( | 553 EXPECT_CALL( |
557 *server_connection_, | 554 *server_connection_, |
558 CloseConnection(QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO, | 555 CloseConnection(QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO, |
559 "Unexpected handshake message while processing CHLO", _)); | 556 "Unexpected handshake message while processing CHLO", _)); |
560 server_stream()->OnHandshakeMessage(chlo); | 557 server_stream()->OnHandshakeMessage(chlo); |
561 } | 558 } |
562 | 559 |
563 } // namespace | 560 } // namespace |
564 } // namespace test | 561 } // namespace test |
565 } // namespace net | 562 } // namespace net |
OLD | NEW |