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 4037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4508 | 4508 |
4509 virtual void SetUp() OVERRIDE { | 4509 virtual void SetUp() OVERRIDE { |
4510 SetupContext(&context_); | 4510 SetupContext(&context_); |
4511 context_.Init(); | 4511 context_.Init(); |
4512 | 4512 |
4513 scoped_refptr<net::X509Certificate> root_cert = | 4513 scoped_refptr<net::X509Certificate> root_cert = |
4514 ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem"); | 4514 ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem"); |
4515 CHECK_NE(static_cast<X509Certificate*>(NULL), root_cert); | 4515 CHECK_NE(static_cast<X509Certificate*>(NULL), root_cert); |
4516 test_root_.reset(new ScopedTestRoot(root_cert)); | 4516 test_root_.reset(new ScopedTestRoot(root_cert)); |
4517 | 4517 |
4518 #if defined(USE_NSS) | 4518 #if defined(USE_NSS) || defined(OS_IOS) |
4519 SetURLRequestContextForNSSHttpIO(&context_); | 4519 SetURLRequestContextForNSSHttpIO(&context_); |
4520 EnsureNSSHttpIOInit(); | 4520 EnsureNSSHttpIOInit(); |
4521 #endif | 4521 #endif |
4522 } | 4522 } |
4523 | 4523 |
4524 void DoConnection(const TestServer::SSLOptions& ssl_options, | 4524 void DoConnection(const TestServer::SSLOptions& ssl_options, |
4525 CertStatus* out_cert_status) { | 4525 CertStatus* out_cert_status) { |
4526 TestServer test_server(TestServer::TYPE_HTTPS, | 4526 TestServer test_server(TestServer::TYPE_HTTPS, |
4527 ssl_options, | 4527 ssl_options, |
4528 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 4528 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
4529 ASSERT_TRUE(test_server.Start()); | 4529 ASSERT_TRUE(test_server.Start()); |
4530 | 4530 |
4531 TestDelegate d; | 4531 TestDelegate d; |
4532 d.set_allow_certificate_errors(true); | 4532 d.set_allow_certificate_errors(true); |
4533 URLRequest r(test_server.GetURL(""), &d, &context_); | 4533 URLRequest r(test_server.GetURL(""), &d, &context_); |
4534 r.Start(); | 4534 r.Start(); |
4535 | 4535 |
4536 MessageLoop::current()->Run(); | 4536 MessageLoop::current()->Run(); |
4537 | 4537 |
4538 EXPECT_EQ(1, d.response_started_count()); | 4538 EXPECT_EQ(1, d.response_started_count()); |
4539 *out_cert_status = r.ssl_info().cert_status; | 4539 *out_cert_status = r.ssl_info().cert_status; |
4540 } | 4540 } |
4541 | 4541 |
4542 ~HTTPSOCSPTest() { | 4542 ~HTTPSOCSPTest() { |
4543 #if defined(USE_NSS) | 4543 #if defined(USE_NSS) || defined(OS_IOS) |
4544 ShutdownNSSHttpIO(); | 4544 ShutdownNSSHttpIO(); |
4545 #endif | 4545 #endif |
4546 } | 4546 } |
4547 | 4547 |
4548 protected: | 4548 protected: |
4549 // SetupContext configures the URLRequestContext that will be used for making | 4549 // SetupContext configures the URLRequestContext that will be used for making |
4550 // connetions to testserver. This can be overridden in test subclasses for | 4550 // connetions to testserver. This can be overridden in test subclasses for |
4551 // different behaviour. | 4551 // different behaviour. |
4552 virtual void SetupContext(URLRequestContext* context) { | 4552 virtual void SetupContext(URLRequestContext* context) { |
4553 context->set_ssl_config_service( | 4553 context->set_ssl_config_service( |
(...skipping 17 matching lines...) Expand all Loading... |
4571 } | 4571 } |
4572 | 4572 |
4573 // SystemUsesChromiumEVMetadata returns true iff the current operating system | 4573 // SystemUsesChromiumEVMetadata returns true iff the current operating system |
4574 // uses Chromium's EV metadata (i.e. EVRootCAMetadata). If it does not, then | 4574 // uses Chromium's EV metadata (i.e. EVRootCAMetadata). If it does not, then |
4575 // several tests are effected because our testing EV certificate won't be | 4575 // several tests are effected because our testing EV certificate won't be |
4576 // recognised as EV. | 4576 // recognised as EV. |
4577 static bool SystemUsesChromiumEVMetadata() { | 4577 static bool SystemUsesChromiumEVMetadata() { |
4578 #if defined(USE_OPENSSL) | 4578 #if defined(USE_OPENSSL) |
4579 // http://crbug.com/117478 - OpenSSL does not support EV validation. | 4579 // http://crbug.com/117478 - OpenSSL does not support EV validation. |
4580 return false; | 4580 return false; |
4581 #elif defined(OS_MACOSX) | 4581 #elif defined(OS_MACOSX) && !defined(OS_IOS) |
4582 // On OS X, we use the system to tell us whether a certificate is EV or not | 4582 // On OS X, we use the system to tell us whether a certificate is EV or not |
4583 // and the system won't recognise our testing root. | 4583 // and the system won't recognise our testing root. |
4584 return false; | 4584 return false; |
4585 #else | 4585 #else |
4586 return true; | 4586 return true; |
4587 #endif | 4587 #endif |
4588 } | 4588 } |
4589 | 4589 |
4590 static bool SystemSupportsOCSP() { | 4590 static bool SystemSupportsOCSP() { |
4591 #if defined(USE_OPENSSL) | 4591 #if defined(USE_OPENSSL) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4627 return; | 4627 return; |
4628 } | 4628 } |
4629 | 4629 |
4630 TestServer::SSLOptions ssl_options( | 4630 TestServer::SSLOptions ssl_options( |
4631 TestServer::SSLOptions::CERT_AUTO); | 4631 TestServer::SSLOptions::CERT_AUTO); |
4632 ssl_options.ocsp_status = TestServer::SSLOptions::OCSP_REVOKED; | 4632 ssl_options.ocsp_status = TestServer::SSLOptions::OCSP_REVOKED; |
4633 | 4633 |
4634 CertStatus cert_status; | 4634 CertStatus cert_status; |
4635 DoConnection(ssl_options, &cert_status); | 4635 DoConnection(ssl_options, &cert_status); |
4636 | 4636 |
4637 #if !defined(OS_MACOSX) | 4637 #if !(defined(OS_MACOSX) && !defined(OS_IOS)) |
4638 // Doesn't pass on OS X yet for reasons that need to be investigated. | 4638 // Doesn't pass on OS X yet for reasons that need to be investigated. |
4639 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS); | 4639 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS); |
4640 #endif | 4640 #endif |
4641 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); | 4641 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); |
4642 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); | 4642 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); |
4643 } | 4643 } |
4644 | 4644 |
4645 TEST_F(HTTPSOCSPTest, Invalid) { | 4645 TEST_F(HTTPSOCSPTest, Invalid) { |
4646 if (!SystemSupportsOCSP()) { | 4646 if (!SystemSupportsOCSP()) { |
4647 LOG(WARNING) << "Skipping test because system doesn't support OCSP"; | 4647 LOG(WARNING) << "Skipping test because system doesn't support OCSP"; |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5165 | 5165 |
5166 EXPECT_FALSE(r.is_pending()); | 5166 EXPECT_FALSE(r.is_pending()); |
5167 EXPECT_EQ(1, d->response_started_count()); | 5167 EXPECT_EQ(1, d->response_started_count()); |
5168 EXPECT_FALSE(d->received_data_before_response()); | 5168 EXPECT_FALSE(d->received_data_before_response()); |
5169 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 5169 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
5170 } | 5170 } |
5171 } | 5171 } |
5172 #endif // !defined(DISABLE_FTP_SUPPORT) | 5172 #endif // !defined(DISABLE_FTP_SUPPORT) |
5173 | 5173 |
5174 } // namespace net | 5174 } // namespace net |
OLD | NEW |