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 TestDelegate d; | |
6830 // Quit on redirect to allow response header inspection upon redirect. | |
6831 d.set_quit_on_redirect(true); | |
6832 | |
6833 scoped_ptr<URLRequest> req(context.CreateRequest( | |
6834 GURL(base::StringPrintf("http://example.net:%d/echo", | |
mmenke
2014/09/11 14:38:08
"echo" is a path the test server recognizes. Sinc
robwu
2014/09/11 14:55:39
Done.
| |
6835 test_server.host_port_pair().port())), | |
mmenke
2014/09/11 14:38:09
You should store this URL in a constant, rather th
robwu
2014/09/11 14:55:40
Done (generated the https-URL from a pre-defined h
| |
6836 DEFAULT_PRIORITY, &d, NULL)); | |
6837 // Set Origin header to simulate a cross-origin request. | |
6838 HttpRequestHeaders request_headers; | |
6839 request_headers.SetHeader("Origin", kOriginHeaderValue); | |
6840 req->SetExtraRequestHeaders(request_headers); | |
6841 | |
6842 req->Start(); | |
6843 base::RunLoop().Run(); | |
6844 | |
mmenke
2014/09/11 14:38:09
Maybe "EXPECT_EQ(1, d.received_redirect_count());"
robwu
2014/09/11 14:55:39
Done.
| |
6845 const HttpResponseHeaders* headers = req->response_headers(); | |
6846 std::string redirect_location; | |
6847 EXPECT_TRUE(headers->EnumerateHeader(NULL, "Location", &redirect_location)); | |
6848 EXPECT_EQ(base::StringPrintf("https://example.net:%d/echo", | |
6849 test_server.host_port_pair().port()), | |
6850 redirect_location); | |
6851 | |
6852 std::string received_cors_header; | |
6853 EXPECT_TRUE(headers->EnumerateHeader(NULL, "Access-Control-Allow-Origin", | |
6854 &received_cors_header)); | |
6855 EXPECT_EQ(kOriginHeaderValue, received_cors_header); | |
6856 } | |
6857 | |
6795 namespace { | 6858 namespace { |
6796 | 6859 |
6797 class SSLClientAuthTestDelegate : public TestDelegate { | 6860 class SSLClientAuthTestDelegate : public TestDelegate { |
6798 public: | 6861 public: |
6799 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) { | 6862 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) { |
6800 } | 6863 } |
6801 virtual void OnCertificateRequested( | 6864 virtual void OnCertificateRequested( |
6802 URLRequest* request, | 6865 URLRequest* request, |
6803 SSLCertRequestInfo* cert_request_info) OVERRIDE { | 6866 SSLCertRequestInfo* cert_request_info) OVERRIDE { |
6804 on_certificate_requested_count_++; | 6867 on_certificate_requested_count_++; |
(...skipping 1339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8144 | 8207 |
8145 EXPECT_FALSE(r.is_pending()); | 8208 EXPECT_FALSE(r.is_pending()); |
8146 EXPECT_EQ(1, d->response_started_count()); | 8209 EXPECT_EQ(1, d->response_started_count()); |
8147 EXPECT_FALSE(d->received_data_before_response()); | 8210 EXPECT_FALSE(d->received_data_before_response()); |
8148 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 8211 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
8149 } | 8212 } |
8150 } | 8213 } |
8151 #endif // !defined(DISABLE_FTP_SUPPORT) | 8214 #endif // !defined(DISABLE_FTP_SUPPORT) |
8152 | 8215 |
8153 } // namespace net | 8216 } // namespace net |
OLD | NEW |