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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 : TestURLRequestContext(true) { | 450 : TestURLRequestContext(true) { |
451 context_storage_.set_proxy_service(ProxyService::CreateFixed(proxy)); | 451 context_storage_.set_proxy_service(ProxyService::CreateFixed(proxy)); |
452 set_network_delegate(delegate); | 452 set_network_delegate(delegate); |
453 Init(); | 453 Init(); |
454 } | 454 } |
455 virtual ~TestURLRequestContextWithProxy() {} | 455 virtual ~TestURLRequestContextWithProxy() {} |
456 }; | 456 }; |
457 | 457 |
458 } // namespace | 458 } // namespace |
459 | 459 |
460 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f | 460 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. |
461 class URLRequestTest : public PlatformTest { | 461 class URLRequestTest : public PlatformTest { |
462 public: | 462 public: |
463 URLRequestTest() : default_context_(true) { | 463 URLRequestTest() : default_context_(true) { |
464 default_context_.set_network_delegate(&default_network_delegate_); | 464 default_context_.set_network_delegate(&default_network_delegate_); |
465 default_context_.Init(); | 465 default_context_.Init(); |
466 } | 466 } |
467 | 467 |
468 // Adds the TestJobInterceptor to the default context. | 468 // Adds the TestJobInterceptor to the default context. |
469 TestJobInterceptor* AddTestInterceptor() { | 469 TestJobInterceptor* AddTestInterceptor() { |
470 TestJobInterceptor* interceptor = new TestJobInterceptor(); | 470 TestJobInterceptor* interceptor = new TestJobInterceptor(); |
(...skipping 3985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4456 | 4456 |
4457 virtual void SetUp() OVERRIDE { | 4457 virtual void SetUp() OVERRIDE { |
4458 SetupContext(&context_); | 4458 SetupContext(&context_); |
4459 context_.Init(); | 4459 context_.Init(); |
4460 | 4460 |
4461 scoped_refptr<net::X509Certificate> root_cert = | 4461 scoped_refptr<net::X509Certificate> root_cert = |
4462 ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem"); | 4462 ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem"); |
4463 CHECK_NE(static_cast<X509Certificate*>(NULL), root_cert); | 4463 CHECK_NE(static_cast<X509Certificate*>(NULL), root_cert); |
4464 test_root_.reset(new ScopedTestRoot(root_cert)); | 4464 test_root_.reset(new ScopedTestRoot(root_cert)); |
4465 | 4465 |
4466 #if defined(USE_NSS) | 4466 #if defined(USE_NSS) || defined(OS_IOS) |
4467 SetURLRequestContextForNSSHttpIO(&context_); | 4467 SetURLRequestContextForNSSHttpIO(&context_); |
4468 EnsureNSSHttpIOInit(); | 4468 EnsureNSSHttpIOInit(); |
4469 #endif | 4469 #endif |
4470 } | 4470 } |
4471 | 4471 |
4472 void DoConnection(const TestServer::SSLOptions& ssl_options, | 4472 void DoConnection(const TestServer::SSLOptions& ssl_options, |
4473 CertStatus* out_cert_status) { | 4473 CertStatus* out_cert_status) { |
4474 TestServer test_server(TestServer::TYPE_HTTPS, | 4474 TestServer test_server(TestServer::TYPE_HTTPS, |
4475 ssl_options, | 4475 ssl_options, |
4476 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 4476 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
4477 ASSERT_TRUE(test_server.Start()); | 4477 ASSERT_TRUE(test_server.Start()); |
4478 | 4478 |
4479 TestDelegate d; | 4479 TestDelegate d; |
4480 d.set_allow_certificate_errors(true); | 4480 d.set_allow_certificate_errors(true); |
4481 URLRequest r(test_server.GetURL(""), &d, &context_); | 4481 URLRequest r(test_server.GetURL(""), &d, &context_); |
4482 r.Start(); | 4482 r.Start(); |
4483 | 4483 |
4484 MessageLoop::current()->Run(); | 4484 MessageLoop::current()->Run(); |
4485 | 4485 |
4486 EXPECT_EQ(1, d.response_started_count()); | 4486 EXPECT_EQ(1, d.response_started_count()); |
4487 *out_cert_status = r.ssl_info().cert_status; | 4487 *out_cert_status = r.ssl_info().cert_status; |
4488 } | 4488 } |
4489 | 4489 |
4490 ~HTTPSOCSPTest() { | 4490 ~HTTPSOCSPTest() { |
4491 #if defined(USE_NSS) | 4491 #if defined(USE_NSS) || defined(OS_IOS) |
4492 ShutdownNSSHttpIO(); | 4492 ShutdownNSSHttpIO(); |
4493 #endif | 4493 #endif |
4494 } | 4494 } |
4495 | 4495 |
4496 protected: | 4496 protected: |
4497 // SetupContext configures the URLRequestContext that will be used for making | 4497 // SetupContext configures the URLRequestContext that will be used for making |
4498 // connetions to testserver. This can be overridden in test subclasses for | 4498 // connetions to testserver. This can be overridden in test subclasses for |
4499 // different behaviour. | 4499 // different behaviour. |
4500 virtual void SetupContext(URLRequestContext* context) { | 4500 virtual void SetupContext(URLRequestContext* context) { |
4501 context->set_ssl_config_service( | 4501 context->set_ssl_config_service( |
(...skipping 17 matching lines...) Expand all Loading... |
4519 } | 4519 } |
4520 | 4520 |
4521 // SystemUsesChromiumEVMetadata returns true iff the current operating system | 4521 // SystemUsesChromiumEVMetadata returns true iff the current operating system |
4522 // uses Chromium's EV metadata (i.e. EVRootCAMetadata). If it does not, then | 4522 // uses Chromium's EV metadata (i.e. EVRootCAMetadata). If it does not, then |
4523 // several tests are effected because our testing EV certificate won't be | 4523 // several tests are effected because our testing EV certificate won't be |
4524 // recognised as EV. | 4524 // recognised as EV. |
4525 static bool SystemUsesChromiumEVMetadata() { | 4525 static bool SystemUsesChromiumEVMetadata() { |
4526 #if defined(USE_OPENSSL) | 4526 #if defined(USE_OPENSSL) |
4527 // http://crbug.com/117478 - OpenSSL does not support EV validation. | 4527 // http://crbug.com/117478 - OpenSSL does not support EV validation. |
4528 return false; | 4528 return false; |
4529 #elif defined(OS_MACOSX) | 4529 #elif defined(OS_MACOSX) && !defined(OS_IOS) |
4530 // On OS X, we use the system to tell us whether a certificate is EV or not | 4530 // On OS X, we use the system to tell us whether a certificate is EV or not |
4531 // and the system won't recognise our testing root. | 4531 // and the system won't recognise our testing root. |
4532 return false; | 4532 return false; |
4533 #else | 4533 #else |
4534 return true; | 4534 return true; |
4535 #endif | 4535 #endif |
4536 } | 4536 } |
4537 | 4537 |
4538 static bool SystemSupportsOCSP() { | 4538 static bool SystemSupportsOCSP() { |
4539 #if defined(USE_OPENSSL) | 4539 #if defined(USE_OPENSSL) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4575 return; | 4575 return; |
4576 } | 4576 } |
4577 | 4577 |
4578 TestServer::SSLOptions ssl_options( | 4578 TestServer::SSLOptions ssl_options( |
4579 TestServer::SSLOptions::CERT_AUTO); | 4579 TestServer::SSLOptions::CERT_AUTO); |
4580 ssl_options.ocsp_status = TestServer::SSLOptions::OCSP_REVOKED; | 4580 ssl_options.ocsp_status = TestServer::SSLOptions::OCSP_REVOKED; |
4581 | 4581 |
4582 CertStatus cert_status; | 4582 CertStatus cert_status; |
4583 DoConnection(ssl_options, &cert_status); | 4583 DoConnection(ssl_options, &cert_status); |
4584 | 4584 |
4585 #if !defined(OS_MACOSX) | 4585 #if !(defined(OS_MACOSX) && !defined(OS_IOS)) |
4586 // Doesn't pass on OS X yet for reasons that need to be investigated. | 4586 // Doesn't pass on OS X yet for reasons that need to be investigated. |
4587 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS); | 4587 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS); |
4588 #endif | 4588 #endif |
4589 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); | 4589 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); |
4590 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); | 4590 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); |
4591 } | 4591 } |
4592 | 4592 |
4593 TEST_F(HTTPSOCSPTest, Invalid) { | 4593 TEST_F(HTTPSOCSPTest, Invalid) { |
4594 if (!SystemSupportsOCSP()) { | 4594 if (!SystemSupportsOCSP()) { |
4595 LOG(WARNING) << "Skipping test because system doesn't support OCSP"; | 4595 LOG(WARNING) << "Skipping test because system doesn't support OCSP"; |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5113 | 5113 |
5114 EXPECT_FALSE(r.is_pending()); | 5114 EXPECT_FALSE(r.is_pending()); |
5115 EXPECT_EQ(1, d->response_started_count()); | 5115 EXPECT_EQ(1, d->response_started_count()); |
5116 EXPECT_FALSE(d->received_data_before_response()); | 5116 EXPECT_FALSE(d->received_data_before_response()); |
5117 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 5117 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
5118 } | 5118 } |
5119 } | 5119 } |
5120 #endif // !defined(DISABLE_FTP_SUPPORT) | 5120 #endif // !defined(DISABLE_FTP_SUPPORT) |
5121 | 5121 |
5122 } // namespace net | 5122 } // namespace net |
OLD | NEW |