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 6774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6785 EXPECT_EQ("https", req.url().scheme()); | 6785 EXPECT_EQ("https", req.url().scheme()); |
6786 EXPECT_EQ("POST", req.method()); | 6786 EXPECT_EQ("POST", req.method()); |
6787 EXPECT_EQ(kData, d.data_received()); | 6787 EXPECT_EQ(kData, d.data_received()); |
6788 | 6788 |
6789 LoadTimingInfo load_timing_info; | 6789 LoadTimingInfo load_timing_info; |
6790 network_delegate.GetLoadTimingInfoBeforeRedirect(&load_timing_info); | 6790 network_delegate.GetLoadTimingInfoBeforeRedirect(&load_timing_info); |
6791 // LoadTimingInfo of HSTS redirects is similar to that of network cache hits | 6791 // LoadTimingInfo of HSTS redirects is similar to that of network cache hits |
6792 TestLoadTimingCacheHitNoNetwork(load_timing_info); | 6792 TestLoadTimingCacheHitNoNetwork(load_timing_info); |
6793 } | 6793 } |
6794 | 6794 |
| 6795 // Make sure that the CORS headers are added to cross-origin HSTS redirects. |
| 6796 TEST_F(HTTPSRequestTest, HSTSCrossOriginAddHeaders) { |
| 6797 static const char kOriginHeaderValue[] = "http://www.example.com"; |
| 6798 |
| 6799 SpawnedTestServer::SSLOptions ssl_options( |
| 6800 SpawnedTestServer::SSLOptions::CERT_OK); |
| 6801 SpawnedTestServer test_server( |
| 6802 SpawnedTestServer::TYPE_HTTPS, |
| 6803 ssl_options, |
| 6804 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 6805 ASSERT_TRUE(test_server.Start()); |
| 6806 |
| 6807 // Per spec, TransportSecurityState expects a domain name, rather than an IP |
| 6808 // address, so a MockHostResolver is needed to redirect example.net to the |
| 6809 // SpawnedTestServer. MockHostResolver maps all hosts to 127.0.0.1 by default. |
| 6810 MockHostResolver host_resolver; |
| 6811 |
| 6812 TransportSecurityState transport_security_state; |
| 6813 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 6814 bool include_subdomains = false; |
| 6815 transport_security_state.AddHSTS("example.net", expiry, include_subdomains); |
| 6816 |
| 6817 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 6818 |
| 6819 MockCertVerifier cert_verifier; |
| 6820 cert_verifier.set_default_result(OK); |
| 6821 |
| 6822 TestURLRequestContext context(true); |
| 6823 context.set_host_resolver(&host_resolver); |
| 6824 context.set_transport_security_state(&transport_security_state); |
| 6825 context.set_network_delegate(&network_delegate); |
| 6826 context.set_cert_verifier(&cert_verifier); |
| 6827 context.Init(); |
| 6828 |
| 6829 GURL hsts_http_url(base::StringPrintf("http://example.net:%d/somehstssite", |
| 6830 test_server.host_port_pair().port())); |
| 6831 url::Replacements<char> replacements; |
| 6832 const char kNewScheme[] = "https"; |
| 6833 replacements.SetScheme(kNewScheme, url::Component(0, strlen(kNewScheme))); |
| 6834 GURL hsts_https_url = hsts_http_url.ReplaceComponents(replacements); |
| 6835 |
| 6836 TestDelegate d; |
| 6837 // Quit on redirect to allow response header inspection upon redirect. |
| 6838 d.set_quit_on_redirect(true); |
| 6839 |
| 6840 scoped_ptr<URLRequest> req(context.CreateRequest(hsts_http_url, |
| 6841 DEFAULT_PRIORITY, &d, NULL)); |
| 6842 // Set Origin header to simulate a cross-origin request. |
| 6843 HttpRequestHeaders request_headers; |
| 6844 request_headers.SetHeader("Origin", kOriginHeaderValue); |
| 6845 req->SetExtraRequestHeaders(request_headers); |
| 6846 |
| 6847 req->Start(); |
| 6848 base::RunLoop().Run(); |
| 6849 |
| 6850 EXPECT_EQ(1, d.received_redirect_count()); |
| 6851 |
| 6852 const HttpResponseHeaders* headers = req->response_headers(); |
| 6853 std::string redirect_location; |
| 6854 EXPECT_TRUE(headers->EnumerateHeader(NULL, "Location", &redirect_location)); |
| 6855 EXPECT_EQ(hsts_https_url.spec(), redirect_location); |
| 6856 |
| 6857 std::string received_cors_header; |
| 6858 EXPECT_TRUE(headers->EnumerateHeader(NULL, "Access-Control-Allow-Origin", |
| 6859 &received_cors_header)); |
| 6860 EXPECT_EQ(kOriginHeaderValue, received_cors_header); |
| 6861 } |
| 6862 |
6795 namespace { | 6863 namespace { |
6796 | 6864 |
6797 class SSLClientAuthTestDelegate : public TestDelegate { | 6865 class SSLClientAuthTestDelegate : public TestDelegate { |
6798 public: | 6866 public: |
6799 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) { | 6867 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) { |
6800 } | 6868 } |
6801 virtual void OnCertificateRequested( | 6869 virtual void OnCertificateRequested( |
6802 URLRequest* request, | 6870 URLRequest* request, |
6803 SSLCertRequestInfo* cert_request_info) OVERRIDE { | 6871 SSLCertRequestInfo* cert_request_info) OVERRIDE { |
6804 on_certificate_requested_count_++; | 6872 on_certificate_requested_count_++; |
(...skipping 1339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8144 | 8212 |
8145 EXPECT_FALSE(r.is_pending()); | 8213 EXPECT_FALSE(r.is_pending()); |
8146 EXPECT_EQ(1, d->response_started_count()); | 8214 EXPECT_EQ(1, d->response_started_count()); |
8147 EXPECT_FALSE(d->received_data_before_response()); | 8215 EXPECT_FALSE(d->received_data_before_response()); |
8148 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 8216 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
8149 } | 8217 } |
8150 } | 8218 } |
8151 #endif // !defined(DISABLE_FTP_SUPPORT) | 8219 #endif // !defined(DISABLE_FTP_SUPPORT) |
8152 | 8220 |
8153 } // namespace net | 8221 } // namespace net |
OLD | NEW |