Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(881)

Unified Diff: net/url_request/url_request_unittest.cc

Issue 11420013: POSTs to HSTS domains are no longer converted to GETs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix breakage Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/url_request/url_request_redirect_job.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_request_unittest.cc
===================================================================
--- net/url_request/url_request_unittest.cc (revision 169969)
+++ net/url_request/url_request_unittest.cc (working copy)
@@ -3682,7 +3682,8 @@
req.SetExtraRequestHeaders(headers);
URLRequestRedirectJob* job = new URLRequestRedirectJob(
- &req, default_context_.network_delegate(), test_server_.GetURL("echo"));
+ &req, default_context_.network_delegate(), test_server_.GetURL("echo"),
+ URLRequestRedirectJob::REDIRECT_302_FOUND);
AddTestInterceptor()->set_main_intercept_job(job);
req.Start();
@@ -3705,8 +3706,7 @@
req.SetExtraRequestHeaders(headers);
URLRequestRedirectJob* job = new URLRequestRedirectJob(
- &req, default_context_.network_delegate(), test_server_.GetURL("echo"));
- job->set_redirect_code(
+ &req, default_context_.network_delegate(), test_server_.GetURL("echo"),
URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT);
AddTestInterceptor()->set_main_intercept_job(job);
@@ -4179,6 +4179,58 @@
domain_state.bad_static_spki_hashes));
}
+// Make sure HSTS preserves a POST request's method and body.
+TEST_F(HTTPSRequestTest, HSTSPreservesPosts) {
+ static const char kData[] = "hello world";
+
+ TestServer::SSLOptions ssl_options(TestServer::SSLOptions::CERT_OK);
+ TestServer test_server(TestServer::TYPE_HTTPS,
+ ssl_options,
+ FilePath(FILE_PATH_LITERAL("net/data/ssl")));
+ ASSERT_TRUE(test_server.Start());
+
+
+ // Per spec, TransportSecurityState expects a domain name, rather than an IP
+ // address, so a MockHostResolver is needed to redirect www.somewhere.com to
+ // the TestServer.
+ MockHostResolver host_resolver;
+ host_resolver.rules()->AddRule("www.somewhere.com", "127.0.0.1");
szym 2012/11/28 18:04:16 Drive-by: MockHostResolver redirects everything to
mmenke 2012/11/28 18:34:45 Thanks. This was copy/pasted directly from anothe
+
+ // Force https for www.somewhere.com.
+ TransportSecurityState transport_security_state;
+ net::TransportSecurityState::DomainState domain_state;
+ domain_state.upgrade_expiry =
+ domain_state.created + base::TimeDelta::FromDays(1000);
+ transport_security_state.EnableHost("www.somewhere.com", domain_state);
+
+ TestNetworkDelegate network_delegate; // Must outlive URLRequest.
+
+ TestURLRequestContext context(true);
+ context.set_host_resolver(&host_resolver);
+ context.set_transport_security_state(&transport_security_state);
+ context.set_network_delegate(&network_delegate);
+ context.Init();
+
+ TestDelegate d;
+ // Navigating to https://www.somewhere.com instead of https://127.0.0.1 will
+ // cause a certificate error. Ignore the error.
+ d.set_allow_certificate_errors(true);
+
+ URLRequest req(GURL(StringPrintf("http://www.somewhere.com:%d/echo",
+ test_server.host_port_pair().port())),
+ &d,
+ &context);
+ req.set_method("POST");
+ req.set_upload(CreateSimpleUploadData(kData).get());
+
+ req.Start();
+ MessageLoop::current()->Run();
+
+ EXPECT_EQ("https", req.url().scheme());
+ EXPECT_EQ("POST", req.method());
+ EXPECT_EQ(kData, d.data_received());
+}
+
TEST_F(HTTPSRequestTest, SSLv3Fallback) {
TestServer::SSLOptions ssl_options(
TestServer::SSLOptions::CERT_OK);
« no previous file with comments | « net/url_request/url_request_redirect_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698