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 3664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3675 TestDelegate d; | 3675 TestDelegate d; |
3676 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); | 3676 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); |
3677 req.set_method("POST"); | 3677 req.set_method("POST"); |
3678 req.set_upload(CreateSimpleUploadData(kData).get()); | 3678 req.set_upload(CreateSimpleUploadData(kData).get()); |
3679 HttpRequestHeaders headers; | 3679 HttpRequestHeaders headers; |
3680 headers.SetHeader(HttpRequestHeaders::kContentLength, | 3680 headers.SetHeader(HttpRequestHeaders::kContentLength, |
3681 base::UintToString(arraysize(kData) - 1)); | 3681 base::UintToString(arraysize(kData) - 1)); |
3682 req.SetExtraRequestHeaders(headers); | 3682 req.SetExtraRequestHeaders(headers); |
3683 | 3683 |
3684 URLRequestRedirectJob* job = new URLRequestRedirectJob( | 3684 URLRequestRedirectJob* job = new URLRequestRedirectJob( |
3685 &req, default_context_.network_delegate(), test_server_.GetURL("echo")); | 3685 &req, default_context_.network_delegate(), test_server_.GetURL("echo"), |
| 3686 URLRequestRedirectJob::REDIRECT_302_FOUND); |
3686 AddTestInterceptor()->set_main_intercept_job(job); | 3687 AddTestInterceptor()->set_main_intercept_job(job); |
3687 | 3688 |
3688 req.Start(); | 3689 req.Start(); |
3689 MessageLoop::current()->Run(); | 3690 MessageLoop::current()->Run(); |
3690 EXPECT_EQ("GET", req.method()); | 3691 EXPECT_EQ("GET", req.method()); |
3691 } | 3692 } |
3692 | 3693 |
3693 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { | 3694 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { |
3694 ASSERT_TRUE(test_server_.Start()); | 3695 ASSERT_TRUE(test_server_.Start()); |
3695 | 3696 |
3696 const char kData[] = "hello world"; | 3697 const char kData[] = "hello world"; |
3697 | 3698 |
3698 TestDelegate d; | 3699 TestDelegate d; |
3699 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); | 3700 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); |
3700 req.set_method("POST"); | 3701 req.set_method("POST"); |
3701 req.set_upload(CreateSimpleUploadData(kData).get()); | 3702 req.set_upload(CreateSimpleUploadData(kData).get()); |
3702 HttpRequestHeaders headers; | 3703 HttpRequestHeaders headers; |
3703 headers.SetHeader(HttpRequestHeaders::kContentLength, | 3704 headers.SetHeader(HttpRequestHeaders::kContentLength, |
3704 base::UintToString(arraysize(kData) - 1)); | 3705 base::UintToString(arraysize(kData) - 1)); |
3705 req.SetExtraRequestHeaders(headers); | 3706 req.SetExtraRequestHeaders(headers); |
3706 | 3707 |
3707 URLRequestRedirectJob* job = new URLRequestRedirectJob( | 3708 URLRequestRedirectJob* job = new URLRequestRedirectJob( |
3708 &req, default_context_.network_delegate(), test_server_.GetURL("echo")); | 3709 &req, default_context_.network_delegate(), test_server_.GetURL("echo"), |
3709 job->set_redirect_code( | |
3710 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT); | 3710 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT); |
3711 AddTestInterceptor()->set_main_intercept_job(job); | 3711 AddTestInterceptor()->set_main_intercept_job(job); |
3712 | 3712 |
3713 req.Start(); | 3713 req.Start(); |
3714 MessageLoop::current()->Run(); | 3714 MessageLoop::current()->Run(); |
3715 EXPECT_EQ("POST", req.method()); | 3715 EXPECT_EQ("POST", req.method()); |
3716 EXPECT_EQ(kData, d.data_received()); | 3716 EXPECT_EQ(kData, d.data_received()); |
3717 } | 3717 } |
3718 | 3718 |
3719 // Check that default A-L header is sent. | 3719 // Check that default A-L header is sent. |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4172 EXPECT_EQ(new_domain_state.include_subdomains, | 4172 EXPECT_EQ(new_domain_state.include_subdomains, |
4173 domain_state.include_subdomains); | 4173 domain_state.include_subdomains); |
4174 EXPECT_TRUE(FingerprintsEqual(new_domain_state.static_spki_hashes, | 4174 EXPECT_TRUE(FingerprintsEqual(new_domain_state.static_spki_hashes, |
4175 domain_state.static_spki_hashes)); | 4175 domain_state.static_spki_hashes)); |
4176 EXPECT_TRUE(FingerprintsEqual(new_domain_state.dynamic_spki_hashes, | 4176 EXPECT_TRUE(FingerprintsEqual(new_domain_state.dynamic_spki_hashes, |
4177 domain_state.dynamic_spki_hashes)); | 4177 domain_state.dynamic_spki_hashes)); |
4178 EXPECT_TRUE(FingerprintsEqual(new_domain_state.bad_static_spki_hashes, | 4178 EXPECT_TRUE(FingerprintsEqual(new_domain_state.bad_static_spki_hashes, |
4179 domain_state.bad_static_spki_hashes)); | 4179 domain_state.bad_static_spki_hashes)); |
4180 } | 4180 } |
4181 | 4181 |
| 4182 // Make sure HSTS preserves a POST request's method and body. |
| 4183 TEST_F(HTTPSRequestTest, HSTSPreservesPosts) { |
| 4184 static const char kData[] = "hello world"; |
| 4185 |
| 4186 TestServer::SSLOptions ssl_options(TestServer::SSLOptions::CERT_OK); |
| 4187 TestServer test_server(TestServer::TYPE_HTTPS, |
| 4188 ssl_options, |
| 4189 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 4190 ASSERT_TRUE(test_server.Start()); |
| 4191 |
| 4192 |
| 4193 // Per spec, TransportSecurityState expects a domain name, rather than an IP |
| 4194 // address, so a MockHostResolver is needed to redirect www.somewhere.com to |
| 4195 // the TestServer. |
| 4196 MockHostResolver host_resolver; |
| 4197 host_resolver.rules()->AddRule("www.somewhere.com", "127.0.0.1"); |
| 4198 |
| 4199 // Force https for www.somewhere.com. |
| 4200 TransportSecurityState transport_security_state; |
| 4201 net::TransportSecurityState::DomainState domain_state; |
| 4202 domain_state.upgrade_expiry = |
| 4203 domain_state.created + base::TimeDelta::FromDays(1000); |
| 4204 transport_security_state.EnableHost("www.somewhere.com", domain_state); |
| 4205 |
| 4206 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 4207 |
| 4208 TestURLRequestContext context(true); |
| 4209 context.set_host_resolver(&host_resolver); |
| 4210 context.set_transport_security_state(&transport_security_state); |
| 4211 context.set_network_delegate(&network_delegate); |
| 4212 context.Init(); |
| 4213 |
| 4214 TestDelegate d; |
| 4215 // Navigating to https://www.somewhere.com instead of https://127.0.0.1 will |
| 4216 // cause a certificate error. Ignore the error. |
| 4217 d.set_allow_certificate_errors(true); |
| 4218 |
| 4219 URLRequest req(GURL(StringPrintf("http://www.somewhere.com:%d/echo", |
| 4220 test_server.host_port_pair().port())), |
| 4221 &d, |
| 4222 &context); |
| 4223 req.set_method("POST"); |
| 4224 req.set_upload(CreateSimpleUploadData(kData).get()); |
| 4225 |
| 4226 req.Start(); |
| 4227 MessageLoop::current()->Run(); |
| 4228 |
| 4229 EXPECT_EQ("https", req.url().scheme()); |
| 4230 EXPECT_EQ("POST", req.method()); |
| 4231 EXPECT_EQ(kData, d.data_received()); |
| 4232 } |
| 4233 |
4182 TEST_F(HTTPSRequestTest, SSLv3Fallback) { | 4234 TEST_F(HTTPSRequestTest, SSLv3Fallback) { |
4183 TestServer::SSLOptions ssl_options( | 4235 TestServer::SSLOptions ssl_options( |
4184 TestServer::SSLOptions::CERT_OK); | 4236 TestServer::SSLOptions::CERT_OK); |
4185 ssl_options.tls_intolerant = TestServer::SSLOptions::TLS_INTOLERANT_ALL; | 4237 ssl_options.tls_intolerant = TestServer::SSLOptions::TLS_INTOLERANT_ALL; |
4186 TestServer test_server(TestServer::TYPE_HTTPS, | 4238 TestServer test_server(TestServer::TYPE_HTTPS, |
4187 ssl_options, | 4239 ssl_options, |
4188 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 4240 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
4189 ASSERT_TRUE(test_server.Start()); | 4241 ASSERT_TRUE(test_server.Start()); |
4190 | 4242 |
4191 TestDelegate d; | 4243 TestDelegate d; |
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5113 | 5165 |
5114 EXPECT_FALSE(r.is_pending()); | 5166 EXPECT_FALSE(r.is_pending()); |
5115 EXPECT_EQ(1, d->response_started_count()); | 5167 EXPECT_EQ(1, d->response_started_count()); |
5116 EXPECT_FALSE(d->received_data_before_response()); | 5168 EXPECT_FALSE(d->received_data_before_response()); |
5117 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 5169 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
5118 } | 5170 } |
5119 } | 5171 } |
5120 #endif // !defined(DISABLE_FTP_SUPPORT) | 5172 #endif // !defined(DISABLE_FTP_SUPPORT) |
5121 | 5173 |
5122 } // namespace net | 5174 } // namespace net |
OLD | NEW |