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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 #endif | 10 #endif |
(...skipping 5240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5251 EXPECT_EQ("text/html; charset=ISO-8859-1", header); | 5251 EXPECT_EQ("text/html; charset=ISO-8859-1", header); |
5252 | 5252 |
5253 // The response has two "X-Multiple-Entries" headers. | 5253 // The response has two "X-Multiple-Entries" headers. |
5254 // This verfies our output has them concatenated together. | 5254 // This verfies our output has them concatenated together. |
5255 header.clear(); | 5255 header.clear(); |
5256 EXPECT_TRUE(headers->GetNormalizedHeader("x-multiple-entries", &header)); | 5256 EXPECT_TRUE(headers->GetNormalizedHeader("x-multiple-entries", &header)); |
5257 EXPECT_EQ("a, b", header); | 5257 EXPECT_EQ("a, b", header); |
5258 } | 5258 } |
5259 | 5259 |
5260 TEST_F(URLRequestTestHTTP, ProcessSTS) { | 5260 TEST_F(URLRequestTestHTTP, ProcessSTS) { |
5261 SpawnedTestServer::SSLOptions ssl_options; | 5261 SpawnedTestServer::SSLOptions ssl_options( |
5262 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | |
5262 SpawnedTestServer https_test_server( | 5263 SpawnedTestServer https_test_server( |
5263 SpawnedTestServer::TYPE_HTTPS, | 5264 SpawnedTestServer::TYPE_HTTPS, |
5264 ssl_options, | 5265 ssl_options, |
5265 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 5266 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
5266 ASSERT_TRUE(https_test_server.Start()); | 5267 ASSERT_TRUE(https_test_server.Start()); |
5267 | 5268 |
5269 std::string test_server_hostname = https_test_server.GetURL("").host(); | |
Ryan Sleevi
2015/04/04 00:35:24
s/""/std::string()
estark
2015/04/06 16:41:13
Done.
| |
5270 | |
5268 TestDelegate d; | 5271 TestDelegate d; |
5269 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | 5272 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
5270 https_test_server.GetURL("files/hsts-headers.html"), DEFAULT_PRIORITY, | 5273 https_test_server.GetURL("files/hsts-headers.html"), DEFAULT_PRIORITY, |
5271 &d)); | 5274 &d)); |
5272 request->Start(); | 5275 request->Start(); |
5273 base::RunLoop().Run(); | 5276 base::RunLoop().Run(); |
5274 | 5277 |
5275 TransportSecurityState* security_state = | 5278 TransportSecurityState* security_state = |
5276 default_context_.transport_security_state(); | 5279 default_context_.transport_security_state(); |
5277 TransportSecurityState::DomainState domain_state; | 5280 TransportSecurityState::DomainState domain_state; |
5278 EXPECT_TRUE(security_state->GetDynamicDomainState( | 5281 EXPECT_TRUE(security_state->GetDynamicDomainState(test_server_hostname, |
5279 SpawnedTestServer::kLocalhost, &domain_state)); | 5282 &domain_state)); |
5280 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 5283 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
5281 domain_state.sts.upgrade_mode); | 5284 domain_state.sts.upgrade_mode); |
5282 EXPECT_TRUE(domain_state.sts.include_subdomains); | 5285 EXPECT_TRUE(domain_state.sts.include_subdomains); |
5283 EXPECT_FALSE(domain_state.pkp.include_subdomains); | 5286 EXPECT_FALSE(domain_state.pkp.include_subdomains); |
5284 #if defined(OS_ANDROID) | 5287 #if defined(OS_ANDROID) |
5285 // Android's CertVerifyProc does not (yet) handle pins. | 5288 // Android's CertVerifyProc does not (yet) handle pins. |
5286 #else | 5289 #else |
5287 EXPECT_FALSE(domain_state.HasPublicKeyPins()); | 5290 EXPECT_FALSE(domain_state.HasPublicKeyPins()); |
5288 #endif | 5291 #endif |
5289 } | 5292 } |
5290 | 5293 |
5294 TEST_F(URLRequestTestHTTP, STSNotProcessedOnIP) { | |
5295 SpawnedTestServer https_test_server( | |
5296 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::SSLOptions(), | |
5297 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | |
5298 ASSERT_TRUE(https_test_server.Start()); | |
5299 // Make sure this test fails if the test server is changed to not | |
Ryan Sleevi
2015/04/04 00:35:24
newline between 5298/5299
estark
2015/04/06 16:41:13
Done.
| |
5300 // listen on an IP by default. | |
5301 ASSERT_TRUE(https_test_server.GetURL("").HostIsIPAddress()); | |
Ryan Sleevi
2015/04/04 00:35:24
std::string
estark
2015/04/06 16:41:13
Done.
| |
5302 std::string test_server_hostname = https_test_server.GetURL("").host(); | |
Ryan Sleevi
2015/04/04 00:35:24
ditto
estark
2015/04/06 16:41:13
Done.
| |
5303 | |
5304 TestDelegate d; | |
5305 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | |
5306 https_test_server.GetURL("files/hsts-headers.html"), DEFAULT_PRIORITY, | |
5307 &d)); | |
5308 request->Start(); | |
5309 base::RunLoop().Run(); | |
5310 | |
5311 TransportSecurityState* security_state = | |
5312 default_context_.transport_security_state(); | |
5313 TransportSecurityState::DomainState domain_state; | |
5314 EXPECT_FALSE(security_state->GetDynamicDomainState(test_server_hostname, | |
5315 &domain_state)); | |
5316 } | |
5317 | |
5291 // Android's CertVerifyProc does not (yet) handle pins. Therefore, it will | 5318 // Android's CertVerifyProc does not (yet) handle pins. Therefore, it will |
5292 // reject HPKP headers, and a test setting only HPKP headers will fail (no | 5319 // reject HPKP headers, and a test setting only HPKP headers will fail (no |
5293 // DomainState present because header rejected). | 5320 // DomainState present because header rejected). |
5294 #if defined(OS_ANDROID) | 5321 #if defined(OS_ANDROID) |
5295 #define MAYBE_ProcessPKP DISABLED_ProcessPKP | 5322 #define MAYBE_ProcessPKP DISABLED_ProcessPKP |
5296 #else | 5323 #else |
5297 #define MAYBE_ProcessPKP ProcessPKP | 5324 #define MAYBE_ProcessPKP ProcessPKP |
5298 #endif | 5325 #endif |
5299 | 5326 |
5300 // Tests that enabling HPKP on a domain does not affect the HSTS | 5327 // Tests that enabling HPKP on a domain does not affect the HSTS |
5301 // validity/expiration. | 5328 // validity/expiration. |
5302 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKP) { | 5329 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKP) { |
5303 SpawnedTestServer::SSLOptions ssl_options; | 5330 SpawnedTestServer::SSLOptions ssl_options( |
5331 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | |
5304 SpawnedTestServer https_test_server( | 5332 SpawnedTestServer https_test_server( |
5305 SpawnedTestServer::TYPE_HTTPS, | 5333 SpawnedTestServer::TYPE_HTTPS, |
5306 ssl_options, | 5334 ssl_options, |
5307 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 5335 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
5308 ASSERT_TRUE(https_test_server.Start()); | 5336 ASSERT_TRUE(https_test_server.Start()); |
5309 | 5337 |
5338 std::string test_server_hostname = https_test_server.GetURL("").host(); | |
5339 | |
5310 TestDelegate d; | 5340 TestDelegate d; |
5311 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | 5341 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
5312 https_test_server.GetURL("files/hpkp-headers.html"), DEFAULT_PRIORITY, | 5342 https_test_server.GetURL("files/hpkp-headers.html"), DEFAULT_PRIORITY, |
5313 &d)); | 5343 &d)); |
5314 request->Start(); | 5344 request->Start(); |
5315 base::RunLoop().Run(); | 5345 base::RunLoop().Run(); |
5316 | 5346 |
5317 TransportSecurityState* security_state = | 5347 TransportSecurityState* security_state = |
5318 default_context_.transport_security_state(); | 5348 default_context_.transport_security_state(); |
5319 TransportSecurityState::DomainState domain_state; | 5349 TransportSecurityState::DomainState domain_state; |
5320 EXPECT_TRUE(security_state->GetDynamicDomainState( | 5350 EXPECT_TRUE(security_state->GetDynamicDomainState(test_server_hostname, |
5321 SpawnedTestServer::kLocalhost, &domain_state)); | 5351 &domain_state)); |
5322 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT, | 5352 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT, |
5323 domain_state.sts.upgrade_mode); | 5353 domain_state.sts.upgrade_mode); |
5324 EXPECT_FALSE(domain_state.sts.include_subdomains); | 5354 EXPECT_FALSE(domain_state.sts.include_subdomains); |
5325 EXPECT_FALSE(domain_state.pkp.include_subdomains); | 5355 EXPECT_FALSE(domain_state.pkp.include_subdomains); |
5326 EXPECT_TRUE(domain_state.HasPublicKeyPins()); | 5356 EXPECT_TRUE(domain_state.HasPublicKeyPins()); |
5327 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry); | 5357 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry); |
5328 } | 5358 } |
5329 | 5359 |
5360 TEST_F(URLRequestTestHTTP, PKPNotProcessedOnIP) { | |
5361 SpawnedTestServer https_test_server( | |
5362 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::SSLOptions(), | |
5363 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | |
5364 ASSERT_TRUE(https_test_server.Start()); | |
5365 // Make sure this test fails if the test server is changed to not | |
5366 // listen on an IP by default. | |
5367 ASSERT_TRUE(https_test_server.GetURL("").HostIsIPAddress()); | |
5368 std::string test_server_hostname = https_test_server.GetURL("").host(); | |
5369 | |
5370 TestDelegate d; | |
5371 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | |
5372 https_test_server.GetURL("files/hpkp-headers.html"), DEFAULT_PRIORITY, | |
5373 &d)); | |
5374 request->Start(); | |
5375 base::RunLoop().Run(); | |
5376 | |
5377 TransportSecurityState* security_state = | |
5378 default_context_.transport_security_state(); | |
5379 TransportSecurityState::DomainState domain_state; | |
5380 EXPECT_FALSE(security_state->GetDynamicDomainState(test_server_hostname, | |
5381 &domain_state)); | |
5382 } | |
5383 | |
5330 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) { | 5384 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) { |
5331 SpawnedTestServer::SSLOptions ssl_options; | 5385 SpawnedTestServer::SSLOptions ssl_options( |
5386 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | |
5332 SpawnedTestServer https_test_server( | 5387 SpawnedTestServer https_test_server( |
5333 SpawnedTestServer::TYPE_HTTPS, | 5388 SpawnedTestServer::TYPE_HTTPS, |
5334 ssl_options, | 5389 ssl_options, |
5335 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 5390 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
5336 ASSERT_TRUE(https_test_server.Start()); | 5391 ASSERT_TRUE(https_test_server.Start()); |
5337 | 5392 |
5393 std::string test_server_hostname = https_test_server.GetURL("").host(); | |
5394 | |
5338 TestDelegate d; | 5395 TestDelegate d; |
5339 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | 5396 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
5340 https_test_server.GetURL("files/hsts-multiple-headers.html"), | 5397 https_test_server.GetURL("files/hsts-multiple-headers.html"), |
5341 DEFAULT_PRIORITY, &d)); | 5398 DEFAULT_PRIORITY, &d)); |
5342 request->Start(); | 5399 request->Start(); |
5343 base::RunLoop().Run(); | 5400 base::RunLoop().Run(); |
5344 | 5401 |
5345 // We should have set parameters from the first header, not the second. | 5402 // We should have set parameters from the first header, not the second. |
5346 TransportSecurityState* security_state = | 5403 TransportSecurityState* security_state = |
5347 default_context_.transport_security_state(); | 5404 default_context_.transport_security_state(); |
5348 TransportSecurityState::DomainState domain_state; | 5405 TransportSecurityState::DomainState domain_state; |
5349 EXPECT_TRUE(security_state->GetDynamicDomainState( | 5406 EXPECT_TRUE(security_state->GetDynamicDomainState(test_server_hostname, |
5350 SpawnedTestServer::kLocalhost, &domain_state)); | 5407 &domain_state)); |
5351 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 5408 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
5352 domain_state.sts.upgrade_mode); | 5409 domain_state.sts.upgrade_mode); |
5353 EXPECT_FALSE(domain_state.sts.include_subdomains); | 5410 EXPECT_FALSE(domain_state.sts.include_subdomains); |
5354 EXPECT_FALSE(domain_state.pkp.include_subdomains); | 5411 EXPECT_FALSE(domain_state.pkp.include_subdomains); |
5355 } | 5412 } |
5356 | 5413 |
5357 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { | 5414 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { |
5358 SpawnedTestServer::SSLOptions ssl_options; | 5415 SpawnedTestServer::SSLOptions ssl_options( |
5416 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | |
5359 SpawnedTestServer https_test_server( | 5417 SpawnedTestServer https_test_server( |
5360 SpawnedTestServer::TYPE_HTTPS, | 5418 SpawnedTestServer::TYPE_HTTPS, |
5361 ssl_options, | 5419 ssl_options, |
5362 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 5420 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
5363 ASSERT_TRUE(https_test_server.Start()); | 5421 ASSERT_TRUE(https_test_server.Start()); |
5364 | 5422 |
5423 std::string test_server_hostname = https_test_server.GetURL("").host(); | |
5424 | |
5365 TestDelegate d; | 5425 TestDelegate d; |
5366 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | 5426 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
5367 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"), | 5427 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"), |
5368 DEFAULT_PRIORITY, &d)); | 5428 DEFAULT_PRIORITY, &d)); |
5369 request->Start(); | 5429 request->Start(); |
5370 base::RunLoop().Run(); | 5430 base::RunLoop().Run(); |
5371 | 5431 |
5372 // We should have set parameters from the first header, not the second. | 5432 // We should have set parameters from the first header, not the second. |
5373 TransportSecurityState* security_state = | 5433 TransportSecurityState* security_state = |
5374 default_context_.transport_security_state(); | 5434 default_context_.transport_security_state(); |
5375 TransportSecurityState::DomainState domain_state; | 5435 TransportSecurityState::DomainState domain_state; |
5376 EXPECT_TRUE(security_state->GetDynamicDomainState( | 5436 EXPECT_TRUE(security_state->GetDynamicDomainState(test_server_hostname, |
5377 SpawnedTestServer::kLocalhost, &domain_state)); | 5437 &domain_state)); |
5378 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 5438 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
5379 domain_state.sts.upgrade_mode); | 5439 domain_state.sts.upgrade_mode); |
5380 #if defined(OS_ANDROID) | 5440 #if defined(OS_ANDROID) |
5381 // Android's CertVerifyProc does not (yet) handle pins. | 5441 // Android's CertVerifyProc does not (yet) handle pins. |
5382 #else | 5442 #else |
5383 EXPECT_TRUE(domain_state.HasPublicKeyPins()); | 5443 EXPECT_TRUE(domain_state.HasPublicKeyPins()); |
5384 #endif | 5444 #endif |
5385 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry); | 5445 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry); |
5386 | 5446 |
5387 // Even though there is an HSTS header asserting includeSubdomains, it is | 5447 // Even though there is an HSTS header asserting includeSubdomains, it is |
5388 // the *second* such header, and we MUST process only the first. | 5448 // the *second* such header, and we MUST process only the first. |
5389 EXPECT_FALSE(domain_state.sts.include_subdomains); | 5449 EXPECT_FALSE(domain_state.sts.include_subdomains); |
5390 // includeSubdomains does not occur in the test HPKP header. | 5450 // includeSubdomains does not occur in the test HPKP header. |
5391 EXPECT_FALSE(domain_state.pkp.include_subdomains); | 5451 EXPECT_FALSE(domain_state.pkp.include_subdomains); |
5392 } | 5452 } |
5393 | 5453 |
5394 // Tests that when multiple HPKP headers are present, asserting different | 5454 // Tests that when multiple HPKP headers are present, asserting different |
5395 // policies, that only the first such policy is processed. | 5455 // policies, that only the first such policy is processed. |
5396 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP2) { | 5456 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP2) { |
5397 SpawnedTestServer::SSLOptions ssl_options; | 5457 SpawnedTestServer::SSLOptions ssl_options( |
5458 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | |
5398 SpawnedTestServer https_test_server( | 5459 SpawnedTestServer https_test_server( |
5399 SpawnedTestServer::TYPE_HTTPS, | 5460 SpawnedTestServer::TYPE_HTTPS, |
5400 ssl_options, | 5461 ssl_options, |
5401 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 5462 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
5402 ASSERT_TRUE(https_test_server.Start()); | 5463 ASSERT_TRUE(https_test_server.Start()); |
5403 | 5464 |
5465 std::string test_server_hostname = https_test_server.GetURL("").host(); | |
5466 | |
5404 TestDelegate d; | 5467 TestDelegate d; |
5405 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | 5468 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
5406 https_test_server.GetURL("files/hsts-and-hpkp-headers2.html"), | 5469 https_test_server.GetURL("files/hsts-and-hpkp-headers2.html"), |
5407 DEFAULT_PRIORITY, &d)); | 5470 DEFAULT_PRIORITY, &d)); |
5408 request->Start(); | 5471 request->Start(); |
5409 base::RunLoop().Run(); | 5472 base::RunLoop().Run(); |
5410 | 5473 |
5411 TransportSecurityState* security_state = | 5474 TransportSecurityState* security_state = |
5412 default_context_.transport_security_state(); | 5475 default_context_.transport_security_state(); |
5413 TransportSecurityState::DomainState domain_state; | 5476 TransportSecurityState::DomainState domain_state; |
5414 EXPECT_TRUE(security_state->GetDynamicDomainState( | 5477 EXPECT_TRUE(security_state->GetDynamicDomainState(test_server_hostname, |
5415 SpawnedTestServer::kLocalhost, &domain_state)); | 5478 &domain_state)); |
5416 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 5479 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
5417 domain_state.sts.upgrade_mode); | 5480 domain_state.sts.upgrade_mode); |
5418 #if defined(OS_ANDROID) | 5481 #if defined(OS_ANDROID) |
5419 // Android's CertVerifyProc does not (yet) handle pins. | 5482 // Android's CertVerifyProc does not (yet) handle pins. |
5420 #else | 5483 #else |
5421 EXPECT_TRUE(domain_state.HasPublicKeyPins()); | 5484 EXPECT_TRUE(domain_state.HasPublicKeyPins()); |
5422 #endif | 5485 #endif |
5423 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry); | 5486 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry); |
5424 | 5487 |
5425 EXPECT_TRUE(domain_state.sts.include_subdomains); | 5488 EXPECT_TRUE(domain_state.sts.include_subdomains); |
(...skipping 3576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9002 | 9065 |
9003 EXPECT_FALSE(r->is_pending()); | 9066 EXPECT_FALSE(r->is_pending()); |
9004 EXPECT_EQ(1, d->response_started_count()); | 9067 EXPECT_EQ(1, d->response_started_count()); |
9005 EXPECT_FALSE(d->received_data_before_response()); | 9068 EXPECT_FALSE(d->received_data_before_response()); |
9006 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 9069 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
9007 } | 9070 } |
9008 } | 9071 } |
9009 #endif // !defined(DISABLE_FTP_SUPPORT) | 9072 #endif // !defined(DISABLE_FTP_SUPPORT) |
9010 | 9073 |
9011 } // namespace net | 9074 } // namespace net |
OLD | NEW |