| 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 <memory> | 5 #include <memory> |
| 6 #include <ostream> | 6 #include <ostream> |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 namespace test { | 50 namespace test { |
| 51 | 51 |
| 52 namespace { | 52 namespace { |
| 53 | 53 |
| 54 const char kResponseBody[] = "some arbitrary response body"; | 54 const char kResponseBody[] = "some arbitrary response body"; |
| 55 | 55 |
| 56 // Factory for creating HttpTransactions, used by TestTransactionConsumer. | 56 // Factory for creating HttpTransactions, used by TestTransactionConsumer. |
| 57 class TestTransactionFactory : public HttpTransactionFactory { | 57 class TestTransactionFactory : public HttpTransactionFactory { |
| 58 public: | 58 public: |
| 59 explicit TestTransactionFactory(const HttpNetworkSession::Params& params) | 59 explicit TestTransactionFactory( |
| 60 : session_(new HttpNetworkSession(params)) {} | 60 const HttpNetworkSession::Params& session_params, |
| 61 const HttpNetworkSession::Context& session_context) |
| 62 : session_(new HttpNetworkSession(session_params, session_context)) {} |
| 61 | 63 |
| 62 ~TestTransactionFactory() override {} | 64 ~TestTransactionFactory() override {} |
| 63 | 65 |
| 64 // HttpTransactionFactory methods | 66 // HttpTransactionFactory methods |
| 65 int CreateTransaction(RequestPriority priority, | 67 int CreateTransaction(RequestPriority priority, |
| 66 std::unique_ptr<HttpTransaction>* trans) override { | 68 std::unique_ptr<HttpTransaction>* trans) override { |
| 67 trans->reset(new HttpNetworkTransaction(priority, session_.get())); | 69 trans->reset(new HttpNetworkTransaction(priority, session_.get())); |
| 68 return OK; | 70 return OK; |
| 69 } | 71 } |
| 70 | 72 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 101 cert_transparency_verifier_(new MultiLogCTVerifier()), | 103 cert_transparency_verifier_(new MultiLogCTVerifier()), |
| 102 ssl_config_service_(new SSLConfigServiceDefaults), | 104 ssl_config_service_(new SSLConfigServiceDefaults), |
| 103 proxy_service_(ProxyService::CreateDirect()), | 105 proxy_service_(ProxyService::CreateDirect()), |
| 104 auth_handler_factory_( | 106 auth_handler_factory_( |
| 105 HttpAuthHandlerFactory::CreateDefault(&host_resolver_)), | 107 HttpAuthHandlerFactory::CreateDefault(&host_resolver_)), |
| 106 strike_register_no_startup_period_(false) { | 108 strike_register_no_startup_period_(false) { |
| 107 request_.method = "GET"; | 109 request_.method = "GET"; |
| 108 request_.url = GURL("https://test.example.com/"); | 110 request_.url = GURL("https://test.example.com/"); |
| 109 request_.load_flags = 0; | 111 request_.load_flags = 0; |
| 110 | 112 |
| 111 params_.enable_quic = true; | 113 session_params_.enable_quic = true; |
| 112 params_.quic_random = nullptr; | |
| 113 if (GetParam().use_stateless_rejects) { | 114 if (GetParam().use_stateless_rejects) { |
| 114 params_.quic_connection_options.push_back(kSREJ); | 115 session_params_.quic_connection_options.push_back(kSREJ); |
| 115 } | 116 } |
| 116 params_.host_resolver = &host_resolver_; | 117 |
| 117 params_.cert_verifier = &cert_verifier_; | 118 session_context_.quic_random = nullptr; |
| 118 params_.transport_security_state = &transport_security_state_; | 119 session_context_.host_resolver = &host_resolver_; |
| 119 params_.cert_transparency_verifier = cert_transparency_verifier_.get(); | 120 session_context_.cert_verifier = &cert_verifier_; |
| 120 params_.ct_policy_enforcer = &ct_policy_enforcer_; | 121 session_context_.transport_security_state = &transport_security_state_; |
| 121 params_.proxy_service = proxy_service_.get(); | 122 session_context_.cert_transparency_verifier = |
| 122 params_.ssl_config_service = ssl_config_service_.get(); | 123 cert_transparency_verifier_.get(); |
| 123 params_.http_auth_handler_factory = auth_handler_factory_.get(); | 124 session_context_.ct_policy_enforcer = &ct_policy_enforcer_; |
| 124 params_.http_server_properties = &http_server_properties_; | 125 session_context_.proxy_service = proxy_service_.get(); |
| 126 session_context_.ssl_config_service = ssl_config_service_.get(); |
| 127 session_context_.http_auth_handler_factory = auth_handler_factory_.get(); |
| 128 session_context_.http_server_properties = &http_server_properties_; |
| 125 channel_id_service_.reset( | 129 channel_id_service_.reset( |
| 126 new ChannelIDService(new DefaultChannelIDStore(nullptr))); | 130 new ChannelIDService(new DefaultChannelIDStore(nullptr))); |
| 127 params_.channel_id_service = channel_id_service_.get(); | 131 session_context_.channel_id_service = channel_id_service_.get(); |
| 128 | 132 |
| 129 CertVerifyResult verify_result; | 133 CertVerifyResult verify_result; |
| 130 verify_result.verified_cert = ImportCertFromFile( | 134 verify_result.verified_cert = ImportCertFromFile( |
| 131 GetTestCertsDirectory(), "quic_test.example.com.crt"); | 135 GetTestCertsDirectory(), "quic_test.example.com.crt"); |
| 132 cert_verifier_.AddResultForCertAndHost(verify_result.verified_cert.get(), | 136 cert_verifier_.AddResultForCertAndHost(verify_result.verified_cert.get(), |
| 133 "test.example.com", verify_result, | 137 "test.example.com", verify_result, |
| 134 OK); | 138 OK); |
| 135 verify_result.verified_cert = ImportCertFromFile( | 139 verify_result.verified_cert = ImportCertFromFile( |
| 136 GetTestCertsDirectory(), "quic_test_ecc.example.com.crt"); | 140 GetTestCertsDirectory(), "quic_test_ecc.example.com.crt"); |
| 137 cert_verifier_.AddResultForCertAndHost(verify_result.verified_cert.get(), | 141 cert_verifier_.AddResultForCertAndHost(verify_result.verified_cert.get(), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 151 StartServer(); | 155 StartServer(); |
| 152 | 156 |
| 153 // Use a mapped host resolver so that request for test.example.com (port 80) | 157 // Use a mapped host resolver so that request for test.example.com (port 80) |
| 154 // reach the server running on localhost. | 158 // reach the server running on localhost. |
| 155 std::string map_rule = "MAP test.example.com test.example.com:" + | 159 std::string map_rule = "MAP test.example.com test.example.com:" + |
| 156 base::IntToString(server_->server_address().port()); | 160 base::IntToString(server_->server_address().port()); |
| 157 EXPECT_TRUE(host_resolver_.AddRuleFromString(map_rule)); | 161 EXPECT_TRUE(host_resolver_.AddRuleFromString(map_rule)); |
| 158 | 162 |
| 159 // To simplify the test, and avoid the race with the HTTP request, we force | 163 // To simplify the test, and avoid the race with the HTTP request, we force |
| 160 // QUIC for these requests. | 164 // QUIC for these requests. |
| 161 params_.origins_to_force_quic_on.insert( | 165 session_params_.origins_to_force_quic_on.insert( |
| 162 HostPortPair::FromString("test.example.com:443")); | 166 HostPortPair::FromString("test.example.com:443")); |
| 163 | 167 |
| 164 transaction_factory_.reset(new TestTransactionFactory(params_)); | 168 transaction_factory_.reset( |
| 169 new TestTransactionFactory(session_params_, session_context_)); |
| 165 } | 170 } |
| 166 | 171 |
| 167 void TearDown() override {} | 172 void TearDown() override {} |
| 168 | 173 |
| 169 // Starts the QUIC server listening on a random port. | 174 // Starts the QUIC server listening on a random port. |
| 170 void StartServer() { | 175 void StartServer() { |
| 171 server_address_ = IPEndPoint(IPAddress(127, 0, 0, 1), 0); | 176 server_address_ = IPEndPoint(IPAddress(127, 0, 0, 1), 0); |
| 172 server_config_.SetInitialStreamFlowControlWindowToSend( | 177 server_config_.SetInitialStreamFlowControlWindowToSend( |
| 173 kInitialStreamFlowControlWindowForTest); | 178 kInitialStreamFlowControlWindowForTest); |
| 174 server_config_.SetInitialSessionFlowControlWindowToSend( | 179 server_config_.SetInitialSessionFlowControlWindowToSend( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 MappedHostResolver host_resolver_; | 237 MappedHostResolver host_resolver_; |
| 233 MockCertVerifier cert_verifier_; | 238 MockCertVerifier cert_verifier_; |
| 234 std::unique_ptr<ChannelIDService> channel_id_service_; | 239 std::unique_ptr<ChannelIDService> channel_id_service_; |
| 235 TransportSecurityState transport_security_state_; | 240 TransportSecurityState transport_security_state_; |
| 236 std::unique_ptr<CTVerifier> cert_transparency_verifier_; | 241 std::unique_ptr<CTVerifier> cert_transparency_verifier_; |
| 237 CTPolicyEnforcer ct_policy_enforcer_; | 242 CTPolicyEnforcer ct_policy_enforcer_; |
| 238 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; | 243 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; |
| 239 std::unique_ptr<ProxyService> proxy_service_; | 244 std::unique_ptr<ProxyService> proxy_service_; |
| 240 std::unique_ptr<HttpAuthHandlerFactory> auth_handler_factory_; | 245 std::unique_ptr<HttpAuthHandlerFactory> auth_handler_factory_; |
| 241 HttpServerPropertiesImpl http_server_properties_; | 246 HttpServerPropertiesImpl http_server_properties_; |
| 242 HttpNetworkSession::Params params_; | 247 HttpNetworkSession::Params session_params_; |
| 248 HttpNetworkSession::Context session_context_; |
| 243 std::unique_ptr<TestTransactionFactory> transaction_factory_; | 249 std::unique_ptr<TestTransactionFactory> transaction_factory_; |
| 244 HttpRequestInfo request_; | 250 HttpRequestInfo request_; |
| 245 std::string request_body_; | 251 std::string request_body_; |
| 246 std::unique_ptr<UploadDataStream> upload_data_stream_; | 252 std::unique_ptr<UploadDataStream> upload_data_stream_; |
| 247 std::unique_ptr<QuicSimpleServer> server_; | 253 std::unique_ptr<QuicSimpleServer> server_; |
| 248 QuicHttpResponseCache response_cache_; | 254 QuicHttpResponseCache response_cache_; |
| 249 IPEndPoint server_address_; | 255 IPEndPoint server_address_; |
| 250 std::string server_hostname_; | 256 std::string server_hostname_; |
| 251 QuicConfig server_config_; | 257 QuicConfig server_config_; |
| 252 QuicCryptoServerConfig::ConfigOptions server_config_options_; | 258 QuicCryptoServerConfig::ConfigOptions server_config_options_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 268 consumer.Start(&request_, NetLogWithSource()); | 274 consumer.Start(&request_, NetLogWithSource()); |
| 269 | 275 |
| 270 // Will terminate when the last consumer completes. | 276 // Will terminate when the last consumer completes. |
| 271 base::RunLoop().Run(); | 277 base::RunLoop().Run(); |
| 272 | 278 |
| 273 CheckResponse(consumer, "HTTP/1.1 200", response); | 279 CheckResponse(consumer, "HTTP/1.1 200", response); |
| 274 } | 280 } |
| 275 | 281 |
| 276 TEST_P(QuicEndToEndTest, TokenBinding) { | 282 TEST_P(QuicEndToEndTest, TokenBinding) { |
| 277 // Enable token binding and re-initialize the TestTransactionFactory. | 283 // Enable token binding and re-initialize the TestTransactionFactory. |
| 278 params_.enable_token_binding = true; | 284 session_params_.enable_token_binding = true; |
| 279 transaction_factory_.reset(new TestTransactionFactory(params_)); | 285 transaction_factory_.reset( |
| 286 new TestTransactionFactory(session_params_, session_context_)); |
| 280 | 287 |
| 281 AddToCache(request_.url.PathForRequest(), 200, "OK", kResponseBody); | 288 AddToCache(request_.url.PathForRequest(), 200, "OK", kResponseBody); |
| 282 | 289 |
| 283 TestTransactionConsumer consumer(DEFAULT_PRIORITY, | 290 TestTransactionConsumer consumer(DEFAULT_PRIORITY, |
| 284 transaction_factory_.get()); | 291 transaction_factory_.get()); |
| 285 consumer.Start(&request_, NetLogWithSource()); | 292 consumer.Start(&request_, NetLogWithSource()); |
| 286 | 293 |
| 287 // Will terminate when the last consumer completes. | 294 // Will terminate when the last consumer completes. |
| 288 base::RunLoop().Run(); | 295 base::RunLoop().Run(); |
| 289 | 296 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 363 |
| 357 // Will terminate when the last consumer completes. | 364 // Will terminate when the last consumer completes. |
| 358 base::RunLoop().Run(); | 365 base::RunLoop().Run(); |
| 359 | 366 |
| 360 for (const auto& consumer : consumers) | 367 for (const auto& consumer : consumers) |
| 361 CheckResponse(*consumer.get(), "HTTP/1.1 200", kResponseBody); | 368 CheckResponse(*consumer.get(), "HTTP/1.1 200", kResponseBody); |
| 362 } | 369 } |
| 363 | 370 |
| 364 } // namespace test | 371 } // namespace test |
| 365 } // namespace net | 372 } // namespace net |
| OLD | NEW |