| 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/quic_crypto_server_stream.h" | 5 #include "net/quic/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 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 server_crypto_config_.SetStrikeRegisterClient(strike_register_client_); | 95 server_crypto_config_.SetStrikeRegisterClient(strike_register_client_); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 ~QuicCryptoServerStreamTest() override { | 99 ~QuicCryptoServerStreamTest() override { |
| 100 // Ensure that anything that might reference |helpers_| is destroyed before | 100 // Ensure that anything that might reference |helpers_| is destroyed before |
| 101 // |helpers_| is destroyed. | 101 // |helpers_| is destroyed. |
| 102 server_session_.reset(); | 102 server_session_.reset(); |
| 103 client_session_.reset(); | 103 client_session_.reset(); |
| 104 STLDeleteElements(&helpers_); | 104 STLDeleteElements(&helpers_); |
| 105 STLDeleteElements(&alarm_factories_); |
| 105 } | 106 } |
| 106 | 107 |
| 107 // Initializes the crypto server stream state for testing. May be | 108 // Initializes the crypto server stream state for testing. May be |
| 108 // called multiple times. | 109 // called multiple times. |
| 109 void InitializeServer() { | 110 void InitializeServer() { |
| 110 TestQuicSpdyServerSession* server_session = nullptr; | 111 TestQuicSpdyServerSession* server_session = nullptr; |
| 111 helpers_.push_back(new MockConnectionHelper); | 112 helpers_.push_back(new MockConnectionHelper); |
| 113 alarm_factories_.push_back(new MockAlarmFactory); |
| 112 CreateServerSessionForTest( | 114 CreateServerSessionForTest( |
| 113 server_id_, QuicTime::Delta::FromSeconds(100000), supported_versions_, | 115 server_id_, QuicTime::Delta::FromSeconds(100000), supported_versions_, |
| 114 helpers_.back(), &server_crypto_config_, | 116 helpers_.back(), alarm_factories_.back(), &server_crypto_config_, |
| 115 &server_compressed_certs_cache_, &server_connection_, &server_session); | 117 &server_compressed_certs_cache_, &server_connection_, &server_session); |
| 116 CHECK(server_session); | 118 CHECK(server_session); |
| 117 server_session_.reset(server_session); | 119 server_session_.reset(server_session); |
| 118 CryptoTestUtils::FakeServerOptions options; | 120 CryptoTestUtils::FakeServerOptions options; |
| 119 options.token_binding_enabled = true; | 121 options.token_binding_enabled = true; |
| 120 CryptoTestUtils::SetupCryptoServerConfigForTest( | 122 CryptoTestUtils::SetupCryptoServerConfigForTest( |
| 121 server_connection_->clock(), server_connection_->random_generator(), | 123 server_connection_->clock(), server_connection_->random_generator(), |
| 122 server_session_->config(), &server_crypto_config_, options); | 124 server_session_->config(), &server_crypto_config_, options); |
| 123 } | 125 } |
| 124 | 126 |
| 125 QuicCryptoServerStream* server_stream() { | 127 QuicCryptoServerStream* server_stream() { |
| 126 return server_session_->GetCryptoStream(); | 128 return server_session_->GetCryptoStream(); |
| 127 } | 129 } |
| 128 | 130 |
| 129 QuicCryptoClientStream* client_stream() { | 131 QuicCryptoClientStream* client_stream() { |
| 130 return client_session_->GetCryptoStream(); | 132 return client_session_->GetCryptoStream(); |
| 131 } | 133 } |
| 132 | 134 |
| 133 // Initializes a fake client, and all its associated state, for | 135 // Initializes a fake client, and all its associated state, for |
| 134 // testing. May be called multiple times. | 136 // testing. May be called multiple times. |
| 135 void InitializeFakeClient(bool supports_stateless_rejects) { | 137 void InitializeFakeClient(bool supports_stateless_rejects) { |
| 136 TestQuicSpdyClientSession* client_session = nullptr; | 138 TestQuicSpdyClientSession* client_session = nullptr; |
| 137 helpers_.push_back(new MockConnectionHelper); | 139 helpers_.push_back(new MockConnectionHelper); |
| 138 CreateClientSessionForTest(server_id_, supports_stateless_rejects, | 140 alarm_factories_.push_back(new MockAlarmFactory); |
| 139 QuicTime::Delta::FromSeconds(100000), | 141 CreateClientSessionForTest( |
| 140 supported_versions_, | 142 server_id_, supports_stateless_rejects, |
| 143 QuicTime::Delta::FromSeconds(100000), supported_versions_, |
| 141 | 144 |
| 142 helpers_.back(), &client_crypto_config_, | 145 helpers_.back(), alarm_factories_.back(), &client_crypto_config_, |
| 143 &client_connection_, &client_session); | 146 &client_connection_, &client_session); |
| 144 CHECK(client_session); | 147 CHECK(client_session); |
| 145 client_session_.reset(client_session); | 148 client_session_.reset(client_session); |
| 146 } | 149 } |
| 147 | 150 |
| 148 bool AsyncStrikeRegisterVerification() { | 151 bool AsyncStrikeRegisterVerification() { |
| 149 if (server_connection_->version() > QUIC_VERSION_32) { | 152 if (server_connection_->version() > QUIC_VERSION_32) { |
| 150 return false; | 153 return false; |
| 151 } | 154 } |
| 152 return GetParam(); | 155 return GetParam(); |
| 153 } | 156 } |
| 154 | 157 |
| 155 void ConstructHandshakeMessage() { | 158 void ConstructHandshakeMessage() { |
| 156 CryptoFramer framer; | 159 CryptoFramer framer; |
| 157 message_data_.reset(framer.ConstructHandshakeMessage(message_)); | 160 message_data_.reset(framer.ConstructHandshakeMessage(message_)); |
| 158 } | 161 } |
| 159 | 162 |
| 160 int CompleteCryptoHandshake() { | 163 int CompleteCryptoHandshake() { |
| 161 CHECK(server_connection_); | 164 CHECK(server_connection_); |
| 162 CHECK(server_session_ != nullptr); | 165 CHECK(server_session_ != nullptr); |
| 163 return CryptoTestUtils::HandshakeWithFakeClient( | 166 return CryptoTestUtils::HandshakeWithFakeClient( |
| 164 helpers_.back(), server_connection_, server_stream(), server_id_, | 167 helpers_.back(), alarm_factories_.back(), server_connection_, |
| 165 client_options_); | 168 server_stream(), server_id_, client_options_); |
| 166 } | 169 } |
| 167 | 170 |
| 168 // Performs a single round of handshake message-exchange between the | 171 // Performs a single round of handshake message-exchange between the |
| 169 // client and server. | 172 // client and server. |
| 170 void AdvanceHandshakeWithFakeClient() { | 173 void AdvanceHandshakeWithFakeClient() { |
| 171 CHECK(server_connection_); | 174 CHECK(server_connection_); |
| 172 CHECK(client_session_ != nullptr); | 175 CHECK(client_session_ != nullptr); |
| 173 | 176 |
| 174 EXPECT_CALL(*client_session_, OnProofValid(_)).Times(testing::AnyNumber()); | 177 EXPECT_CALL(*client_session_, OnProofValid(_)).Times(testing::AnyNumber()); |
| 175 client_stream()->CryptoConnect(); | 178 client_stream()->CryptoConnect(); |
| 176 CryptoTestUtils::AdvanceHandshake(client_connection_, client_stream(), 0, | 179 CryptoTestUtils::AdvanceHandshake(client_connection_, client_stream(), 0, |
| 177 server_connection_, server_stream(), 0); | 180 server_connection_, server_stream(), 0); |
| 178 } | 181 } |
| 179 | 182 |
| 180 protected: | 183 protected: |
| 181 // Every connection gets its own MockConnectionHelper, tracked separately | 184 // Every connection gets its own MockConnectionHelper and MockAlarmFactory, |
| 182 // from the server and client state so their lifetimes persist through the | 185 // tracked separately from |
| 183 // whole test. | 186 // the server and client state so their lifetimes persist through the whole |
| 187 // test. |
| 184 std::vector<MockConnectionHelper*> helpers_; | 188 std::vector<MockConnectionHelper*> helpers_; |
| 189 std::vector<MockAlarmFactory*> alarm_factories_; |
| 185 | 190 |
| 186 // Server state | 191 // Server state |
| 187 PacketSavingConnection* server_connection_; | 192 PacketSavingConnection* server_connection_; |
| 188 std::unique_ptr<TestQuicSpdyServerSession> server_session_; | 193 std::unique_ptr<TestQuicSpdyServerSession> server_session_; |
| 189 QuicCryptoServerConfig server_crypto_config_; | 194 QuicCryptoServerConfig server_crypto_config_; |
| 190 QuicCompressedCertsCache server_compressed_certs_cache_; | 195 QuicCompressedCertsCache server_compressed_certs_cache_; |
| 191 QuicServerId server_id_; | 196 QuicServerId server_id_; |
| 192 | 197 |
| 193 // Client state | 198 // Client state |
| 194 PacketSavingConnection* client_connection_; | 199 PacketSavingConnection* client_connection_; |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 QUIC_NO_ERROR, "", ConnectionCloseBehavior::SILENT_CLOSE); | 527 QUIC_NO_ERROR, "", ConnectionCloseBehavior::SILENT_CLOSE); |
| 523 | 528 |
| 524 // The outstanding nonce verification RPC now completes. | 529 // The outstanding nonce verification RPC now completes. |
| 525 strike_register_client_->RunPendingVerifications(); | 530 strike_register_client_->RunPendingVerifications(); |
| 526 } | 531 } |
| 527 | 532 |
| 528 } // namespace | 533 } // namespace |
| 529 | 534 |
| 530 } // namespace test | 535 } // namespace test |
| 531 } // namespace net | 536 } // namespace net |
| OLD | NEW |